-
-
Notifications
You must be signed in to change notification settings - Fork 529
Expand file tree
/
Copy pathdoesItemMatchSearchQuery.ts
More file actions
33 lines (28 loc) · 1.15 KB
/
doesItemMatchSearchQuery.ts
File metadata and controls
33 lines (28 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { DecryptedItemInterface, ItemContent, isNote, isTag } from '@standardnotes/snjs'
import { WebApplicationInterface } from '@standardnotes/ui-services'
export function getItemTitleInContextOfLinkBubble(item: DecryptedItemInterface<ItemContent>) {
return item.title && item.title.length > 0 ? item.title : isNote(item) ? item.preview_plain : ''
}
function getItemSearchableString(item: DecryptedItemInterface<ItemContent>, application: WebApplicationInterface) {
if (isNote(item)) {
if (item.title.length > 0) {
return item.title
} else if (!item.protected) {
return item.preview_plain
}
} else if (isTag(item)) {
return application.items.getTagLongTitle(item)
}
return item.title ?? ''
}
export function doesItemMatchSearchQuery(
item: DecryptedItemInterface<ItemContent>,
searchQuery: string,
application: WebApplicationInterface,
lowercaseQuery?: string,
) {
const title = getItemSearchableString(item, application).toLowerCase()
const matchesQuery = title.includes(lowercaseQuery ?? searchQuery.toLowerCase())
const isArchivedOrTrashed = item.archived || item.trashed
return matchesQuery && !isArchivedOrTrashed
}