From ae1cd09013165381d7d26bd556d6a501bb294dcd Mon Sep 17 00:00:00 2001 From: CREDO23 Date: Fri, 12 Dec 2025 09:20:52 +0000 Subject: [PATCH] refactor: delete unused search space hooks and update exports --- surfsense_web/hooks/index.ts | 1 - surfsense_web/hooks/use-search-space.ts | 60 ------------------- surfsense_web/hooks/use-search-spaces.ts | 76 ------------------------ 3 files changed, 137 deletions(-) delete mode 100644 surfsense_web/hooks/use-search-space.ts delete mode 100644 surfsense_web/hooks/use-search-spaces.ts diff --git a/surfsense_web/hooks/index.ts b/surfsense_web/hooks/index.ts index 2cea293e8..f7ef22534 100644 --- a/surfsense_web/hooks/index.ts +++ b/surfsense_web/hooks/index.ts @@ -1,5 +1,4 @@ export * from "./use-logs"; export * from "./use-rbac"; export * from "./use-search-source-connectors"; -export * from "./use-search-space"; export * from "./use-user"; diff --git a/surfsense_web/hooks/use-search-space.ts b/surfsense_web/hooks/use-search-space.ts deleted file mode 100644 index 849aad413..000000000 --- a/surfsense_web/hooks/use-search-space.ts +++ /dev/null @@ -1,60 +0,0 @@ -"use client"; - -import { useCallback, useEffect, useState } from "react"; -import { toast } from "sonner"; -import { authenticatedFetch } from "@/lib/auth-utils"; - -interface SearchSpace { - created_at: string; - id: number; - name: string; - description: string; - user_id: string; - citations_enabled: boolean; - qna_custom_instructions: string | null; -} - -interface UseSearchSpaceOptions { - searchSpaceId: string | number; - autoFetch?: boolean; -} - -export function useSearchSpace({ searchSpaceId, autoFetch = true }: UseSearchSpaceOptions) { - const [searchSpace, setSearchSpace] = useState(null); - const [loading, setLoading] = useState(true); - const [error, setError] = useState(null); - - const fetchSearchSpace = useCallback(async () => { - try { - // Only run on client-side - if (typeof window === "undefined") return; - - setLoading(true); - const response = await authenticatedFetch( - `${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/searchspaces/${searchSpaceId}`, - { method: "GET" } - ); - - if (!response.ok) { - throw new Error(`Failed to fetch search space: ${response.status}`); - } - - const data = await response.json(); - setSearchSpace(data); - setError(null); - } catch (err: any) { - setError(err.message || "Failed to fetch search space"); - console.error("Error fetching search space:", err); - } finally { - setLoading(false); - } - }, [searchSpaceId]); - - useEffect(() => { - if (autoFetch) { - fetchSearchSpace(); - } - }, [autoFetch, fetchSearchSpace]); - - return { searchSpace, loading, error, fetchSearchSpace }; -} diff --git a/surfsense_web/hooks/use-search-spaces.ts b/surfsense_web/hooks/use-search-spaces.ts deleted file mode 100644 index 03a87881c..000000000 --- a/surfsense_web/hooks/use-search-spaces.ts +++ /dev/null @@ -1,76 +0,0 @@ -"use client"; - -import { useEffect, useState } from "react"; -import { toast } from "sonner"; -import { authenticatedFetch } from "@/lib/auth-utils"; - -interface SearchSpace { - id: number; - name: string; - description: string; - created_at: string; - citations_enabled: boolean; - qna_custom_instructions: string | null; - member_count: number; - is_owner: boolean; -} - -export function useSearchSpaces() { - const [searchSpaces, setSearchSpaces] = useState([]); - const [loading, setLoading] = useState(true); - const [error, setError] = useState(null); - - useEffect(() => { - const fetchSearchSpaces = async () => { - try { - setLoading(true); - const response = await authenticatedFetch( - `${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/searchspaces`, - { method: "GET" } - ); - - if (!response.ok) { - toast.error("Failed to fetch search spaces"); - throw new Error("Failed to fetch search spaces"); - } - - const data = await response.json(); - setSearchSpaces(data); - setError(null); - } catch (err: any) { - setError(err.message || "Failed to fetch search spaces"); - console.error("Error fetching search spaces:", err); - } finally { - setLoading(false); - } - }; - - fetchSearchSpaces(); - }, []); - - // Function to refresh the search spaces list - const refreshSearchSpaces = async () => { - setLoading(true); - try { - const response = await authenticatedFetch( - `${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/searchspaces`, - { method: "GET" } - ); - - if (!response.ok) { - toast.error("Failed to fetch search spaces"); - throw new Error("Failed to fetch search spaces"); - } - - const data = await response.json(); - setSearchSpaces(data); - setError(null); - } catch (err: any) { - setError(err.message || "Failed to fetch search spaces"); - } finally { - setLoading(false); - } - }; - - return { searchSpaces, loading, error, refreshSearchSpaces }; -}