feat: unify mounted workspace graph
This commit is contained in:
@@ -4,6 +4,7 @@ import { fuzzyMatch, bestSearchRank } from '../utils/fuzzyMatch'
|
||||
import { getTypeColor, getTypeLightColor, buildTypeEntryMap } from '../utils/typeColors'
|
||||
import { getTypeIcon } from '../components/NoteItem'
|
||||
import type { NoteSearchResultItem } from '../components/NoteSearchList'
|
||||
import { workspaceDisplayPrefix } from '../utils/workspaces'
|
||||
|
||||
const DEFAULT_MAX_RESULTS = 20
|
||||
|
||||
@@ -11,12 +12,12 @@ export interface NoteSearchResult extends NoteSearchResultItem {
|
||||
entry: VaultEntry
|
||||
}
|
||||
|
||||
function toResult(e: VaultEntry, typeEntryMap: Record<string, VaultEntry>): NoteSearchResult {
|
||||
function toResult(e: VaultEntry, typeEntryMap: Record<string, VaultEntry>, showWorkspace: boolean): NoteSearchResult {
|
||||
const noteType = e.isA || undefined
|
||||
const te = typeEntryMap[e.isA ?? '']
|
||||
return {
|
||||
entry: e,
|
||||
title: e.title,
|
||||
title: `${showWorkspace ? workspaceDisplayPrefix(e) ?? '' : ''}${e.title}`,
|
||||
noteIcon: e.icon,
|
||||
noteType,
|
||||
typeColor: noteType ? getTypeColor(e.isA, te?.color) : undefined,
|
||||
@@ -36,9 +37,13 @@ export function useNoteSearch(entries: VaultEntry[], query: string, maxResults =
|
||||
() => entries.filter((e) => !SEARCH_EXCLUDED_TYPES.has(e.isA ?? '')),
|
||||
[entries],
|
||||
)
|
||||
const showWorkspace = useMemo(
|
||||
() => new Set(entries.map((entry) => entry.workspace?.alias).filter(Boolean)).size > 1,
|
||||
[entries],
|
||||
)
|
||||
|
||||
const results: NoteSearchResult[] = useMemo(() => {
|
||||
const mapResult = (e: VaultEntry) => toResult(e, typeEntryMap)
|
||||
const mapResult = (e: VaultEntry) => toResult(e, typeEntryMap, showWorkspace)
|
||||
if (!query.trim()) {
|
||||
return [...searchableEntries]
|
||||
.sort((a, b) => (b.modifiedAt ?? 0) - (a.modifiedAt ?? 0))
|
||||
@@ -55,7 +60,7 @@ export function useNoteSearch(entries: VaultEntry[], query: string, maxResults =
|
||||
.sort((a, b) => a.rank - b.rank || b.score - a.score)
|
||||
.slice(0, maxResults)
|
||||
.map((r) => mapResult(r.entry))
|
||||
}, [searchableEntries, query, maxResults, typeEntryMap])
|
||||
}, [searchableEntries, query, maxResults, typeEntryMap, showWorkspace])
|
||||
|
||||
useEffect(() => {
|
||||
setSelectedIndex(0) // eslint-disable-line react-hooks/set-state-in-effect -- reset on query change
|
||||
|
||||
Reference in New Issue
Block a user