diff --git a/surfsense_web/components/onboard/setup-prompt-step.tsx b/surfsense_web/components/onboard/setup-prompt-step.tsx index 899d856fa..3327b5489 100644 --- a/surfsense_web/components/onboard/setup-prompt-step.tsx +++ b/surfsense_web/components/onboard/setup-prompt-step.tsx @@ -12,8 +12,9 @@ import { ScrollArea } from "@/components/ui/scroll-area"; import { Switch } from "@/components/ui/switch"; import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { Textarea } from "@/components/ui/textarea"; -import { type CommunityPrompt, useCommunityPrompts } from "@/hooks/use-community-prompts"; +import { communityPromptsAtom } from "@/atoms/search-spaces/search-space-query.atoms"; import { authenticatedFetch } from "@/lib/auth-utils"; +import { useAtomValue } from "jotai"; interface SetupPromptStepProps { searchSpaceId: number; @@ -21,7 +22,9 @@ interface SetupPromptStepProps { } export function SetupPromptStep({ searchSpaceId, onComplete }: SetupPromptStepProps) { - const { prompts, loading: loadingPrompts } = useCommunityPrompts(); + const communityPromptsQuery = useAtomValue(communityPromptsAtom); + const prompts = communityPromptsQuery.data || []; + const loadingPrompts = communityPromptsQuery.isPending; const [enableCitations, setEnableCitations] = useState(true); const [customInstructions, setCustomInstructions] = useState(""); const [saving, setSaving] = useState(false); diff --git a/surfsense_web/components/settings/prompt-config-manager.tsx b/surfsense_web/components/settings/prompt-config-manager.tsx index 10f36c11e..082f438b0 100644 --- a/surfsense_web/components/settings/prompt-config-manager.tsx +++ b/surfsense_web/components/settings/prompt-config-manager.tsx @@ -24,9 +24,10 @@ import { Switch } from "@/components/ui/switch"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { Textarea } from "@/components/ui/textarea"; import { useQuery } from "@tanstack/react-query"; -import { type CommunityPrompt, useCommunityPrompts } from "@/hooks/use-community-prompts"; +import { communityPromptsAtom } from "@/atoms/search-spaces/search-space-query.atoms"; import { searchSpacesApiService } from "@/lib/apis/search-spaces-api.service"; import { cacheKeys } from "@/lib/query-client/cache-keys"; +import { useAtomValue } from "jotai"; import { authenticatedFetch } from "@/lib/auth-utils"; interface PromptConfigManagerProps { @@ -39,7 +40,9 @@ export function PromptConfigManager({ searchSpaceId }: PromptConfigManagerProps) queryFn: () => searchSpacesApiService.getSearchSpace({ id: searchSpaceId }), enabled: !!searchSpaceId, }); - const { prompts, loading: loadingPrompts } = useCommunityPrompts(); + const communityPromptsQuery = useAtomValue(communityPromptsAtom); + const prompts = communityPromptsQuery.data || []; + const loadingPrompts = communityPromptsQuery.isPending; const [enableCitations, setEnableCitations] = useState(true); const [customInstructions, setCustomInstructions] = useState(""); diff --git a/surfsense_web/hooks/use-community-prompts.ts b/surfsense_web/hooks/use-community-prompts.ts deleted file mode 100644 index 3b4ac59db..000000000 --- a/surfsense_web/hooks/use-community-prompts.ts +++ /dev/null @@ -1,45 +0,0 @@ -"use client"; - -import { useCallback, useEffect, useState } from "react"; - -export interface CommunityPrompt { - key: string; - value: string; - author: string; - link: string | null; - category?: string; -} - -export function useCommunityPrompts() { - const [prompts, setPrompts] = useState([]); - const [loading, setLoading] = useState(true); - const [error, setError] = useState(null); - - const fetchPrompts = useCallback(async () => { - try { - setLoading(true); - const response = await fetch( - `${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/searchspaces/prompts/community` - ); - - if (!response.ok) { - throw new Error(`Failed to fetch community prompts: ${response.status}`); - } - - const data = await response.json(); - setPrompts(data); - setError(null); - } catch (err: any) { - setError(err.message || "Failed to fetch community prompts"); - console.error("Error fetching community prompts:", err); - } finally { - setLoading(false); - } - }, []); - - useEffect(() => { - fetchPrompts(); - }, [fetchPrompts]); - - return { prompts, loading, error, refetch: fetchPrompts }; -}