()
| 47 | | `tag:${string}`; |
| 48 | |
| 49 | export default function SearchNotes(): ReactElement { |
| 50 | const [notes, setNotes] = useState<ZenNote[]>([]); |
| 51 | const [vaultRoot, setVaultRoot] = useState<string | null>(null); |
| 52 | const [isLoading, setIsLoading] = useState(true); |
| 53 | const [error, setError] = useState<LoadError | null>(null); |
| 54 | const [filter, setFilter] = useState<FilterValue>("all"); |
| 55 | |
| 56 | const load = useCallback(async () => { |
| 57 | setIsLoading(true); |
| 58 | setError(null); |
| 59 | try { |
| 60 | const nextNotes = await loadNotes(); |
| 61 | const nextVaultRoot = await loadVaultRoot().catch(() => null); |
| 62 | setNotes(nextNotes); |
| 63 | setVaultRoot(nextVaultRoot); |
| 64 | } catch (err) { |
| 65 | setNotes([]); |
| 66 | setVaultRoot(null); |
| 67 | setError(toLoadError(err)); |
| 68 | } finally { |
| 69 | setIsLoading(false); |
| 70 | } |
| 71 | }, []); |
| 72 | |
| 73 | useEffect(() => { |
| 74 | void load(); |
| 75 | }, [load]); |
| 76 | |
| 77 | const emptyView = useMemo(() => { |
| 78 | if (!error) { |
| 79 | return ( |
| 80 | <List.EmptyView |
| 81 | icon={Icon.MagnifyingGlass} |
| 82 | title="No notes found" |
| 83 | description="ZenNotes returned no notes for this vault." |
| 84 | actions={<RefreshActions onRefresh={load} />} |
| 85 | /> |
| 86 | ); |
| 87 | } |
| 88 | |
| 89 | return ( |
| 90 | <List.EmptyView |
| 91 | icon={Icon.Warning} |
| 92 | title={error.title} |
| 93 | description={error.message} |
| 94 | actions={<ErrorActions onRefresh={load} />} |
| 95 | /> |
| 96 | ); |
| 97 | }, [error, load]); |
| 98 | |
| 99 | const filteredNotes = useMemo( |
| 100 | () => filterNotes(notes, filter), |
| 101 | [filter, notes], |
| 102 | ); |
| 103 | const availableTags = useMemo(() => collectTags(notes), [notes]); |
| 104 | |
| 105 | return ( |
| 106 | <List |
nothing calls this directly
no test coverage detected