mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-30 21:59:46 +02:00
feat: add useQuery implementation with centralized cache key management in SourceDetailSheet
This commit is contained in:
parent
f92b1ab4d5
commit
013bb1547d
1 changed files with 11 additions and 0 deletions
|
|
@ -3,6 +3,9 @@
|
||||||
import { ChevronDown, ChevronUp, ExternalLink, Loader2 } from "lucide-react";
|
import { ChevronDown, ChevronUp, ExternalLink, Loader2 } from "lucide-react";
|
||||||
import type React from "react";
|
import type React from "react";
|
||||||
import { type ReactNode, useEffect, useRef, useState } from "react";
|
import { type ReactNode, useEffect, useRef, useState } from "react";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import { documentsApiService } from "@/lib/apis/documents-api.service";
|
||||||
|
import { cacheKeys } from "@/lib/query-client/cache-keys";
|
||||||
import { MarkdownViewer } from "@/components/markdown-viewer";
|
import { MarkdownViewer } from "@/components/markdown-viewer";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible";
|
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible";
|
||||||
|
|
@ -51,6 +54,14 @@ export function SourceDetailSheet({
|
||||||
const highlightedChunkRef = useRef<HTMLDivElement>(null);
|
const highlightedChunkRef = useRef<HTMLDivElement>(null);
|
||||||
const [summaryOpen, setSummaryOpen] = useState(false);
|
const [summaryOpen, setSummaryOpen] = useState(false);
|
||||||
|
|
||||||
|
// Add useQuery to fetch document by chunk
|
||||||
|
const { data: queryDocument, isLoading: queryLoading, error: queryError } = useQuery({
|
||||||
|
queryKey: cacheKeys.documents.byChunk(chunkId.toString()),
|
||||||
|
queryFn: () => documentsApiService.getDocumentByChunk({ chunk_id: chunkId }),
|
||||||
|
enabled: !!chunkId && open,
|
||||||
|
staleTime: 5 * 60 * 1000, // 5 minutes
|
||||||
|
});
|
||||||
|
|
||||||
// Check if this is a source type that should render directly from node
|
// Check if this is a source type that should render directly from node
|
||||||
const isDirectRenderSource =
|
const isDirectRenderSource =
|
||||||
sourceType === "TAVILY_API" ||
|
sourceType === "TAVILY_API" ||
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue