From e31b97f60e7ce72398aa04e3cef2a7bd8262a0cf Mon Sep 17 00:00:00 2001 From: Thomas Camlong Date: Thu, 2 Oct 2025 15:20:47 +0200 Subject: [PATCH] feat(hooks): add useExistingIconNames hook and clean up debug logs - Add new useExistingIconNames hook for fetching community gallery icon names - Implement proper caching with 5-minute stale time - Remove debug console.log statements from useSubmissions hook - Improve code organization and reusability - Add proper error handling and retry configuration --- web/src/hooks/use-submissions.ts | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/web/src/hooks/use-submissions.ts b/web/src/hooks/use-submissions.ts index 6037638e..76e2290e 100644 --- a/web/src/hooks/use-submissions.ts +++ b/web/src/hooks/use-submissions.ts @@ -14,18 +14,13 @@ export function useSubmissions() { return useQuery({ queryKey: submissionKeys.lists(), queryFn: async () => { - console.log("🔍 Fetching submissions...") const records = await pb.collection("submissions").getFullList({ sort: "-updated", expand: "created_by,approved_by", requestKey: null, }) - console.log("📊 Fetched submissions:", records.length) if (records.length > 0) { - console.log("📋 First submission sample:", records[0]) - console.log("👤 First submission created_by field:", records[0].created_by) - console.log("🔗 First submission expand data:", (records[0] as any).expand) } return records @@ -105,6 +100,28 @@ export function useRejectSubmission() { }) } +// Fetch existing icon names for the combobox +export function useExistingIconNames() { + return useQuery({ + queryKey: ["existing-icon-names"], + queryFn: async () => { + const records = await pb.collection("community_gallery").getFullList({ + fields: "name", + sort: "name", + requestKey: null, + }) + + const uniqueNames = Array.from(new Set(records.map((r) => r.name))) + return uniqueNames.map((name) => ({ + label: name, + value: name, + })) + }, + staleTime: 5 * 60 * 1000, // 5 minutes + retry: false, + }) +} + // Check authentication status export function useAuth() { return useQuery({