diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsx index 894fde25e916..0e700369eba8 100644 --- a/apps/web/src/components/Sidebar.tsx +++ b/apps/web/src/components/Sidebar.tsx @@ -312,6 +312,8 @@ export default function Sidebar() { const renamingCommittedRef = useRef(false); const renamingInputRef = useRef(null); const [desktopUpdateState, setDesktopUpdateState] = useState(null); + const shouldBrowseForProjectImmediately = isElectron; + const shouldShowProjectPathEntry = addingProject && !shouldBrowseForProjectImmediately; const pendingApprovalByThreadId = useMemo(() => { const map = new Map(); for (const thread of threads) { @@ -523,15 +525,29 @@ export default function Sidebar() { }); await handleNewThread(projectId).catch(() => undefined); } catch (error) { + const description = + error instanceof Error ? error.message : "An error occurred while adding the project."; setIsAddingProject(false); - setAddProjectError( - error instanceof Error ? error.message : "An error occurred while adding the project.", - ); + if (shouldBrowseForProjectImmediately) { + toastManager.add({ + type: "error", + title: "Failed to add project", + description, + }); + } else { + setAddProjectError(description); + } return; } finishAddingProject(); }, - [focusMostRecentThreadForProject, handleNewThread, isAddingProject, projects], + [ + focusMostRecentThreadForProject, + handleNewThread, + isAddingProject, + projects, + shouldBrowseForProjectImmediately, + ], ); const handleAddProject = () => { @@ -550,12 +566,21 @@ export default function Sidebar() { } if (pickedPath) { await addProjectFromPath(pickedPath); - } else { + } else if (!shouldBrowseForProjectImmediately) { addProjectInputRef.current?.focus(); } setIsPickingFolder(false); }; + const handleStartAddProject = () => { + setAddProjectError(null); + if (shouldBrowseForProjectImmediately) { + void handlePickFolder(); + return; + } + setAddingProject((prev) => !prev); + }; + const cancelRename = useCallback(() => { setRenamingThreadId(null); renamingInputRef.current = null; @@ -1075,21 +1100,23 @@ export default function Sidebar() {