refactor: optimize button rendering in CreateSearchSpaceDialog and enhance watched folder ID retrieval in DocumentsSidebar

This commit is contained in:
Anish Sarkar 2026-04-08 16:17:34 +05:30
parent d009d06432
commit c9c1d239f8
2 changed files with 39 additions and 43 deletions

View file

@ -152,16 +152,10 @@ export function CreateSearchSpaceDialog({ open, onOpenChange }: CreateSearchSpac
<Button <Button
type="submit" type="submit"
disabled={isSubmitting} disabled={isSubmitting}
className="h-8 sm:h-9 text-xs sm:text-sm" className="h-8 sm:h-9 text-xs sm:text-sm relative"
> >
{isSubmitting ? ( <span className={isSubmitting ? "opacity-0" : ""}>{t("create_button")}</span>
<> {isSubmitting && <Spinner size="sm" className="absolute" />}
<Spinner size="sm" className="mr-1.5" />
{t("creating")}
</>
) : (
<>{t("create_button")}</>
)}
</Button> </Button>
</DialogFooter> </DialogFooter>
</form> </form>

View file

@ -116,48 +116,48 @@ export function DocumentsSidebar({
setFolderWatchOpen(true); setFolderWatchOpen(true);
}, []); }, []);
useEffect(() => { const refreshWatchedIds = useCallback(async () => {
if (!electronAPI?.getWatchedFolders) return; if (!electronAPI?.getWatchedFolders) return;
const api = electronAPI; const api = electronAPI;
async function loadWatchedIds() { const folders = await api.getWatchedFolders();
const folders = await api.getWatchedFolders();
if (folders.length === 0) { if (folders.length === 0) {
try { try {
const backendFolders = await documentsApiService.getWatchedFolders(searchSpaceId); const backendFolders = await documentsApiService.getWatchedFolders(searchSpaceId);
for (const bf of backendFolders) { for (const bf of backendFolders) {
const meta = bf.metadata as Record<string, unknown> | null; const meta = bf.metadata as Record<string, unknown> | null;
if (!meta?.watched || !meta.folder_path) continue; if (!meta?.watched || !meta.folder_path) continue;
await api.addWatchedFolder({ await api.addWatchedFolder({
path: meta.folder_path as string, path: meta.folder_path as string,
name: bf.name, name: bf.name,
rootFolderId: bf.id, rootFolderId: bf.id,
searchSpaceId: bf.search_space_id, searchSpaceId: bf.search_space_id,
excludePatterns: (meta.exclude_patterns as string[]) ?? [], excludePatterns: (meta.exclude_patterns as string[]) ?? [],
fileExtensions: (meta.file_extensions as string[] | null) ?? null, fileExtensions: (meta.file_extensions as string[] | null) ?? null,
active: true, active: true,
}); });
}
const recovered = await api.getWatchedFolders();
const ids = new Set(
recovered.filter((f) => f.rootFolderId != null).map((f) => f.rootFolderId as number)
);
setWatchedFolderIds(ids);
return;
} catch (err) {
console.error("[DocumentsSidebar] Recovery from backend failed:", err);
} }
const recovered = await api.getWatchedFolders();
const ids = new Set(
recovered.filter((f) => f.rootFolderId != null).map((f) => f.rootFolderId as number)
);
setWatchedFolderIds(ids);
return;
} catch (err) {
console.error("[DocumentsSidebar] Recovery from backend failed:", err);
} }
const ids = new Set(
folders.filter((f) => f.rootFolderId != null).map((f) => f.rootFolderId as number)
);
setWatchedFolderIds(ids);
} }
loadWatchedIds(); const ids = new Set(
folders.filter((f) => f.rootFolderId != null).map((f) => f.rootFolderId as number)
);
setWatchedFolderIds(ids);
}, [searchSpaceId, electronAPI]); }, [searchSpaceId, electronAPI]);
useEffect(() => {
refreshWatchedIds();
}, [refreshWatchedIds]);
const { mutateAsync: deleteDocumentMutation } = useAtomValue(deleteDocumentMutationAtom); const { mutateAsync: deleteDocumentMutation } = useAtomValue(deleteDocumentMutationAtom);
const [sidebarDocs, setSidebarDocs] = useAtom(sidebarSelectedDocumentsAtom); const [sidebarDocs, setSidebarDocs] = useAtom(sidebarSelectedDocumentsAtom);
@ -342,8 +342,9 @@ export function DocumentsSidebar({
console.error("[DocumentsSidebar] Failed to clear watched metadata:", err); console.error("[DocumentsSidebar] Failed to clear watched metadata:", err);
} }
toast.success(`Stopped watching: ${matched.name}`); toast.success(`Stopped watching: ${matched.name}`);
refreshWatchedIds();
}, },
[electronAPI] [electronAPI, refreshWatchedIds]
); );
const handleRenameFolder = useCallback(async (folder: FolderDisplay, newName: string) => { const handleRenameFolder = useCallback(async (folder: FolderDisplay, newName: string) => {
@ -872,6 +873,7 @@ export function DocumentsSidebar({
}} }}
searchSpaceId={searchSpaceId} searchSpaceId={searchSpaceId}
initialFolder={watchInitialFolder} initialFolder={watchInitialFolder}
onSuccess={refreshWatchedIds}
/> />
)} )}