feat(20-01): extend UIStore with FAB/catalog state, add useTags hook, update useGlobalItems
- Add fabMenuOpen, openFabMenu, closeFabMenu to UIStore - Add catalogSearchOpen, catalogSearchMode, openCatalogSearch, closeCatalogSearch - openCatalogSearch also closes FAB menu (natural flow) - Create useTags hook with 5-min staleTime cache - Add optional tags parameter to useGlobalItems for tag filtering
This commit is contained in:
@@ -23,13 +23,16 @@ interface ItemGlobalLink {
|
||||
globalItemId: number;
|
||||
}
|
||||
|
||||
export function useGlobalItems(query?: string) {
|
||||
export function useGlobalItems(query?: string, tags?: string[]) {
|
||||
const params = new URLSearchParams();
|
||||
if (query) params.set("q", query);
|
||||
if (tags && tags.length > 0) params.set("tags", tags.join(","));
|
||||
const qs = params.toString();
|
||||
|
||||
return useQuery({
|
||||
queryKey: ["global-items", query ?? ""],
|
||||
queryKey: ["global-items", query ?? "", tags ?? []],
|
||||
queryFn: () =>
|
||||
apiGet<GlobalItem[]>(
|
||||
`/api/global-items${query ? `?q=${encodeURIComponent(query)}` : ""}`,
|
||||
),
|
||||
apiGet<GlobalItem[]>(`/api/global-items${qs ? `?${qs}` : ""}`),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
15
src/client/hooks/useTags.ts
Normal file
15
src/client/hooks/useTags.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { apiGet } from "../lib/api";
|
||||
|
||||
export interface Tag {
|
||||
id: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export function useTags() {
|
||||
return useQuery({
|
||||
queryKey: ["tags"],
|
||||
queryFn: () => apiGet<Tag[]>("/api/tags"),
|
||||
staleTime: 5 * 60 * 1000,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user