more fixes for note search

This commit is contained in:
Jason Wall 2020-11-26 11:16:27 -05:00
parent 78a349fb0f
commit caf3ef2d30

View File

@ -157,7 +157,7 @@ export class AppService extends createStateService(reducer, initialState) {
async updateCards(queries: IStorable<readonly DataReference[]>) { async updateCards(queries: IStorable<readonly DataReference[]>) {
const cards: CardItem[] = []; const cards: CardItem[] = [];
for (const q of queries.value) { for (const q of queries.value) {
const card = await this.getCardByQuery(q.qry, q.type); const card = await this.getCardByQuery(q.qry.trim(), q.type);
cards.push(card); cards.push(card);
} }
this.dispatch( this.dispatch(
@ -170,9 +170,19 @@ export class AppService extends createStateService(reducer, initialState) {
} }
private async getCardByQuery(qry: string, type?: CardType): Promise<CardItem> { private async getCardByQuery(qry: string, type?: CardType): Promise<CardItem> {
if (qry.startsWith('note:') || (type !== undefined && type === CardType.Note)) { if (qry.startsWith('note:')) {
const id = qry.replace('note:', ''); const q = qry.toLocaleLowerCase().trim().replace('note:', '');
const data = this.getState().notes.value.find((o) => o.id === id); const data = this.getState().notes.value.find((o) => o.title.toLowerCase().indexOf(q) > -1);
if (!data) {
return;
}
return {
qry,
type: CardType.Note,
data,
} as CardItem;
} else if (type !== undefined && type === CardType.Note) {
const data = this.getState().notes.value.find((o) => o.id === qry);
if (!data) { if (!data) {
return; return;
} }