diff options
| author | Adam <[email protected]> | 2025-10-30 14:41:13 -0500 |
|---|---|---|
| committer | Adam <[email protected]> | 2025-10-30 14:41:15 -0500 |
| commit | 48f50cf55ea1cff07b69bede05e6010ea50778f0 (patch) | |
| tree | cd7ea28588ad96c4467a415e55f5fc005dff90c4 /packages/ui/src/hooks | |
| parent | ba13f8da08f54a5362ac5432885be30ac1508203 (diff) | |
| download | opencode-48f50cf55ea1cff07b69bede05e6010ea50778f0.tar.gz opencode-48f50cf55ea1cff07b69bede05e6010ea50778f0.zip | |
wip: desktop work
Diffstat (limited to 'packages/ui/src/hooks')
| -rw-r--r-- | packages/ui/src/hooks/use-filtered-list.tsx | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/packages/ui/src/hooks/use-filtered-list.tsx b/packages/ui/src/hooks/use-filtered-list.tsx index b3ddf69ed..ca9bc5388 100644 --- a/packages/ui/src/hooks/use-filtered-list.tsx +++ b/packages/ui/src/hooks/use-filtered-list.tsx @@ -11,18 +11,22 @@ export interface FilteredListProps<T> { current?: T groupBy?: (x: T) => string sortBy?: (a: T, b: T) => number - sortGroupsBy?: (a: { category: string; items: T[] }, b: { category: string; items: T[] }) => number + sortGroupsBy?: ( + a: { category: string; items: T[] }, + b: { category: string; items: T[] }, + ) => number onSelect?: (value: T | undefined) => void } export function useFilteredList<T>(props: FilteredListProps<T>) { const [store, setStore] = createStore<{ filter: string }>({ filter: "" }) - const [grouped] = createResource( + const [grouped, { refetch }] = createResource( () => store.filter, async (filter) => { const needle = filter?.toLowerCase() - const all = (typeof props.items === "function" ? await props.items(needle) : props.items) || [] + const all = + (typeof props.items === "function" ? await props.items(needle) : props.items) || [] const result = pipe( all, (x) => { @@ -76,10 +80,11 @@ export function useFilteredList<T>(props: FilteredListProps<T>) { } return { - filter: () => store.filter, grouped, + filter: () => store.filter, flat, reset, + refetch, clear: () => setStore("filter", ""), onKeyDown, onInput, |
