From b7c9077fb2f90e5d15a4c930aca473476d336a99 Mon Sep 17 00:00:00 2001 From: Anish Sarkar <104695310+AnishSarkar22@users.noreply.github.com> Date: Wed, 8 Apr 2026 04:42:07 +0530 Subject: [PATCH] feat: enhance folder watching experience by adding initial folder selection and updating state management in DocumentsSidebar and FolderWatchDialog --- .../layout/ui/sidebar/DocumentsSidebar.tsx | 24 ++++++++++++++--- .../components/sources/FolderWatchDialog.tsx | 27 ++++++++++++------- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/surfsense_web/components/layout/ui/sidebar/DocumentsSidebar.tsx b/surfsense_web/components/layout/ui/sidebar/DocumentsSidebar.tsx index d182317e4..daf85bec9 100644 --- a/surfsense_web/components/layout/ui/sidebar/DocumentsSidebar.tsx +++ b/surfsense_web/components/layout/ui/sidebar/DocumentsSidebar.tsx @@ -20,7 +20,7 @@ import { CreateFolderDialog } from "@/components/documents/CreateFolderDialog"; import type { DocumentNodeDoc } from "@/components/documents/DocumentNode"; import type { FolderDisplay } from "@/components/documents/FolderNode"; import { FolderPickerDialog } from "@/components/documents/FolderPickerDialog"; -import { FolderWatchDialog } from "@/components/sources/FolderWatchDialog"; +import { FolderWatchDialog, type SelectedFolder } from "@/components/sources/FolderWatchDialog"; import { FolderTreeView } from "@/components/documents/FolderTreeView"; import { VersionHistoryDialog } from "@/components/documents/version-history"; import { EXPORT_FILE_EXTENSIONS } from "@/components/shared/ExportMenuItems"; @@ -97,8 +97,22 @@ export function DocumentsSidebar({ const [activeTypes, setActiveTypes] = useState([]); const [watchedFolderIds, setWatchedFolderIds] = useState>(new Set()); const [folderWatchOpen, setFolderWatchOpen] = useState(false); + const [watchInitialFolder, setWatchInitialFolder] = useState(null); const isElectron = typeof window !== "undefined" && !!window.electronAPI; + const handleWatchLocalFolder = useCallback(async () => { + const api = window.electronAPI; + if (!api?.selectFolder) return; + + const folderPath = await api.selectFolder(); + if (!folderPath) return; + + const folderName = + folderPath.split("/").pop() || folderPath.split("\\").pop() || folderPath; + setWatchInitialFolder({ path: folderPath, name: folderName }); + setFolderWatchOpen(true); + }, []); + useEffect(() => { const api = typeof window !== "undefined" ? window.electronAPI : null; if (!api?.getWatchedFolders) return; @@ -754,7 +768,7 @@ export function DocumentsSidebar({ {isElectron && (