diff --git a/surfsense_web/app/dashboard/[search_space_id]/documents/(manage)/components/DocumentsFilters.tsx b/surfsense_web/app/dashboard/[search_space_id]/documents/(manage)/components/DocumentsFilters.tsx index b514d0ed7..eb7a4517c 100644 --- a/surfsense_web/app/dashboard/[search_space_id]/documents/(manage)/components/DocumentsFilters.tsx +++ b/surfsense_web/app/dashboard/[search_space_id]/documents/(manage)/components/DocumentsFilters.tsx @@ -2,7 +2,6 @@ import { CircleAlert, - FileType, ListFilter, Search, Trash, @@ -90,7 +89,7 @@ export function DocumentsFilters({ size="icon" className="h-9 w-9 shrink-0 border-dashed border-border/60 text-muted-foreground hover:text-foreground hover:border-border" > - + {activeTypes.length > 0 && ( {activeTypes.length} @@ -174,7 +173,7 @@ export function DocumentsFilters({ {/* Search Input */} - + onSort(sortKey)} - className="flex items-center gap-1.5 text-left text-sm font-medium text-muted-foreground/70 hover:text-muted-foreground transition-colors group" + className="flex items-center gap-1.5 text-left text-sm font-medium text-muted-foreground hover:text-muted-foreground transition-colors group" > - {icon && {icon}} + {icon && {icon}} {children} + {/* Desktop Table View */} + + + + + + + toggleAll(!!v)} + aria-label="Select all" + className="border-foreground data-[state=checked]:bg-primary data-[state=checked]:border-primary" + /> + + + + } + > + Document + + + + + + + + + + Status + + + + + {loading ? ( - <> - {/* Desktop Skeleton */} - - - - - + + + + {[65, 80, 45, 72, 55, 88, 40, 60, 50, 75].map((widthPercent) => ( + + - - - - - - - - - - - - - - - - - {[65, 80, 45, 72, 55, 88, 40, 60, 50, 75].map((widthPercent) => ( - - - - - - - - - - - - - - - - - ))} - - - - - {/* Mobile Skeleton */} - - {[70, 85, 55, 78, 62, 90].map((widthPercent) => ( - - - - + + - - - - - - - - ))} - - > + + + + + + + + + ))} + + + ) : error ? ( @@ -548,49 +545,9 @@ export function DocumentsTableShell({ ) : ( - <> - {/* Desktop Table View */} - - - - - - - toggleAll(!!v)} - aria-label="Select all" - className="border-foreground data-[state=checked]:bg-primary data-[state=checked]:border-primary" - /> - - - - } - > - Document - - - - - - - - - - Status - - - - - - - - + + + {sorted.map((doc, index) => { const isSelected = selectedIds.has(doc.id); const canSelect = isSelectable(doc); @@ -659,80 +616,98 @@ export function DocumentsTableShell({ })} - {hasMore && ( - - )} - - - - {/* Mobile Card View */} - - {sorted.map((doc, index) => { - const isSelected = selectedIds.has(doc.id); - const canSelect = isSelectable(doc); - return ( - - - - - canSelect && toggleOne(doc.id, !!v) - } - disabled={!canSelect} - aria-label={ - canSelect - ? "Select row" - : "Cannot select while processing" - } - className={`border-foreground data-[state=checked]:bg-primary data-[state=checked]:border-primary shrink-0 ${!canSelect ? "opacity-40 cursor-not-allowed" : ""}`} - /> - - - - - - - - {getDocumentTypeIcon( - doc.document_type, - "h-4 w-4" - )} - - - - {getDocumentTypeLabel(doc.document_type)} - - - - - - - - ); - })} {hasMore && ( - + )} - > )} + + + {/* Mobile Card View */} + {loading ? ( + + {[70, 85, 55, 78, 62, 90].map((widthPercent) => ( + + + + + + + + + + + + + ))} + + ) : !error && sorted.length > 0 && ( + + {sorted.map((doc, index) => { + const isSelected = selectedIds.has(doc.id); + const canSelect = isSelectable(doc); + return ( + + + + + canSelect && toggleOne(doc.id, !!v) + } + disabled={!canSelect} + aria-label={ + canSelect + ? "Select row" + : "Cannot select while processing" + } + className={`border-foreground data-[state=checked]:bg-primary data-[state=checked]:border-primary shrink-0 ${!canSelect ? "opacity-40 cursor-not-allowed" : ""}`} + /> + + + + + + + + {getDocumentTypeIcon( + doc.document_type, + "h-4 w-4" + )} + + + + {getDocumentTypeLabel(doc.document_type)} + + + + + + + + ); + })} + {hasMore && ( + + )} + + )} {/* Document Content Viewer */} !open && handleCloseViewer()}> diff --git a/surfsense_web/hooks/use-documents.ts b/surfsense_web/hooks/use-documents.ts index 96243049a..c2ce390d7 100644 --- a/surfsense_web/hooks/use-documents.ts +++ b/surfsense_web/hooks/use-documents.ts @@ -156,10 +156,13 @@ export function useDocuments( let cancelled = false; - setLoading(true); - setDocuments([]); - setTotal(0); - setHasMore(false); + const isRefresh = initialLoadDoneRef.current; + if (!isRefresh) { + setLoading(true); + setDocuments([]); + setTotal(0); + setHasMore(false); + } apiLoadedCountRef.current = 0; initialLoadDoneRef.current = false; electricBaselineIdsRef.current = null;