mirror of
https://github.com/getpaseo/paseo.git
synced 2026-07-29 12:01:31 +00:00
fix(app): redirect optimistically when archiving worktree from toolbar (#852)
The toolbar archive deferred its redirect until the server confirmed the archive, so users briefly landed on the "workspace not found" gate and were then sent to the main checkout's workspace route. Mirror the sidebar pattern: synchronously router.replace to the project's new workspace screen up front and let archive reconcile only update the store.
This commit is contained in:
@@ -1,14 +1,16 @@
|
|||||||
import { useState, useCallback, useEffect, useMemo, type ReactElement } from "react";
|
import { useState, useCallback, useEffect, useMemo, type ReactElement } from "react";
|
||||||
|
import { router, type Href } from "expo-router";
|
||||||
import AsyncStorage from "@react-native-async-storage/async-storage";
|
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||||
import { type CheckoutGitActionStatus, useCheckoutGitActionsStore } from "@/git/actions-store";
|
import { type CheckoutGitActionStatus, useCheckoutGitActionsStore } from "@/git/actions-store";
|
||||||
import { type CheckoutStatusPayload, useCheckoutStatusQuery } from "@/git/use-status-query";
|
import { type CheckoutStatusPayload, useCheckoutStatusQuery } from "@/git/use-status-query";
|
||||||
import { type CheckoutPrStatusPayload, useCheckoutPrStatusQuery } from "@/git/use-pr-status-query";
|
import { type CheckoutPrStatusPayload, useCheckoutPrStatusQuery } from "@/git/use-pr-status-query";
|
||||||
import { buildGitActions, narrowPullRequestState, type GitActions } from "@/git/policy";
|
import { buildGitActions, narrowPullRequestState, type GitActions } from "@/git/policy";
|
||||||
import type { CheckoutPrMergeMethod } from "@server/shared/messages";
|
import type { CheckoutPrMergeMethod } from "@server/shared/messages";
|
||||||
import { resolveNewAgentWorkingDir } from "@/utils/new-agent-routing";
|
|
||||||
import { openExternalUrl } from "@/utils/open-external-url";
|
import { openExternalUrl } from "@/utils/open-external-url";
|
||||||
import { useToast } from "@/contexts/toast-context";
|
import { useToast } from "@/contexts/toast-context";
|
||||||
import { navigateToWorkspace } from "@/hooks/use-workspace-navigation";
|
import { useSessionStore } from "@/stores/session-store";
|
||||||
|
import { resolveWorkspaceIdByExecutionDirectory } from "@/utils/workspace-execution";
|
||||||
|
import { buildWorkspaceArchiveRedirectRoute } from "@/utils/workspace-archive-navigation";
|
||||||
|
|
||||||
export type { GitActionId, GitAction, GitActions } from "@/git/policy";
|
export type { GitActionId, GitAction, GitActions } from "@/git/policy";
|
||||||
|
|
||||||
@@ -393,15 +395,22 @@ export function useGitActions({ serverId, cwd, icons }: UseGitActionsInput): Use
|
|||||||
toast.error("Worktree path unavailable");
|
toast.error("Worktree path unavailable");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const targetWorkingDir = resolveNewAgentWorkingDir(cwd, status ?? null);
|
const workspaces = useSessionStore.getState().sessions[serverId]?.workspaces;
|
||||||
void runArchiveWorktree({ serverId, cwd, worktreePath })
|
const archivedWorkspaceId =
|
||||||
.then(() => {
|
resolveWorkspaceIdByExecutionDirectory({
|
||||||
navigateToWorkspace(serverId, targetWorkingDir);
|
workspaces: workspaces?.values(),
|
||||||
return;
|
workspaceDirectory: worktreePath,
|
||||||
})
|
}) ?? worktreePath;
|
||||||
.catch((err) => {
|
router.replace(
|
||||||
toastActionError(err, "Failed to archive worktree");
|
buildWorkspaceArchiveRedirectRoute({
|
||||||
});
|
serverId,
|
||||||
|
archivedWorkspaceId,
|
||||||
|
workspaces: workspaces?.values() ?? [],
|
||||||
|
}) as Href,
|
||||||
|
);
|
||||||
|
void runArchiveWorktree({ serverId, cwd, worktreePath }).catch((err) => {
|
||||||
|
toastActionError(err, "Failed to archive worktree");
|
||||||
|
});
|
||||||
}, [cwd, runArchiveWorktree, serverId, status, toast, toastActionError]);
|
}, [cwd, runArchiveWorktree, serverId, status, toast, toastActionError]);
|
||||||
|
|
||||||
const baseRefLabel = useMemo(() => formatBaseRefLabel(baseRef), [baseRef]);
|
const baseRefLabel = useMemo(() => formatBaseRefLabel(baseRef), [baseRef]);
|
||||||
|
|||||||
Reference in New Issue
Block a user