diff --git a/surfsense_backend/app/routes/logs_routes.py b/surfsense_backend/app/routes/logs_routes.py index 98fd9141e..e7e00280e 100644 --- a/surfsense_backend/app/routes/logs_routes.py +++ b/surfsense_backend/app/routes/logs_routes.py @@ -319,6 +319,9 @@ async def get_logs_summary( if log.log_metadata else "Unknown" ) + document_id = ( + log.log_metadata.get("document_id") if log.log_metadata else None + ) summary["active_tasks"].append( { "id": log.id, @@ -326,6 +329,7 @@ async def get_logs_summary( "message": log.message, "started_at": log.created_at, "source": log.source, + "document_id": document_id, } ) diff --git a/surfsense_web/app/dashboard/[search_space_id]/documents/(manage)/components/ProcessingIndicator.tsx b/surfsense_web/app/dashboard/[search_space_id]/documents/(manage)/components/ProcessingIndicator.tsx index f0d20644c..827694d22 100644 --- a/surfsense_web/app/dashboard/[search_space_id]/documents/(manage)/components/ProcessingIndicator.tsx +++ b/surfsense_web/app/dashboard/[search_space_id]/documents/(manage)/components/ProcessingIndicator.tsx @@ -1,6 +1,6 @@ "use client"; -import { Loader2, RefreshCw } from "lucide-react"; +import { Loader2 } from "lucide-react"; import { motion, AnimatePresence } from "motion/react"; import { useTranslations } from "next-intl"; import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; @@ -22,7 +22,7 @@ export function ProcessingIndicator({ activeTasksCount }: ProcessingIndicatorPro exit={{ opacity: 0, height: 0, marginBottom: 0 }} transition={{ duration: 0.3 }} > - +
diff --git a/surfsense_web/components/sidebar/nav-notes.tsx b/surfsense_web/components/sidebar/nav-notes.tsx index 13886da05..e6ad7ea23 100644 --- a/surfsense_web/components/sidebar/nav-notes.tsx +++ b/surfsense_web/components/sidebar/nav-notes.tsx @@ -12,7 +12,8 @@ import { } from "lucide-react"; import { usePathname, useRouter } from "next/navigation"; import { useTranslations } from "next-intl"; -import { useCallback, useEffect, useState } from "react"; +import { useCallback, useEffect, useMemo, useState } from "react"; +import { useLogsSummary } from "@/hooks/use-logs"; import { Button } from "@/components/ui/button"; import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible"; import { @@ -78,6 +79,23 @@ export function NavNotes({ const [isOpen, setIsOpen] = useState(defaultOpen); const [isAllNotesSidebarOpen, setIsAllNotesSidebarOpen] = useState(false); + // Poll for active reindexing tasks to show inline loading indicators + const { summary } = useLogsSummary( + searchSpaceId ? Number(searchSpaceId) : 0, + 24, + { refetchInterval: 2000 } + ); + + // Create a Set of document IDs that are currently being reindexed + const reindexingDocumentIds = useMemo(() => { + if (!summary?.active_tasks) return new Set(); + return new Set( + summary.active_tasks + .filter((task) => task.document_id != null) + .map((task) => task.document_id as number) + ); + }, [summary?.active_tasks]); + // Auto-collapse on smaller screens when Sources is expanded useEffect(() => { if (isSourcesExpanded && isMobile) { @@ -159,6 +177,7 @@ export function NavNotes({ notes.map((note) => { const isDeletingNote = isDeleting === note.id; const isActive = pathname === note.url; + const isReindexing = note.id ? reindexingDocumentIds.has(note.id) : false; return ( @@ -172,7 +191,11 @@ export function NavNotes({ isDeletingNote && "opacity-50" )} > - + {isReindexing ? ( + + ) : ( + + )} {note.name} diff --git a/surfsense_web/contracts/types/log.types.ts b/surfsense_web/contracts/types/log.types.ts index b1e95bbf2..ac81d2d0d 100644 --- a/surfsense_web/contracts/types/log.types.ts +++ b/surfsense_web/contracts/types/log.types.ts @@ -85,6 +85,7 @@ export const logActiveTask = z.object({ message: z.string(), started_at: z.string(), source: z.string().nullable().optional(), + document_id: z.number().nullable().optional(), }); export const logFailure = z.object({ id: z.number(), diff --git a/surfsense_web/hooks/use-logs.ts b/surfsense_web/hooks/use-logs.ts index b03d302bb..643222c0c 100644 --- a/surfsense_web/hooks/use-logs.ts +++ b/surfsense_web/hooks/use-logs.ts @@ -39,6 +39,7 @@ export interface LogSummary { message: string; started_at: string; source?: string; + document_id?: number; }>; recent_failures: Array<{ id: number;