-
Notifications
You must be signed in to change notification settings - Fork 897
fix(desktop): persist new workspace modal state #2194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,6 +8,11 @@ import { electronTrpc } from "renderer/lib/electron-trpc"; | |||||||||||
| import { useCreateBranchWorkspace } from "renderer/react-query/workspaces"; | ||||||||||||
| import { navigateToWorkspace } from "renderer/routes/_authenticated/_dashboard/utils/workspace-navigation"; | ||||||||||||
| import { useHotkeysStore } from "renderer/stores/hotkeys/store"; | ||||||||||||
| import { | ||||||||||||
| useClearNewWorkspaceModalInputs, | ||||||||||||
| useClearNewWorkspaceModalInputsIfDraftVersion, | ||||||||||||
| useNewWorkspaceModalDraftVersion, | ||||||||||||
| } from "renderer/stores/new-workspace-modal"; | ||||||||||||
|
|
||||||||||||
| interface BranchesGroupProps { | ||||||||||||
| projectId: string | null; | ||||||||||||
|
|
@@ -19,6 +24,10 @@ export function BranchesGroup({ projectId, onClose }: BranchesGroupProps) { | |||||||||||
| const modKey = platform === "darwin" ? "⌘" : "Ctrl"; | ||||||||||||
| const navigate = useNavigate(); | ||||||||||||
| const createBranchWorkspace = useCreateBranchWorkspace(); | ||||||||||||
| const clearInputs = useClearNewWorkspaceModalInputs(); | ||||||||||||
| const clearInputsIfDraftVersion = | ||||||||||||
| useClearNewWorkspaceModalInputsIfDraftVersion(); | ||||||||||||
| const draftVersion = useNewWorkspaceModalDraftVersion(); | ||||||||||||
|
|
||||||||||||
| const { data, isLoading } = electronTrpc.projects.getBranches.useQuery( | ||||||||||||
| { projectId: projectId ?? "" }, | ||||||||||||
|
|
@@ -52,29 +61,40 @@ export function BranchesGroup({ projectId, onClose }: BranchesGroupProps) { | |||||||||||
| const handleCreate = useCallback( | ||||||||||||
| (branchName: string) => { | ||||||||||||
| if (!projectId) return; | ||||||||||||
| const submitDraftVersion = draftVersion; | ||||||||||||
| const createWorkspacePromise = createBranchWorkspace.mutateAsync({ | ||||||||||||
| projectId, | ||||||||||||
| branch: branchName, | ||||||||||||
| }); | ||||||||||||
| onClose(); | ||||||||||||
| toast.promise( | ||||||||||||
| createBranchWorkspace.mutateAsync({ | ||||||||||||
| projectId, | ||||||||||||
| branch: branchName, | ||||||||||||
| }), | ||||||||||||
| { | ||||||||||||
| loading: "Creating workspace from branch...", | ||||||||||||
| success: "Workspace created", | ||||||||||||
| error: (err) => | ||||||||||||
| err instanceof Error ? err.message : "Failed to create workspace", | ||||||||||||
| }, | ||||||||||||
| ); | ||||||||||||
| toast.promise(createWorkspacePromise, { | ||||||||||||
| loading: "Creating workspace from branch...", | ||||||||||||
| success: "Workspace created", | ||||||||||||
| error: (err) => | ||||||||||||
| err instanceof Error ? err.message : "Failed to create workspace", | ||||||||||||
| }); | ||||||||||||
| void createWorkspacePromise | ||||||||||||
| .then(() => { | ||||||||||||
| clearInputsIfDraftVersion(submitDraftVersion); | ||||||||||||
| }) | ||||||||||||
| .catch(() => undefined); | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Avoid swallowing create-workspace errors in an empty catch; log the rejection context so failures remain observable. (Based on your team's feedback about avoiding empty catch blocks that hide failures.) Prompt for AI agents
Suggested change
|
||||||||||||
| }, | ||||||||||||
| [projectId, onClose, createBranchWorkspace], | ||||||||||||
| [ | ||||||||||||
| clearInputsIfDraftVersion, | ||||||||||||
| createBranchWorkspace, | ||||||||||||
| draftVersion, | ||||||||||||
| onClose, | ||||||||||||
| projectId, | ||||||||||||
| ], | ||||||||||||
| ); | ||||||||||||
|
|
||||||||||||
| const handleOpen = useCallback( | ||||||||||||
| (workspaceId: string) => { | ||||||||||||
| clearInputs(); | ||||||||||||
| onClose(); | ||||||||||||
| navigateToWorkspace(workspaceId, navigate); | ||||||||||||
| }, | ||||||||||||
| [onClose, navigate], | ||||||||||||
| [clearInputs, onClose, navigate], | ||||||||||||
| ); | ||||||||||||
|
|
||||||||||||
| if (!projectId) { | ||||||||||||
|
|
||||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -19,6 +19,11 @@ import { | |||||
| } from "renderer/routes/_authenticated/_dashboard/tasks/components/TasksView/components/shared/StatusIcon"; | ||||||
| import { navigateToWorkspace } from "renderer/routes/_authenticated/_dashboard/utils/workspace-navigation"; | ||||||
| import { useCollections } from "renderer/routes/_authenticated/providers/CollectionsProvider"; | ||||||
| import { | ||||||
| useClearNewWorkspaceModalInputs, | ||||||
| useClearNewWorkspaceModalInputsIfDraftVersion, | ||||||
| useNewWorkspaceModalDraftVersion, | ||||||
| } from "renderer/stores/new-workspace-modal"; | ||||||
|
|
||||||
| interface IssuesGroupProps { | ||||||
| projectId: string | null; | ||||||
|
|
@@ -30,6 +35,10 @@ export function IssuesGroup({ projectId, onClose }: IssuesGroupProps) { | |||||
| const navigate = useNavigate(); | ||||||
| const { gateFeature } = usePaywall(); | ||||||
| const createWorkspace = useCreateWorkspace(); | ||||||
| const clearInputs = useClearNewWorkspaceModalInputs(); | ||||||
| const clearInputsIfDraftVersion = | ||||||
| useClearNewWorkspaceModalInputsIfDraftVersion(); | ||||||
| const draftVersion = useNewWorkspaceModalDraftVersion(); | ||||||
|
|
||||||
| const { data: integrations } = useLiveQuery( | ||||||
| (q) => | ||||||
|
|
@@ -125,26 +134,31 @@ export function IssuesGroup({ projectId, onClose }: IssuesGroupProps) { | |||||
| } | ||||||
| const existingId = workspaceByBranch.get(task.slug.toLowerCase()); | ||||||
| if (existingId) { | ||||||
| clearInputs(); | ||||||
| onClose(); | ||||||
| navigateToWorkspace(existingId, navigate); | ||||||
| return; | ||||||
| } | ||||||
| const submitDraftVersion = draftVersion; | ||||||
| const createWorkspacePromise = createWorkspace.mutateAsync({ | ||||||
| projectId, | ||||||
| name: task.title, | ||||||
| branchName: task.slug.toLowerCase(), | ||||||
| }); | ||||||
| onClose(); | ||||||
| toast.promise( | ||||||
| createWorkspace.mutateAsync({ | ||||||
| projectId, | ||||||
| name: task.title, | ||||||
| branchName: task.slug.toLowerCase(), | ||||||
| }), | ||||||
| { | ||||||
| loading: "Creating workspace...", | ||||||
| success: "Workspace created", | ||||||
| error: (err) => | ||||||
| err instanceof Error | ||||||
| ? err.message | ||||||
| : "Failed to create workspace", | ||||||
| }, | ||||||
| ); | ||||||
| toast.promise(createWorkspacePromise, { | ||||||
| loading: "Creating workspace...", | ||||||
| success: "Workspace created", | ||||||
| error: (err) => | ||||||
| err instanceof Error | ||||||
| ? err.message | ||||||
| : "Failed to create workspace", | ||||||
| }); | ||||||
| void createWorkspacePromise | ||||||
| .then(() => { | ||||||
| clearInputsIfDraftVersion(submitDraftVersion); | ||||||
| }) | ||||||
| .catch(() => undefined); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: Avoid using an empty catch here; log the rejected error so create-workspace failures are still diagnosable. (Based on your team's feedback about avoiding empty catch blocks that hide failures.) Prompt for AI agents
Suggested change
|
||||||
| }} | ||||||
| className="group h-12" | ||||||
| > | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: This condition resets the selected project while recents are still loading (empty array), which can wipe the persisted project selection on reopen.
Prompt for AI agents