From e5d1598270891f339f8411ef528c0643a8bae1c3 Mon Sep 17 00:00:00 2001 From: CREDO23 Date: Thu, 4 Dec 2025 13:12:15 +0000 Subject: [PATCH] refactor: remove unused use-document-by-chunk hook - Delete use-document-by-chunk.ts file - Remove export from hooks index - Hook has been replaced with useQuery implementation in SourceDetailSheet --- surfsense_web/hooks/index.ts | 1 - surfsense_web/hooks/use-document-by-chunk.ts | 106 ------------------- 2 files changed, 107 deletions(-) delete mode 100644 surfsense_web/hooks/use-document-by-chunk.ts diff --git a/surfsense_web/hooks/index.ts b/surfsense_web/hooks/index.ts index a244609a2..2cea293e8 100644 --- a/surfsense_web/hooks/index.ts +++ b/surfsense_web/hooks/index.ts @@ -1,4 +1,3 @@ -export * from "./use-document-by-chunk"; export * from "./use-logs"; export * from "./use-rbac"; export * from "./use-search-source-connectors"; diff --git a/surfsense_web/hooks/use-document-by-chunk.ts b/surfsense_web/hooks/use-document-by-chunk.ts deleted file mode 100644 index 630e810a2..000000000 --- a/surfsense_web/hooks/use-document-by-chunk.ts +++ /dev/null @@ -1,106 +0,0 @@ -"use client"; -import { useCallback, useState } from "react"; -import { toast } from "sonner"; -import { authenticatedFetch } from "@/lib/auth-utils"; - -export interface Chunk { - id: number; - content: string; - document_id: number; - created_at: string; -} - -export interface DocumentWithChunks { - id: number; - title: string; - document_type: DocumentType; - document_metadata: any; - content: string; - created_at: string; - search_space_id: number; - chunks: Chunk[]; -} - -export type DocumentType = - | "EXTENSION" - | "CRAWLED_URL" - | "SLACK_CONNECTOR" - | "NOTION_CONNECTOR" - | "FILE" - | "YOUTUBE_VIDEO" - | "GITHUB_CONNECTOR" - | "LINEAR_CONNECTOR" - | "DISCORD_CONNECTOR" - | "JIRA_CONNECTOR" - | "CONFLUENCE_CONNECTOR" - | "CLICKUP_CONNECTOR" - | "GOOGLE_CALENDAR_CONNECTOR" - | "GOOGLE_GMAIL_CONNECTOR" - | "LUMA_CONNECTOR" - | "ELASTICSEARCH_CONNECTOR"; - -export function useDocumentByChunk() { - const [document, setDocument] = useState(null); - const [loading, setLoading] = useState(false); - const [error, setError] = useState(null); - - const fetchDocumentByChunk = useCallback(async (chunkId: number) => { - try { - setLoading(true); - setError(null); - setDocument(null); - - const response = await authenticatedFetch( - `${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/documents/by-chunk/${chunkId}`, - { - headers: { "Content-Type": "application/json" }, - method: "GET", - } - ); - - if (!response.ok) { - const errorText = await response.text(); - let errorMessage = "Failed to fetch document"; - - try { - const errorData = JSON.parse(errorText); - errorMessage = errorData.detail || errorMessage; - } catch { - // If parsing fails, use default message - } - - if (response.status === 404) { - errorMessage = "Chunk not found or you don't have access to it"; - } - - toast.error(errorMessage); - throw new Error(errorMessage); - } - - const data: DocumentWithChunks = await response.json(); - setDocument(data); - setError(null); - return data; - } catch (err: any) { - const errorMessage = err.message || "Failed to fetch document"; - setError(errorMessage); - console.error("Error fetching document by chunk:", err); - throw err; - } finally { - setLoading(false); - } - }, []); - - const clearDocument = useCallback(() => { - setDocument(null); - setError(null); - }, []); - - return { - document, - loading, - error, - fetchDocumentByChunk, - clearDocument, - }; -}