Compare commits
18
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0d4a38f079 | ||
|
|
f3b65dbedf | ||
|
|
38667d323c | ||
|
|
e829f971ce | ||
|
|
37cd7be09b | ||
|
|
aa6412c3ba | ||
|
|
04d86b0559 | ||
|
|
d4447da322 | ||
|
|
2512721b13 | ||
|
|
07d5dc1f25 | ||
|
|
3125dd80a7 | ||
|
|
25579c9942 | ||
|
|
5caae992e3 | ||
|
|
beb9201f5d | ||
|
|
c129be5e21 | ||
|
|
5aaae6cb60 | ||
|
|
8b94f007f2 | ||
|
|
80ce01b8e6 |
No files matched your search
@@ -239,207 +239,6 @@ describe("git integration", () => {
|
||||
expect(current!.name).toBe("feature");
|
||||
});
|
||||
|
||||
it("refreshes upstream behind count after checkout when remote branch advanced", async () => {
|
||||
await using remote = await makeTmpDir();
|
||||
await using source = await makeTmpDir();
|
||||
await using clone = await makeTmpDir();
|
||||
await git(remote.path, "init --bare");
|
||||
|
||||
await initRepoWithCommit(source.path);
|
||||
const defaultBranch = (await listGitBranches({ cwd: source.path })).branches.find(
|
||||
(branch) => branch.current,
|
||||
)!.name;
|
||||
await git(source.path, `remote add origin ${JSON.stringify(remote.path)}`);
|
||||
await git(source.path, `push -u origin ${defaultBranch}`);
|
||||
|
||||
const featureBranch = "feature-behind";
|
||||
await createGitBranch({ cwd: source.path, branch: featureBranch });
|
||||
await checkoutGitBranch({ cwd: source.path, branch: featureBranch });
|
||||
await writeFile(path.join(source.path, "feature.txt"), "feature base\n");
|
||||
await git(source.path, "add feature.txt");
|
||||
await git(source.path, "commit -m 'feature base'");
|
||||
await git(source.path, `push -u origin ${featureBranch}`);
|
||||
await checkoutGitBranch({ cwd: source.path, branch: defaultBranch });
|
||||
|
||||
await git(clone.path, `clone ${JSON.stringify(remote.path)} .`);
|
||||
await git(clone.path, "config user.email '[email protected]'");
|
||||
await git(clone.path, "config user.name 'Test'");
|
||||
await git(clone.path, `checkout -b ${featureBranch} --track origin/${featureBranch}`);
|
||||
await writeFile(path.join(clone.path, "feature.txt"), "feature from remote\n");
|
||||
await git(clone.path, "add feature.txt");
|
||||
await git(clone.path, "commit -m 'remote feature update'");
|
||||
await git(clone.path, `push origin ${featureBranch}`);
|
||||
|
||||
await checkoutGitBranch({ cwd: source.path, branch: featureBranch });
|
||||
const core = new GitCoreService();
|
||||
await vi.waitFor(async () => {
|
||||
const details = await core.statusDetails(source.path);
|
||||
expect(details.branch).toBe(featureBranch);
|
||||
expect(details.aheadCount).toBe(0);
|
||||
expect(details.behindCount).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps checkout successful when upstream refresh fails", async () => {
|
||||
await using remote = await makeTmpDir();
|
||||
await using source = await makeTmpDir();
|
||||
await git(remote.path, "init --bare");
|
||||
|
||||
await initRepoWithCommit(source.path);
|
||||
const defaultBranch = (await listGitBranches({ cwd: source.path })).branches.find(
|
||||
(branch) => branch.current,
|
||||
)!.name;
|
||||
await git(source.path, `remote add origin ${JSON.stringify(remote.path)}`);
|
||||
await git(source.path, `push -u origin ${defaultBranch}`);
|
||||
|
||||
const featureBranch = "feature-refresh-failure";
|
||||
await git(source.path, `branch ${featureBranch}`);
|
||||
await git(source.path, `checkout ${featureBranch}`);
|
||||
await writeFile(path.join(source.path, "feature.txt"), "feature base\n");
|
||||
await git(source.path, "add feature.txt");
|
||||
await git(source.path, "commit -m 'feature base'");
|
||||
await git(source.path, `push -u origin ${featureBranch}`);
|
||||
await git(source.path, `checkout ${defaultBranch}`);
|
||||
|
||||
class RefreshFailingGitCoreService extends GitCoreService {
|
||||
refreshFetchAttempts = 0;
|
||||
|
||||
override async git(
|
||||
cwd: string,
|
||||
args: readonly string[],
|
||||
allowNonZeroExit = false,
|
||||
): Promise<void> {
|
||||
if (args[0] === "fetch") {
|
||||
this.refreshFetchAttempts += 1;
|
||||
throw new Error("simulated fetch timeout");
|
||||
}
|
||||
await super.git(cwd, args, allowNonZeroExit);
|
||||
}
|
||||
}
|
||||
|
||||
const core = new RefreshFailingGitCoreService();
|
||||
await expect(core.checkoutBranch({ cwd: source.path, branch: featureBranch })).resolves.toBe(
|
||||
undefined,
|
||||
);
|
||||
await vi.waitFor(() => {
|
||||
expect(core.refreshFetchAttempts).toBe(1);
|
||||
});
|
||||
expect(await git(source.path, "branch --show-current")).toBe(featureBranch);
|
||||
});
|
||||
|
||||
it("refresh fetch is scoped to the checked out branch upstream refspec", async () => {
|
||||
await using remote = await makeTmpDir();
|
||||
await using source = await makeTmpDir();
|
||||
await git(remote.path, "init --bare");
|
||||
|
||||
await initRepoWithCommit(source.path);
|
||||
const defaultBranch = (await listGitBranches({ cwd: source.path })).branches.find(
|
||||
(branch) => branch.current,
|
||||
)!.name;
|
||||
await git(source.path, `remote add origin ${JSON.stringify(remote.path)}`);
|
||||
await git(source.path, `push -u origin ${defaultBranch}`);
|
||||
|
||||
const featureBranch = "feature/scoped-fetch";
|
||||
await git(source.path, `checkout -b ${featureBranch}`);
|
||||
await writeFile(path.join(source.path, "feature.txt"), "feature base\n");
|
||||
await git(source.path, "add feature.txt");
|
||||
await git(source.path, "commit -m 'feature base'");
|
||||
await git(source.path, `push -u origin ${featureBranch}`);
|
||||
await git(source.path, `checkout ${defaultBranch}`);
|
||||
|
||||
class FetchRecordingGitCoreService extends GitCoreService {
|
||||
fetchArgs: readonly string[] | null = null;
|
||||
|
||||
override async git(
|
||||
cwd: string,
|
||||
args: readonly string[],
|
||||
allowNonZeroExit = false,
|
||||
): Promise<void> {
|
||||
if (args[0] === "fetch") {
|
||||
this.fetchArgs = args;
|
||||
return;
|
||||
}
|
||||
await super.git(cwd, args, allowNonZeroExit);
|
||||
}
|
||||
}
|
||||
|
||||
const core = new FetchRecordingGitCoreService();
|
||||
await core.checkoutBranch({ cwd: source.path, branch: featureBranch });
|
||||
await vi.waitFor(() => {
|
||||
expect(core.fetchArgs).not.toBeNull();
|
||||
});
|
||||
|
||||
expect(await git(source.path, "branch --show-current")).toBe(featureBranch);
|
||||
expect(core.fetchArgs).toEqual([
|
||||
"fetch",
|
||||
"--quiet",
|
||||
"--no-tags",
|
||||
"origin",
|
||||
`+refs/heads/${featureBranch}:refs/remotes/origin/${featureBranch}`,
|
||||
]);
|
||||
});
|
||||
|
||||
it("returns checkout result before background upstream refresh completes", async () => {
|
||||
await using remote = await makeTmpDir();
|
||||
await using source = await makeTmpDir();
|
||||
await git(remote.path, "init --bare");
|
||||
|
||||
await initRepoWithCommit(source.path);
|
||||
const defaultBranch = (await listGitBranches({ cwd: source.path })).branches.find(
|
||||
(branch) => branch.current,
|
||||
)!.name;
|
||||
await git(source.path, `remote add origin ${JSON.stringify(remote.path)}`);
|
||||
await git(source.path, `push -u origin ${defaultBranch}`);
|
||||
|
||||
const featureBranch = "feature/background-refresh";
|
||||
await git(source.path, `checkout -b ${featureBranch}`);
|
||||
await writeFile(path.join(source.path, "feature.txt"), "feature base\n");
|
||||
await git(source.path, "add feature.txt");
|
||||
await git(source.path, "commit -m 'feature base'");
|
||||
await git(source.path, `push -u origin ${featureBranch}`);
|
||||
await git(source.path, `checkout ${defaultBranch}`);
|
||||
|
||||
class SlowRefreshGitCoreService extends GitCoreService {
|
||||
fetchStarted = false;
|
||||
private readonly waitForReleasePromise: Promise<void>;
|
||||
private releaseWait: () => void = () => undefined;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.waitForReleasePromise = new Promise<void>((resolve) => {
|
||||
this.releaseWait = resolve;
|
||||
});
|
||||
}
|
||||
|
||||
releaseFetch(): void {
|
||||
this.releaseWait();
|
||||
}
|
||||
|
||||
override async git(
|
||||
cwd: string,
|
||||
args: readonly string[],
|
||||
allowNonZeroExit = false,
|
||||
): Promise<void> {
|
||||
if (args[0] === "fetch") {
|
||||
this.fetchStarted = true;
|
||||
await this.waitForReleasePromise;
|
||||
return;
|
||||
}
|
||||
await super.git(cwd, args, allowNonZeroExit);
|
||||
}
|
||||
}
|
||||
|
||||
const core = new SlowRefreshGitCoreService();
|
||||
await expect(core.checkoutBranch({ cwd: source.path, branch: featureBranch })).resolves.toBe(
|
||||
undefined,
|
||||
);
|
||||
await vi.waitFor(() => {
|
||||
expect(core.fetchStarted).toBe(true);
|
||||
});
|
||||
expect(await git(source.path, "branch --show-current")).toBe(featureBranch);
|
||||
core.releaseFetch();
|
||||
});
|
||||
|
||||
it("throws when branch does not exist", async () => {
|
||||
await using tmp = await makeTmpDir();
|
||||
await initRepoWithCommit(tmp.path);
|
||||
|
||||
@@ -553,42 +553,11 @@ export class GitCoreService {
|
||||
});
|
||||
}
|
||||
|
||||
private async refreshCheckedOutBranchUpstream(cwd: string): Promise<void> {
|
||||
const upstreamRef = trimStdout(
|
||||
await this.gitStdout(
|
||||
cwd,
|
||||
["rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{upstream}"],
|
||||
true,
|
||||
),
|
||||
);
|
||||
if (upstreamRef.length === 0 || upstreamRef === "@{upstream}") {
|
||||
return;
|
||||
}
|
||||
|
||||
const separatorIndex = upstreamRef.indexOf("/");
|
||||
if (separatorIndex <= 0) {
|
||||
return;
|
||||
}
|
||||
const remoteName = upstreamRef.slice(0, separatorIndex);
|
||||
const upstreamBranch = upstreamRef.slice(separatorIndex + 1);
|
||||
if (remoteName.length === 0) {
|
||||
return;
|
||||
}
|
||||
if (upstreamBranch.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const refspec = `+refs/heads/${upstreamBranch}:refs/remotes/${upstreamRef}`;
|
||||
await this.git(cwd, ["fetch", "--quiet", "--no-tags", remoteName, refspec], true);
|
||||
}
|
||||
|
||||
async checkoutBranch(input: GitCheckoutInput): Promise<void> {
|
||||
await executeGit(input.cwd, ["checkout", input.branch], {
|
||||
timeoutMs: 10_000,
|
||||
fallbackErrorMessage: "git checkout failed",
|
||||
});
|
||||
// Refresh upstream refs in the background so checkout remains responsive.
|
||||
void this.refreshCheckedOutBranchUpstream(input.cwd).catch(() => undefined);
|
||||
}
|
||||
|
||||
async initRepo(input: GitInitInput): Promise<void> {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { QueryClient, QueryClientProvider, useQueryClient } from "@tanstack/react-query";
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { useEffect, useRef } from "react";
|
||||
|
||||
import ChatView from "./components/ChatView";
|
||||
@@ -11,27 +11,22 @@ import { DEFAULT_THREAD_TERMINAL_HEIGHT, DEFAULT_THREAD_TERMINAL_ID } from "./ty
|
||||
import { onServerWelcome } from "./wsNativeApi";
|
||||
import { useNativeApi } from "./hooks/useNativeApi";
|
||||
import { AnchoredToastProvider, ToastProvider } from "./components/ui/toast";
|
||||
import { invalidateGitQueries } from "./lib/gitReactQuery";
|
||||
|
||||
function EventRouter() {
|
||||
const api = useNativeApi();
|
||||
const { dispatch } = useStore();
|
||||
const queryClient = useQueryClient();
|
||||
const activeAssistantItemRef = useRef<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!api) return;
|
||||
return api.providers.onEvent((event) => {
|
||||
if (event.method === "turn/completed") {
|
||||
void invalidateGitQueries(queryClient);
|
||||
}
|
||||
dispatch({
|
||||
type: "APPLY_EVENT",
|
||||
event,
|
||||
activeAssistantItemRef,
|
||||
});
|
||||
});
|
||||
}, [api, dispatch, queryClient]);
|
||||
}, [api, dispatch]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!api) return;
|
||||
|
||||
@@ -25,15 +25,9 @@ interface BranchToolbarProps {
|
||||
envMode: "local" | "worktree";
|
||||
onEnvModeChange: (mode: "local" | "worktree") => void;
|
||||
envLocked: boolean;
|
||||
onComposerFocusRequest?: () => void;
|
||||
}
|
||||
|
||||
export default function BranchToolbar({
|
||||
envMode,
|
||||
onEnvModeChange,
|
||||
envLocked,
|
||||
onComposerFocusRequest,
|
||||
}: BranchToolbarProps) {
|
||||
export default function BranchToolbar({ envMode, onEnvModeChange, envLocked }: BranchToolbarProps) {
|
||||
const { state, dispatch } = useStore();
|
||||
const api = useNativeApi();
|
||||
const queryClient = useQueryClient();
|
||||
@@ -129,7 +123,6 @@ export default function BranchToolbar({
|
||||
setThreadError(null);
|
||||
setThreadBranch(branch.name, null);
|
||||
setIsBranchMenuOpen(false);
|
||||
onComposerFocusRequest?.();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -142,7 +135,6 @@ export default function BranchToolbar({
|
||||
// Secondary worktree → point the thread at that worktree path.
|
||||
setThreadBranch(branch.name, isMainWorktree ? null : branch.worktreePath);
|
||||
setIsBranchMenuOpen(false);
|
||||
onComposerFocusRequest?.();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -151,7 +143,6 @@ export default function BranchToolbar({
|
||||
setThreadError(null);
|
||||
setThreadBranch(branch.name, activeWorktreePath);
|
||||
setIsBranchMenuOpen(false);
|
||||
onComposerFocusRequest?.();
|
||||
},
|
||||
});
|
||||
};
|
||||
@@ -165,7 +156,6 @@ export default function BranchToolbar({
|
||||
setThreadBranch(name, activeWorktreePath);
|
||||
setBranchQuery("");
|
||||
setIsBranchMenuOpen(false);
|
||||
onComposerFocusRequest?.();
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@@ -19,11 +19,8 @@ import {
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import {
|
||||
gitBranchesQueryOptions,
|
||||
gitCreateWorktreeMutationOptions,
|
||||
} from "~/lib/gitReactQuery";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { gitBranchesQueryOptions } from "~/lib/gitReactQuery";
|
||||
|
||||
import { EDITORS, type EditorId } from "@t3tools/contracts";
|
||||
import { isElectron } from "../env";
|
||||
@@ -128,8 +125,6 @@ function readFileAsDataUrl(file: File): Promise<string> {
|
||||
export default function ChatView() {
|
||||
const { state, dispatch } = useStore();
|
||||
const api = useNativeApi();
|
||||
const queryClient = useQueryClient();
|
||||
const createWorktreeMutation = useMutation(gitCreateWorktreeMutationOptions({ api, queryClient }));
|
||||
const [prompt, setPrompt] = useState("");
|
||||
const [composerImages, setComposerImages] = useState<ComposerImageAttachment[]>([]);
|
||||
const [isDragOverComposer, setIsDragOverComposer] = useState(false);
|
||||
@@ -273,11 +268,6 @@ export default function ChatView() {
|
||||
const cursor = textarea.value.length;
|
||||
textarea.setSelectionRange(cursor, cursor);
|
||||
}, []);
|
||||
const scheduleComposerFocus = useCallback(() => {
|
||||
window.requestAnimationFrame(() => {
|
||||
focusComposer();
|
||||
});
|
||||
}, [focusComposer]);
|
||||
const toggleTerminalVisibility = useCallback(() => {
|
||||
if (!activeThreadId) return;
|
||||
dispatch({
|
||||
@@ -319,20 +309,14 @@ export default function ChatView() {
|
||||
const closeTerminal = useCallback(
|
||||
(terminalId: string) => {
|
||||
if (!activeThreadId || !api) return;
|
||||
const isFinalTerminal = (activeThread?.terminalIds.length ?? 0) <= 1;
|
||||
const fallbackExitWrite = () =>
|
||||
api.terminal
|
||||
.write({ threadId: activeThreadId, terminalId, data: "exit\n" })
|
||||
.catch(() => undefined);
|
||||
if ("close" in api.terminal && typeof api.terminal.close === "function") {
|
||||
void (async () => {
|
||||
if (isFinalTerminal) {
|
||||
await api.terminal
|
||||
.clear({ threadId: activeThreadId, terminalId })
|
||||
.catch(() => undefined);
|
||||
}
|
||||
await api.terminal.close({ threadId: activeThreadId, terminalId, deleteHistory: true });
|
||||
})().catch(() => fallbackExitWrite());
|
||||
void api.terminal
|
||||
.close({ threadId: activeThreadId, terminalId })
|
||||
.catch(() => fallbackExitWrite());
|
||||
} else {
|
||||
void fallbackExitWrite();
|
||||
}
|
||||
@@ -343,13 +327,12 @@ export default function ChatView() {
|
||||
});
|
||||
setTerminalFocusRequestId((value) => value + 1);
|
||||
},
|
||||
[activeThread?.terminalIds.length, activeThreadId, api, dispatch],
|
||||
[activeThreadId, api, dispatch],
|
||||
);
|
||||
|
||||
const handleRuntimeModeChange = async (mode: "approval-required" | "full-access") => {
|
||||
if (mode === state.runtimeMode) return;
|
||||
dispatch({ type: "SET_RUNTIME_MODE", mode });
|
||||
scheduleComposerFocus();
|
||||
if (!api) return;
|
||||
|
||||
const sessionIds = state.threads
|
||||
@@ -680,7 +663,7 @@ export default function ChatView() {
|
||||
) {
|
||||
try {
|
||||
const newBranch = `codething/${crypto.randomUUID().slice(0, 8)}`;
|
||||
const result = await createWorktreeMutation.mutateAsync({
|
||||
const result = await api.git.createWorktree({
|
||||
cwd: activeProject.cwd,
|
||||
branch: activeThread.branch,
|
||||
newBranch,
|
||||
@@ -812,32 +795,14 @@ export default function ChatView() {
|
||||
}
|
||||
};
|
||||
|
||||
const onModelSelect = useCallback(
|
||||
(model: ModelSlug) => {
|
||||
if (!activeThread) return;
|
||||
dispatch({
|
||||
type: "SET_THREAD_MODEL",
|
||||
threadId: activeThread.id,
|
||||
model: resolveModelSlug(model),
|
||||
});
|
||||
scheduleComposerFocus();
|
||||
},
|
||||
[activeThread, dispatch, scheduleComposerFocus],
|
||||
);
|
||||
const onEffortSelect = useCallback(
|
||||
(effort: ReasoningEffort) => {
|
||||
setSelectedEffort(effort);
|
||||
scheduleComposerFocus();
|
||||
},
|
||||
[scheduleComposerFocus],
|
||||
);
|
||||
const onEnvModeChange = useCallback(
|
||||
(mode: "local" | "worktree") => {
|
||||
setEnvMode(mode);
|
||||
scheduleComposerFocus();
|
||||
},
|
||||
[scheduleComposerFocus],
|
||||
);
|
||||
const onModelSelect = (model: ModelSlug) => {
|
||||
if (!activeThread) return;
|
||||
dispatch({
|
||||
type: "SET_THREAD_MODEL",
|
||||
threadId: activeThread.id,
|
||||
model: resolveModelSlug(model),
|
||||
});
|
||||
};
|
||||
|
||||
const onKeyDown = (e: KeyboardEvent<HTMLTextAreaElement>) => {
|
||||
if (e.key === "Enter" && !e.shiftKey) {
|
||||
@@ -1237,7 +1202,7 @@ export default function ChatView() {
|
||||
<Separator orientation="vertical" className="mx-0.5 h-4" />
|
||||
|
||||
{/* Reasoning effort */}
|
||||
<ReasoningEffortPicker effort={selectedEffort} onEffortChange={onEffortSelect} />
|
||||
<ReasoningEffortPicker effort={selectedEffort} onEffortChange={setSelectedEffort} />
|
||||
|
||||
{/* Divider */}
|
||||
<Separator orientation="vertical" className="mx-0.5 h-4" />
|
||||
@@ -1340,12 +1305,7 @@ export default function ChatView() {
|
||||
</div>
|
||||
|
||||
{isGitRepo && (
|
||||
<BranchToolbar
|
||||
envMode={envMode}
|
||||
onEnvModeChange={onEnvModeChange}
|
||||
envLocked={envLocked}
|
||||
onComposerFocusRequest={scheduleComposerFocus}
|
||||
/>
|
||||
<BranchToolbar envMode={envMode} onEnvModeChange={setEnvMode} envLocked={envLocked} />
|
||||
)}
|
||||
|
||||
{activeThread.terminalOpen && api && activeProject && (
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { GitStatusResult } from "@t3tools/contracts";
|
||||
import { assert, describe, it } from "vitest";
|
||||
import {
|
||||
buildGitActionProgressStages,
|
||||
buildMenuItems,
|
||||
requiresDefaultBranchConfirmation,
|
||||
resolveQuickAction,
|
||||
@@ -320,18 +319,6 @@ describe("when: branch is behind upstream", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("when: branch has diverged from upstream", () => {
|
||||
it("resolveQuickAction returns a disabled sync hint", () => {
|
||||
const quick = resolveQuickAction(status({ aheadCount: 2, behindCount: 1 }), false);
|
||||
assert.deepEqual(quick, {
|
||||
label: "Sync branch",
|
||||
disabled: true,
|
||||
kind: "show_hint",
|
||||
hint: "Branch has diverged from upstream. Rebase/merge first.",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("when: working tree has local changes", () => {
|
||||
it("resolveQuickAction returns commit, push, and create PR", () => {
|
||||
const quick = resolveQuickAction(status({ hasWorkingTreeChanges: true }), false);
|
||||
@@ -609,33 +596,6 @@ describe("requiresDefaultBranchConfirmation", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildGitActionProgressStages", () => {
|
||||
it("shows only push progress when push-only is forced", () => {
|
||||
const stages = buildGitActionProgressStages({
|
||||
action: "commit_push",
|
||||
hasCustomCommitMessage: false,
|
||||
hasWorkingTreeChanges: true,
|
||||
forcePushOnly: true,
|
||||
pushTarget: "origin/feature/test",
|
||||
});
|
||||
assert.deepEqual(stages, ["Pushing to origin/feature/test..."]);
|
||||
});
|
||||
|
||||
it("includes commit stages for commit+push when working tree is dirty", () => {
|
||||
const stages = buildGitActionProgressStages({
|
||||
action: "commit_push",
|
||||
hasCustomCommitMessage: false,
|
||||
hasWorkingTreeChanges: true,
|
||||
pushTarget: "origin/feature/test",
|
||||
});
|
||||
assert.deepEqual(stages, [
|
||||
"Generating commit message...",
|
||||
"Committing...",
|
||||
"Pushing to origin/feature/test...",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("summarizeGitResult", () => {
|
||||
it("returns commit-focused toast for commit action", () => {
|
||||
const result = summarizeGitResult({
|
||||
|
||||
@@ -43,30 +43,6 @@ function truncateText(
|
||||
return `${value.slice(0, Math.max(0, maxLength - 3)).trimEnd()}...`;
|
||||
}
|
||||
|
||||
export function buildGitActionProgressStages(input: {
|
||||
action: GitStackedAction;
|
||||
hasCustomCommitMessage: boolean;
|
||||
hasWorkingTreeChanges: boolean;
|
||||
forcePushOnly?: boolean;
|
||||
pushTarget?: string;
|
||||
}): string[] {
|
||||
const shouldIncludeCommitStages =
|
||||
!input.forcePushOnly && (input.action === "commit" || input.hasWorkingTreeChanges);
|
||||
const commitStages = !shouldIncludeCommitStages
|
||||
? []
|
||||
: input.hasCustomCommitMessage
|
||||
? ["Committing..."]
|
||||
: ["Generating commit message...", "Committing..."];
|
||||
const pushStage = input.pushTarget ? `Pushing to ${input.pushTarget}...` : "Pushing...";
|
||||
if (input.action === "commit") {
|
||||
return commitStages;
|
||||
}
|
||||
if (input.action === "commit_push") {
|
||||
return [...commitStages, pushStage];
|
||||
}
|
||||
return [...commitStages, pushStage, "Creating PR..."];
|
||||
}
|
||||
|
||||
export function summarizeGitResult(result: GitRunStackedActionResult): {
|
||||
title: string;
|
||||
description?: string;
|
||||
@@ -181,7 +157,6 @@ export function resolveQuickAction(
|
||||
const hasOpenPr = gitStatus.openPr !== null;
|
||||
const isAhead = gitStatus.aheadCount > 0;
|
||||
const isBehind = gitStatus.behindCount > 0;
|
||||
const isDiverged = isAhead && isBehind;
|
||||
|
||||
if (!hasBranch) {
|
||||
return {
|
||||
@@ -204,15 +179,6 @@ export function resolveQuickAction(
|
||||
};
|
||||
}
|
||||
|
||||
if (isDiverged) {
|
||||
return {
|
||||
label: "Sync branch",
|
||||
disabled: true,
|
||||
kind: "show_hint",
|
||||
hint: "Branch has diverged from upstream. Rebase/merge first.",
|
||||
};
|
||||
}
|
||||
|
||||
if (isBehind) {
|
||||
return {
|
||||
label: "Pull",
|
||||
@@ -241,7 +207,7 @@ export function resolveQuickAction(
|
||||
label: "Commit",
|
||||
disabled: true,
|
||||
kind: "show_hint",
|
||||
hint: "Branch is up to date. No action needed.",
|
||||
hint: "Branch is up to date. Nothing to commit, push, pull, or open as a PR.",
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { type GitStatusResult, type GitStackedAction, type NativeApi } from "@t3tools/contracts";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { useCallback, useMemo, useState } from "react";
|
||||
import { ChevronDownIcon, CloudUploadIcon, GitCommitIcon, InfoIcon } from "lucide-react";
|
||||
import { GitHubIcon } from "./Icons";
|
||||
import {
|
||||
buildGitActionProgressStages,
|
||||
buildMenuItems,
|
||||
type GitActionIconName,
|
||||
type GitActionMenuItem,
|
||||
@@ -38,7 +37,6 @@ import {
|
||||
gitStatusQueryOptions,
|
||||
invalidateGitQueries,
|
||||
} from "~/lib/gitReactQuery";
|
||||
import { useStore } from "~/store";
|
||||
import { preferredTerminalEditor, resolvePathLinkTarget } from "~/terminal-links";
|
||||
|
||||
interface GitActionsControlProps {
|
||||
@@ -136,13 +134,27 @@ function GitQuickActionIcon({ quickAction }: { quickAction: GitQuickAction }) {
|
||||
return <InfoIcon className={iconClassName} />;
|
||||
}
|
||||
|
||||
function buildGitActionProgressStages(input: {
|
||||
action: GitStackedAction;
|
||||
hasCustomCommitMessage: boolean;
|
||||
hasWorkingTreeChanges: boolean;
|
||||
}): string[] {
|
||||
const shouldIncludeCommitStages = input.action === "commit" || input.hasWorkingTreeChanges;
|
||||
const commitStages = !shouldIncludeCommitStages
|
||||
? []
|
||||
: input.hasCustomCommitMessage
|
||||
? ["Committing..."]
|
||||
: ["Generating commit message...", "Committing..."];
|
||||
if (input.action === "commit") {
|
||||
return commitStages;
|
||||
}
|
||||
if (input.action === "commit_push") {
|
||||
return [...commitStages, "Pushing..."];
|
||||
}
|
||||
return [...commitStages, "Pushing...", "Creating PR..."];
|
||||
}
|
||||
|
||||
export default function GitActionsControl({ api, gitCwd }: GitActionsControlProps) {
|
||||
const { state } = useStore();
|
||||
const activeThreadId = state.activeThreadId;
|
||||
const threadToastData = useMemo(
|
||||
() => (activeThreadId ? { threadId: activeThreadId } : undefined),
|
||||
[activeThreadId],
|
||||
);
|
||||
const queryClient = useQueryClient();
|
||||
const [activeDialogAction, setActiveDialogAction] = useState<GitDialogAction | null>(null);
|
||||
const [dialogCommitMessage, setDialogCommitMessage] = useState("");
|
||||
@@ -154,16 +166,6 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
const { data: branchList = null } = useQuery(gitBranchesQueryOptions(api, gitCwd));
|
||||
// Default to true while loading so we don't flash init controls.
|
||||
const isRepo = branchList?.isRepo ?? true;
|
||||
const currentBranch = branchList?.branches.find((branch) => branch.current)?.name ?? null;
|
||||
const isGitStatusOutOfSync =
|
||||
!!gitStatus?.branch && !!currentBranch && gitStatus.branch !== currentBranch;
|
||||
|
||||
useEffect(() => {
|
||||
if (!isGitStatusOutOfSync) return;
|
||||
void invalidateGitQueries(queryClient);
|
||||
}, [isGitStatusOutOfSync, queryClient]);
|
||||
|
||||
const gitStatusForActions = isGitStatusOutOfSync ? null : gitStatus;
|
||||
|
||||
const initMutation = useMutation(gitInitMutationOptions({ api, cwd: gitCwd, queryClient }));
|
||||
|
||||
@@ -174,19 +176,19 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
|
||||
const isGitActionRunning = runImmediateGitActionMutation.isPending || pullMutation.isPending;
|
||||
const isDefaultBranch = useMemo(() => {
|
||||
const branchName = gitStatusForActions?.branch;
|
||||
if (!branchName) return false;
|
||||
const current = branchList?.branches.find((branch) => branch.name === branchName);
|
||||
return current?.isDefault ?? (branchName === "main" || branchName === "master");
|
||||
}, [branchList?.branches, gitStatusForActions?.branch]);
|
||||
const currentBranch = gitStatus?.branch;
|
||||
if (!currentBranch) return false;
|
||||
const current = branchList?.branches.find((branch) => branch.name === currentBranch);
|
||||
return current?.isDefault ?? (currentBranch === "main" || currentBranch === "master");
|
||||
}, [branchList?.branches, gitStatus?.branch]);
|
||||
|
||||
const gitActionMenuItems = useMemo(
|
||||
() => buildMenuItems(gitStatusForActions, isGitActionRunning),
|
||||
[gitStatusForActions, isGitActionRunning],
|
||||
() => buildMenuItems(gitStatus, isGitActionRunning),
|
||||
[gitStatus, isGitActionRunning],
|
||||
);
|
||||
const quickAction = useMemo(
|
||||
() => resolveQuickAction(gitStatusForActions, isGitActionRunning, isDefaultBranch),
|
||||
[gitStatusForActions, isDefaultBranch, isGitActionRunning],
|
||||
() => resolveQuickAction(gitStatus, isGitActionRunning, isDefaultBranch),
|
||||
[gitStatus, isDefaultBranch, isGitActionRunning],
|
||||
);
|
||||
const quickActionDisabledReason = quickAction.disabled
|
||||
? (quickAction.hint ?? "This action is currently unavailable.")
|
||||
@@ -195,81 +197,52 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
const maybeConfirmPushToDefaultBranch = useCallback(
|
||||
async (action: GitStackedAction): Promise<boolean> => {
|
||||
if (!api) return false;
|
||||
if (
|
||||
!requiresDefaultBranchConfirmation(action, isDefaultBranch) ||
|
||||
!gitStatusForActions?.branch
|
||||
) {
|
||||
if (!requiresDefaultBranchConfirmation(action, isDefaultBranch) || !gitStatus?.branch) {
|
||||
return true;
|
||||
}
|
||||
return api.dialogs.confirm(
|
||||
`You're about to push to the default branch "${gitStatusForActions.branch}". Continue?`,
|
||||
`You're about to push to the default branch "${gitStatus.branch}". Continue?`,
|
||||
);
|
||||
},
|
||||
[api, gitStatusForActions?.branch, isDefaultBranch],
|
||||
[api, gitStatus?.branch, isDefaultBranch],
|
||||
);
|
||||
|
||||
const openExistingPr = useCallback(async () => {
|
||||
if (!api) {
|
||||
toastManager.add({
|
||||
type: "error",
|
||||
title: "Link opening is unavailable.",
|
||||
data: threadToastData,
|
||||
});
|
||||
toastManager.add({ type: "error", title: "Link opening is unavailable." });
|
||||
return;
|
||||
}
|
||||
const prUrl = gitStatusForActions?.openPr?.url ?? null;
|
||||
const prUrl = gitStatus?.openPr?.url ?? null;
|
||||
if (!prUrl) {
|
||||
toastManager.add({
|
||||
type: "error",
|
||||
title: "No open PR found.",
|
||||
data: threadToastData,
|
||||
});
|
||||
toastManager.add({ type: "error", title: "No open PR found." });
|
||||
return;
|
||||
}
|
||||
const promise = api.shell.openExternal(prUrl);
|
||||
toastManager.promise(promise, {
|
||||
loading: { title: "Opening PR...", data: threadToastData },
|
||||
success: { title: "PR opened", data: threadToastData },
|
||||
loading: { title: "Opening PR..." },
|
||||
success: { title: "PR opened" },
|
||||
error: (err) => ({
|
||||
title: "Unable to open PR link",
|
||||
description: err instanceof Error ? err.message : "An error occurred.",
|
||||
data: threadToastData,
|
||||
}),
|
||||
});
|
||||
void promise.catch(() => undefined);
|
||||
}, [api, gitStatusForActions?.openPr?.url, threadToastData]);
|
||||
}, [api, gitStatus?.openPr?.url]);
|
||||
|
||||
const runGitActionWithToast = useCallback(
|
||||
async ({
|
||||
action,
|
||||
commitMessage,
|
||||
forcePushOnlyProgress = false,
|
||||
onConfirmed,
|
||||
}: {
|
||||
action: GitStackedAction;
|
||||
commitMessage?: string;
|
||||
forcePushOnlyProgress?: boolean;
|
||||
onConfirmed?: () => void;
|
||||
}) => {
|
||||
async ({ action, commitMessage }: { action: GitStackedAction; commitMessage?: string }) => {
|
||||
const confirmed = await maybeConfirmPushToDefaultBranch(action);
|
||||
if (!confirmed) return;
|
||||
onConfirmed?.();
|
||||
|
||||
const pushTarget = gitStatusForActions?.branch
|
||||
? `origin/${gitStatusForActions.branch}`
|
||||
: undefined;
|
||||
const progressStages = buildGitActionProgressStages({
|
||||
action,
|
||||
hasCustomCommitMessage: !!commitMessage?.trim(),
|
||||
hasWorkingTreeChanges: !!gitStatusForActions?.hasWorkingTreeChanges,
|
||||
forcePushOnly: forcePushOnlyProgress,
|
||||
...(pushTarget ? { pushTarget } : {}),
|
||||
hasWorkingTreeChanges: !!gitStatus?.hasWorkingTreeChanges,
|
||||
});
|
||||
const progressToastId = toastManager.add({
|
||||
type: "loading",
|
||||
title: progressStages[0] ?? "Running git action...",
|
||||
timeout: 0,
|
||||
data: threadToastData,
|
||||
});
|
||||
|
||||
let stageIndex = 0;
|
||||
@@ -279,7 +252,6 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
title: progressStages[stageIndex] ?? "Running git action...",
|
||||
type: "loading",
|
||||
timeout: 0,
|
||||
data: threadToastData,
|
||||
});
|
||||
}, 1100);
|
||||
|
||||
@@ -297,12 +269,12 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
stopProgressUpdates();
|
||||
const resultToast = summarizeGitResult(result);
|
||||
|
||||
const prUrl = result.pr.url ?? gitStatusForActions?.openPr?.url;
|
||||
const prUrl = result.pr.url ?? gitStatus?.openPr?.url;
|
||||
const shouldOfferPushCta = action === "commit" && result.commit.status === "created";
|
||||
const shouldOfferOpenPrCta =
|
||||
(action === "commit_push" || action === "commit_push_pr") && !!prUrl && !isDefaultBranch;
|
||||
(action === "commit_push" || action === "commit_push_pr") && !!prUrl;
|
||||
const shouldOfferCreatePrCta =
|
||||
action === "commit_push" && !prUrl && result.push.status === "pushed" && !isDefaultBranch;
|
||||
action === "commit_push" && !prUrl && result.push.status === "pushed";
|
||||
const closeResultToast = () => {
|
||||
toastManager.close(progressToastId);
|
||||
};
|
||||
@@ -312,17 +284,13 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
title: resultToast.title,
|
||||
description: resultToast.description,
|
||||
timeout: 0,
|
||||
data: threadToastData,
|
||||
...(shouldOfferPushCta
|
||||
? {
|
||||
actionProps: {
|
||||
children: "Push",
|
||||
onClick: () => {
|
||||
void runGitActionWithToast({
|
||||
action: "commit_push",
|
||||
forcePushOnlyProgress: true,
|
||||
onConfirmed: closeResultToast,
|
||||
});
|
||||
closeResultToast();
|
||||
void runGitActionWithToast({ action: "commit_push" });
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -354,20 +322,16 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
type: "error",
|
||||
title: "Action failed",
|
||||
description: err instanceof Error ? err.message : "An error occurred.",
|
||||
data: threadToastData,
|
||||
});
|
||||
}
|
||||
},
|
||||
[
|
||||
api,
|
||||
gitStatusForActions?.branch,
|
||||
gitStatusForActions?.hasWorkingTreeChanges,
|
||||
gitStatusForActions?.openPr?.url,
|
||||
isDefaultBranch,
|
||||
gitStatus?.hasWorkingTreeChanges,
|
||||
gitStatus?.openPr?.url,
|
||||
maybeConfirmPushToDefaultBranch,
|
||||
runImmediateGitActionMutation,
|
||||
setActiveDialogAction,
|
||||
threadToastData,
|
||||
],
|
||||
);
|
||||
|
||||
@@ -379,19 +343,17 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
if (quickAction.kind === "run_pull") {
|
||||
const promise = pullMutation.mutateAsync();
|
||||
toastManager.promise(promise, {
|
||||
loading: { title: "Pulling...", data: threadToastData },
|
||||
loading: { title: "Pulling..." },
|
||||
success: (result) => ({
|
||||
title: result.status === "pulled" ? "Pulled" : "Already up to date",
|
||||
description:
|
||||
result.status === "pulled"
|
||||
? `Updated ${result.branch} from ${result.upstreamBranch ?? "upstream"}`
|
||||
: `${result.branch} is already synchronized.`,
|
||||
data: threadToastData,
|
||||
}),
|
||||
error: (err) => ({
|
||||
title: "Pull failed",
|
||||
description: err instanceof Error ? err.message : "An error occurred.",
|
||||
data: threadToastData,
|
||||
}),
|
||||
});
|
||||
void promise.catch(() => undefined);
|
||||
@@ -402,14 +364,13 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
type: "info",
|
||||
title: quickAction.label,
|
||||
description: quickAction.hint,
|
||||
data: threadToastData,
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (quickAction.action) {
|
||||
void runGitActionWithToast({ action: quickAction.action });
|
||||
}
|
||||
}, [openExistingPr, pullMutation, quickAction, runGitActionWithToast, threadToastData]);
|
||||
}, [openExistingPr, pullMutation, quickAction, runGitActionWithToast]);
|
||||
|
||||
const openDialogForMenuItem = useCallback(
|
||||
(item: GitActionMenuItem) => {
|
||||
@@ -419,7 +380,7 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
return;
|
||||
}
|
||||
if (item.dialogAction === "push") {
|
||||
void runGitActionWithToast({ action: "commit_push", forcePushOnlyProgress: true });
|
||||
void runGitActionWithToast({ action: "commit_push" });
|
||||
return;
|
||||
}
|
||||
if (item.dialogAction) {
|
||||
@@ -438,12 +399,10 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
? "commit_push"
|
||||
: "commit_push_pr";
|
||||
const commitMessage = activeDialogAction === "commit" ? dialogCommitMessage.trim() : "";
|
||||
const forcePushOnlyProgress = activeDialogAction === "push";
|
||||
setActiveDialogAction(null);
|
||||
void runGitActionWithToast({
|
||||
action,
|
||||
...(commitMessage ? { commitMessage } : {}),
|
||||
...(forcePushOnlyProgress ? { forcePushOnlyProgress } : {}),
|
||||
});
|
||||
}, [activeDialogAction, dialogCommitMessage, runGitActionWithToast]);
|
||||
|
||||
@@ -453,7 +412,6 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
toastManager.add({
|
||||
type: "error",
|
||||
title: "Editor opening is unavailable.",
|
||||
data: threadToastData,
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -463,11 +421,10 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
type: "error",
|
||||
title: "Unable to open file",
|
||||
description: error instanceof Error ? error.message : "An error occurred.",
|
||||
data: threadToastData,
|
||||
});
|
||||
});
|
||||
},
|
||||
[api, gitCwd, threadToastData],
|
||||
[api, gitCwd],
|
||||
);
|
||||
|
||||
if (!gitCwd) return null;
|
||||
@@ -491,10 +448,10 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
openOnHover
|
||||
render={
|
||||
<Button
|
||||
aria-disabled="true"
|
||||
className="cursor-not-allowed rounded-e-none border-e-0 opacity-64 before:rounded-e-none"
|
||||
size="xs"
|
||||
variant="outline"
|
||||
size="xs"
|
||||
disabled={isGitActionRunning || quickAction.disabled}
|
||||
className="cursor-not-allowed disabled:cursor-not-allowed disabled:pointer-events-auto"
|
||||
/>
|
||||
}
|
||||
>
|
||||
@@ -528,11 +485,11 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
>
|
||||
<ChevronDownIcon aria-hidden="true" className="size-4" />
|
||||
</MenuTrigger>
|
||||
<MenuPopup align="end" className="w-full">
|
||||
<MenuPopup align="end" sideOffset={4}>
|
||||
{gitActionMenuItems.map((item) => {
|
||||
const disabledReason = getMenuActionDisabledReason(
|
||||
item,
|
||||
gitStatusForActions,
|
||||
gitStatus,
|
||||
isGitActionRunning,
|
||||
);
|
||||
if (item.disabled && disabledReason) {
|
||||
@@ -540,10 +497,9 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
<Popover key={`${item.id}-${item.label}`}>
|
||||
<PopoverTrigger
|
||||
openOnHover
|
||||
nativeButton={false}
|
||||
render={<span className="block w-max cursor-not-allowed" />}
|
||||
render={<span className="inline-flex w-full cursor-not-allowed" />}
|
||||
>
|
||||
<MenuItem className="w-full" disabled>
|
||||
<MenuItem disabled>
|
||||
<GitActionItemIcon icon={item.icon} />
|
||||
{item.label}
|
||||
</MenuItem>
|
||||
@@ -568,25 +524,19 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
</MenuItem>
|
||||
);
|
||||
})}
|
||||
{gitStatusForActions?.branch === null && (
|
||||
{gitStatus?.branch === null && (
|
||||
<p className="px-2 py-1.5 text-xs text-warning">
|
||||
Detached HEAD: create and checkout a branch to enable push and PR actions.
|
||||
</p>
|
||||
)}
|
||||
{gitStatusForActions &&
|
||||
gitStatusForActions.branch !== null &&
|
||||
!gitStatusForActions.hasWorkingTreeChanges &&
|
||||
gitStatusForActions.behindCount > 0 &&
|
||||
gitStatusForActions.aheadCount === 0 && (
|
||||
{gitStatus &&
|
||||
gitStatus.branch !== null &&
|
||||
!gitStatus.hasWorkingTreeChanges &&
|
||||
gitStatus.behindCount > 0 && (
|
||||
<p className="px-2 py-1.5 text-xs text-warning">
|
||||
Behind upstream. Pull/rebase first.
|
||||
</p>
|
||||
)}
|
||||
{isGitStatusOutOfSync && (
|
||||
<p className="px-2 py-1.5 text-xs text-muted-foreground">
|
||||
Refreshing git status...
|
||||
</p>
|
||||
)}
|
||||
{gitStatusError && (
|
||||
<p className="px-2 py-1.5 text-xs text-destructive">{gitStatusError.message}</p>
|
||||
)}
|
||||
@@ -615,42 +565,37 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
<div className="space-y-3 rounded-lg border border-input bg-muted/40 p-3 text-xs">
|
||||
<div className="grid grid-cols-[auto_1fr] items-center gap-x-2 gap-y-1">
|
||||
<span className="text-muted-foreground">Branch</span>
|
||||
<span className="font-medium">
|
||||
{gitStatusForActions?.branch ?? "(detached HEAD)"}
|
||||
</span>
|
||||
<span className="font-medium">{gitStatus?.branch ?? "(detached HEAD)"}</span>
|
||||
{activeDialogAction !== "commit" && (
|
||||
<>
|
||||
<span className="text-muted-foreground">Upstream</span>
|
||||
<span className="font-medium">
|
||||
{!gitStatusForActions || !gitStatusForActions.hasUpstream
|
||||
{!gitStatus || !gitStatus.hasUpstream
|
||||
? "No upstream configured"
|
||||
: gitStatusForActions.aheadCount === 0 &&
|
||||
gitStatusForActions.behindCount === 0
|
||||
: gitStatus.aheadCount === 0 && gitStatus.behindCount === 0
|
||||
? "Up to date"
|
||||
: gitStatusForActions.aheadCount > 0 && gitStatusForActions.behindCount > 0
|
||||
? `Diverged (+${gitStatusForActions.aheadCount} / -${gitStatusForActions.behindCount})`
|
||||
: gitStatusForActions.aheadCount > 0
|
||||
? `Ahead by ${gitStatusForActions.aheadCount}`
|
||||
: `Behind by ${gitStatusForActions.behindCount}`}
|
||||
: gitStatus.aheadCount > 0 && gitStatus.behindCount > 0
|
||||
? `Diverged (+${gitStatus.aheadCount} / -${gitStatus.behindCount})`
|
||||
: gitStatus.aheadCount > 0
|
||||
? `Ahead by ${gitStatus.aheadCount}`
|
||||
: `Behind by ${gitStatus.behindCount}`}
|
||||
</span>
|
||||
<span className="text-muted-foreground">Working tree</span>
|
||||
<span className="font-medium">
|
||||
{!gitStatusForActions || !gitStatusForActions.hasWorkingTreeChanges
|
||||
{!gitStatus || !gitStatus.hasWorkingTreeChanges
|
||||
? "Clean"
|
||||
: `${gitStatusForActions.workingTree.files.length} file(s)`}
|
||||
: `${gitStatus.workingTree.files.length} file(s)`}
|
||||
</span>
|
||||
<span className="text-muted-foreground">Diff</span>
|
||||
<span className="font-mono">
|
||||
{!gitStatusForActions || !gitStatusForActions.hasWorkingTreeChanges ? (
|
||||
{!gitStatus || !gitStatus.hasWorkingTreeChanges ? (
|
||||
"none"
|
||||
) : (
|
||||
<>
|
||||
<span className="text-success">
|
||||
+{gitStatusForActions.workingTree.insertions}
|
||||
</span>
|
||||
<span className="text-success">+{gitStatus.workingTree.insertions}</span>
|
||||
<span className="text-muted-foreground"> / </span>
|
||||
<span className="text-destructive">
|
||||
-{gitStatusForActions.workingTree.deletions}
|
||||
-{gitStatus.workingTree.deletions}
|
||||
</span>
|
||||
</>
|
||||
)}
|
||||
@@ -660,13 +605,13 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
<p className="text-muted-foreground">Files</p>
|
||||
{!gitStatusForActions || gitStatusForActions.workingTree.files.length === 0 ? (
|
||||
{!gitStatus || gitStatus.workingTree.files.length === 0 ? (
|
||||
<p className="font-medium">none</p>
|
||||
) : (
|
||||
<div className="space-y-2">
|
||||
<ScrollArea className="h-44 rounded-md border border-input bg-background">
|
||||
<div className="space-y-1 p-1">
|
||||
{gitStatusForActions.workingTree.files.map((file) => (
|
||||
{gitStatus.workingTree.files.map((file) => (
|
||||
<button
|
||||
type="button"
|
||||
key={file.path}
|
||||
@@ -684,13 +629,9 @@ export default function GitActionsControl({ api, gitCwd }: GitActionsControlProp
|
||||
</div>
|
||||
</ScrollArea>
|
||||
<div className="flex justify-end font-mono">
|
||||
<span className="text-success">
|
||||
+{gitStatusForActions.workingTree.insertions}
|
||||
</span>
|
||||
<span className="text-success">+{gitStatus.workingTree.insertions}</span>
|
||||
<span className="text-muted-foreground"> / </span>
|
||||
<span className="text-destructive">
|
||||
-{gitStatusForActions.workingTree.deletions}
|
||||
</span>
|
||||
<span className="text-destructive">-{gitStatus.workingTree.deletions}</span>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { MonitorIcon, MoonIcon, SunIcon, TerminalIcon } from "lucide-react";
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { isElectron } from "../env";
|
||||
import { useTheme } from "../hooks/useTheme";
|
||||
import { DEFAULT_MODEL } from "../model-logic";
|
||||
@@ -13,7 +12,6 @@ import {
|
||||
type Thread,
|
||||
} from "../types";
|
||||
import { useNativeApi } from "../hooks/useNativeApi";
|
||||
import { gitRemoveWorktreeMutationOptions } from "../lib/gitReactQuery";
|
||||
import { formatWorktreePathForDisplay, getOrphanedWorktreePathForThread } from "../worktreeCleanup";
|
||||
|
||||
const THEME_CYCLE = { system: "light", light: "dark", dark: "system" } as const;
|
||||
@@ -112,8 +110,6 @@ function terminalStatusIndicator(thread: Thread): TerminalStatusIndicator | null
|
||||
export default function Sidebar() {
|
||||
const { state, dispatch } = useStore();
|
||||
const api = useNativeApi();
|
||||
const queryClient = useQueryClient();
|
||||
const removeWorktreeMutation = useMutation(gitRemoveWorktreeMutationOptions({ api, queryClient }));
|
||||
const { theme, setTheme } = useTheme();
|
||||
const [addingProject, setAddingProject] = useState(false);
|
||||
const [newCwd, setNewCwd] = useState("");
|
||||
@@ -311,7 +307,7 @@ export default function Sidebar() {
|
||||
}
|
||||
|
||||
try {
|
||||
await removeWorktreeMutation.mutateAsync({
|
||||
await api.git.removeWorktree({
|
||||
cwd: threadProject.cwd,
|
||||
path: orphanedWorktreePath,
|
||||
});
|
||||
@@ -319,7 +315,7 @@ export default function Sidebar() {
|
||||
// Worktree deletion is best-effort and should not block thread deletion.
|
||||
}
|
||||
},
|
||||
[api, dispatch, removeWorktreeMutation, state.projects, state.threads],
|
||||
[api, dispatch, state.projects, state.threads],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -11,15 +11,9 @@ import {
|
||||
|
||||
import { cn } from "~/lib/utils";
|
||||
import { buttonVariants } from "~/components/ui/button";
|
||||
import { useStore } from "~/store";
|
||||
|
||||
type ThreadToastData = {
|
||||
threadId?: string | null;
|
||||
tooltipStyle?: boolean;
|
||||
};
|
||||
|
||||
const toastManager = Toast.createToastManager<ThreadToastData>();
|
||||
const anchoredToastManager = Toast.createToastManager<ThreadToastData>();
|
||||
const toastManager = Toast.createToastManager();
|
||||
const anchoredToastManager = Toast.createToastManager();
|
||||
|
||||
const TOAST_ICONS = {
|
||||
error: CircleAlertIcon,
|
||||
@@ -41,15 +35,6 @@ interface ToastProviderProps extends Toast.Provider.Props {
|
||||
position?: ToastPosition;
|
||||
}
|
||||
|
||||
function shouldRenderForActiveThread(
|
||||
data: ThreadToastData | undefined,
|
||||
activeThreadId: string | null,
|
||||
): boolean {
|
||||
const toastThreadId = data?.threadId;
|
||||
if (!toastThreadId) return true;
|
||||
return toastThreadId === activeThreadId;
|
||||
}
|
||||
|
||||
function ToastProvider({ children, position = "top-right", ...props }: ToastProviderProps) {
|
||||
return (
|
||||
<Toast.Provider toastManager={toastManager} {...props}>
|
||||
@@ -60,9 +45,7 @@ function ToastProvider({ children, position = "top-right", ...props }: ToastProv
|
||||
}
|
||||
|
||||
function Toasts({ position = "top-right" }: { position: ToastPosition }) {
|
||||
const { state } = useStore();
|
||||
const { toasts } = Toast.useToastManager<ThreadToastData>();
|
||||
const activeThreadId = state.activeThreadId;
|
||||
const { toasts } = Toast.useToastManager();
|
||||
const isTop = position.startsWith("top");
|
||||
|
||||
return (
|
||||
@@ -81,96 +64,91 @@ function Toasts({ position = "top-right" }: { position: ToastPosition }) {
|
||||
data-position={position}
|
||||
data-slot="toast-viewport"
|
||||
>
|
||||
{toasts
|
||||
.filter((toast) => shouldRenderForActiveThread(toast.data, activeThreadId))
|
||||
.map((toast) => {
|
||||
const Icon = toast.type ? TOAST_ICONS[toast.type as keyof typeof TOAST_ICONS] : null;
|
||||
{toasts.map((toast) => {
|
||||
const Icon = toast.type ? TOAST_ICONS[toast.type as keyof typeof TOAST_ICONS] : null;
|
||||
|
||||
return (
|
||||
<Toast.Root
|
||||
className={cn(
|
||||
"absolute z-[calc(9999-var(--toast-index))] h-(--toast-calc-height) w-full select-none rounded-lg border bg-popover not-dark:bg-clip-padding text-popover-foreground shadow-lg/5 [transition:transform_.5s_cubic-bezier(.22,1,.36,1),opacity_.5s,height_.15s] before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-lg)-1px)] before:shadow-[0_1px_--theme(--color-black/4%)] dark:before:shadow-[0_-1px_--theme(--color-white/6%)]",
|
||||
// Base positioning using data-position
|
||||
"data-[position*=right]:right-0 data-[position*=right]:left-auto",
|
||||
"data-[position*=left]:right-auto data-[position*=left]:left-0",
|
||||
"data-[position*=center]:right-0 data-[position*=center]:left-0",
|
||||
"data-[position*=top]:top-0 data-[position*=top]:bottom-auto data-[position*=top]:origin-top",
|
||||
"data-[position*=bottom]:top-auto data-[position*=bottom]:bottom-0 data-[position*=bottom]:origin-bottom",
|
||||
// Gap fill for hover
|
||||
"after:absolute after:left-0 after:h-[calc(var(--toast-gap)+1px)] after:w-full",
|
||||
"data-[position*=top]:after:top-full",
|
||||
"data-[position*=bottom]:after:bottom-full",
|
||||
// Define some variables
|
||||
"[--toast-calc-height:var(--toast-frontmost-height,var(--toast-height))] [--toast-gap:--spacing(3)] [--toast-peek:--spacing(3)] [--toast-scale:calc(max(0,1-(var(--toast-index)*.1)))] [--toast-shrink:calc(1-var(--toast-scale))]",
|
||||
// Define offset-y variable
|
||||
"data-[position*=top]:[--toast-calc-offset-y:calc(var(--toast-offset-y)+var(--toast-index)*var(--toast-gap)+var(--toast-swipe-movement-y))]",
|
||||
"data-[position*=bottom]:[--toast-calc-offset-y:calc(var(--toast-offset-y)*-1+var(--toast-index)*var(--toast-gap)*-1+var(--toast-swipe-movement-y))]",
|
||||
// Default state transform
|
||||
"data-[position*=top]:transform-[translateX(var(--toast-swipe-movement-x))_translateY(calc(var(--toast-swipe-movement-y)+(var(--toast-index)*var(--toast-peek))+(var(--toast-shrink)*var(--toast-calc-height))))_scale(var(--toast-scale))]",
|
||||
"data-[position*=bottom]:transform-[translateX(var(--toast-swipe-movement-x))_translateY(calc(var(--toast-swipe-movement-y)-(var(--toast-index)*var(--toast-peek))-(var(--toast-shrink)*var(--toast-calc-height))))_scale(var(--toast-scale))]",
|
||||
// Limited state
|
||||
"data-limited:opacity-0",
|
||||
// Expanded state
|
||||
"data-expanded:h-(--toast-height)",
|
||||
"data-position:data-expanded:transform-[translateX(var(--toast-swipe-movement-x))_translateY(var(--toast-calc-offset-y))]",
|
||||
// Starting and ending animations
|
||||
"data-[position*=top]:data-starting-style:transform-[translateY(calc(-100%-var(--toast-inset)))]",
|
||||
"data-[position*=bottom]:data-starting-style:transform-[translateY(calc(100%+var(--toast-inset)))]",
|
||||
"data-ending-style:opacity-0",
|
||||
// Ending animations (direction-aware)
|
||||
"data-ending-style:not-data-limited:not-data-swipe-direction:transform-[translateY(calc(100%+var(--toast-inset)))]",
|
||||
"data-ending-style:data-[swipe-direction=left]:transform-[translateX(calc(var(--toast-swipe-movement-x)-100%-var(--toast-inset)))_translateY(var(--toast-calc-offset-y))]",
|
||||
"data-ending-style:data-[swipe-direction=right]:transform-[translateX(calc(var(--toast-swipe-movement-x)+100%+var(--toast-inset)))_translateY(var(--toast-calc-offset-y))]",
|
||||
"data-ending-style:data-[swipe-direction=up]:transform-[translateY(calc(var(--toast-swipe-movement-y)-100%-var(--toast-inset)))]",
|
||||
"data-ending-style:data-[swipe-direction=down]:transform-[translateY(calc(var(--toast-swipe-movement-y)+100%+var(--toast-inset)))]",
|
||||
// Ending animations (expanded)
|
||||
"data-expanded:data-ending-style:data-[swipe-direction=left]:transform-[translateX(calc(var(--toast-swipe-movement-x)-100%-var(--toast-inset)))_translateY(var(--toast-calc-offset-y))]",
|
||||
"data-expanded:data-ending-style:data-[swipe-direction=right]:transform-[translateX(calc(var(--toast-swipe-movement-x)+100%+var(--toast-inset)))_translateY(var(--toast-calc-offset-y))]",
|
||||
"data-expanded:data-ending-style:data-[swipe-direction=up]:transform-[translateY(calc(var(--toast-swipe-movement-y)-100%-var(--toast-inset)))]",
|
||||
"data-expanded:data-ending-style:data-[swipe-direction=down]:transform-[translateY(calc(var(--toast-swipe-movement-y)+100%+var(--toast-inset)))]",
|
||||
)}
|
||||
data-position={position}
|
||||
key={toast.id}
|
||||
swipeDirection={
|
||||
position.includes("center")
|
||||
? [isTop ? "up" : "down"]
|
||||
: position.includes("left")
|
||||
? ["left", isTop ? "up" : "down"]
|
||||
: ["right", isTop ? "up" : "down"]
|
||||
}
|
||||
toast={toast}
|
||||
>
|
||||
<Toast.Content className="pointer-events-auto flex items-center justify-between gap-1.5 overflow-hidden px-3.5 py-3 text-sm transition-opacity duration-250 data-behind:not-data-expanded:pointer-events-none data-behind:opacity-0 data-expanded:opacity-100">
|
||||
<div className="flex gap-2">
|
||||
{Icon && (
|
||||
<div
|
||||
className="[&>svg]:h-lh [&>svg]:w-4 [&_svg]:pointer-events-none [&_svg]:shrink-0"
|
||||
data-slot="toast-icon"
|
||||
>
|
||||
<Icon className="in-data-[type=loading]:animate-spin in-data-[type=error]:text-destructive in-data-[type=info]:text-info in-data-[type=success]:text-success in-data-[type=warning]:text-warning in-data-[type=loading]:opacity-80" />
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex flex-col gap-0.5">
|
||||
<Toast.Title className="font-medium" data-slot="toast-title" />
|
||||
<Toast.Description
|
||||
className="text-muted-foreground"
|
||||
data-slot="toast-description"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{toast.actionProps && (
|
||||
<Toast.Action
|
||||
className={buttonVariants({ size: "xs" })}
|
||||
data-slot="toast-action"
|
||||
return (
|
||||
<Toast.Root
|
||||
className={cn(
|
||||
"absolute z-[calc(9999-var(--toast-index))] h-(--toast-calc-height) w-full select-none rounded-lg border bg-popover not-dark:bg-clip-padding text-popover-foreground shadow-lg/5 [transition:transform_.5s_cubic-bezier(.22,1,.36,1),opacity_.5s,height_.15s] before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-lg)-1px)] before:shadow-[0_1px_--theme(--color-black/4%)] dark:before:shadow-[0_-1px_--theme(--color-white/6%)]",
|
||||
// Base positioning using data-position
|
||||
"data-[position*=right]:right-0 data-[position*=right]:left-auto",
|
||||
"data-[position*=left]:right-auto data-[position*=left]:left-0",
|
||||
"data-[position*=center]:right-0 data-[position*=center]:left-0",
|
||||
"data-[position*=top]:top-0 data-[position*=top]:bottom-auto data-[position*=top]:origin-top",
|
||||
"data-[position*=bottom]:top-auto data-[position*=bottom]:bottom-0 data-[position*=bottom]:origin-bottom",
|
||||
// Gap fill for hover
|
||||
"after:absolute after:left-0 after:h-[calc(var(--toast-gap)+1px)] after:w-full",
|
||||
"data-[position*=top]:after:top-full",
|
||||
"data-[position*=bottom]:after:bottom-full",
|
||||
// Define some variables
|
||||
"[--toast-calc-height:var(--toast-frontmost-height,var(--toast-height))] [--toast-gap:--spacing(3)] [--toast-peek:--spacing(3)] [--toast-scale:calc(max(0,1-(var(--toast-index)*.1)))] [--toast-shrink:calc(1-var(--toast-scale))]",
|
||||
// Define offset-y variable
|
||||
"data-[position*=top]:[--toast-calc-offset-y:calc(var(--toast-offset-y)+var(--toast-index)*var(--toast-gap)+var(--toast-swipe-movement-y))]",
|
||||
"data-[position*=bottom]:[--toast-calc-offset-y:calc(var(--toast-offset-y)*-1+var(--toast-index)*var(--toast-gap)*-1+var(--toast-swipe-movement-y))]",
|
||||
// Default state transform
|
||||
"data-[position*=top]:transform-[translateX(var(--toast-swipe-movement-x))_translateY(calc(var(--toast-swipe-movement-y)+(var(--toast-index)*var(--toast-peek))+(var(--toast-shrink)*var(--toast-calc-height))))_scale(var(--toast-scale))]",
|
||||
"data-[position*=bottom]:transform-[translateX(var(--toast-swipe-movement-x))_translateY(calc(var(--toast-swipe-movement-y)-(var(--toast-index)*var(--toast-peek))-(var(--toast-shrink)*var(--toast-calc-height))))_scale(var(--toast-scale))]",
|
||||
// Limited state
|
||||
"data-limited:opacity-0",
|
||||
// Expanded state
|
||||
"data-expanded:h-(--toast-height)",
|
||||
"data-position:data-expanded:transform-[translateX(var(--toast-swipe-movement-x))_translateY(var(--toast-calc-offset-y))]",
|
||||
// Starting and ending animations
|
||||
"data-[position*=top]:data-starting-style:transform-[translateY(calc(-100%-var(--toast-inset)))]",
|
||||
"data-[position*=bottom]:data-starting-style:transform-[translateY(calc(100%+var(--toast-inset)))]",
|
||||
"data-ending-style:opacity-0",
|
||||
// Ending animations (direction-aware)
|
||||
"data-ending-style:not-data-limited:not-data-swipe-direction:transform-[translateY(calc(100%+var(--toast-inset)))]",
|
||||
"data-ending-style:data-[swipe-direction=left]:transform-[translateX(calc(var(--toast-swipe-movement-x)-100%-var(--toast-inset)))_translateY(var(--toast-calc-offset-y))]",
|
||||
"data-ending-style:data-[swipe-direction=right]:transform-[translateX(calc(var(--toast-swipe-movement-x)+100%+var(--toast-inset)))_translateY(var(--toast-calc-offset-y))]",
|
||||
"data-ending-style:data-[swipe-direction=up]:transform-[translateY(calc(var(--toast-swipe-movement-y)-100%-var(--toast-inset)))]",
|
||||
"data-ending-style:data-[swipe-direction=down]:transform-[translateY(calc(var(--toast-swipe-movement-y)+100%+var(--toast-inset)))]",
|
||||
// Ending animations (expanded)
|
||||
"data-expanded:data-ending-style:data-[swipe-direction=left]:transform-[translateX(calc(var(--toast-swipe-movement-x)-100%-var(--toast-inset)))_translateY(var(--toast-calc-offset-y))]",
|
||||
"data-expanded:data-ending-style:data-[swipe-direction=right]:transform-[translateX(calc(var(--toast-swipe-movement-x)+100%+var(--toast-inset)))_translateY(var(--toast-calc-offset-y))]",
|
||||
"data-expanded:data-ending-style:data-[swipe-direction=up]:transform-[translateY(calc(var(--toast-swipe-movement-y)-100%-var(--toast-inset)))]",
|
||||
"data-expanded:data-ending-style:data-[swipe-direction=down]:transform-[translateY(calc(var(--toast-swipe-movement-y)+100%+var(--toast-inset)))]",
|
||||
)}
|
||||
data-position={position}
|
||||
key={toast.id}
|
||||
swipeDirection={
|
||||
position.includes("center")
|
||||
? [isTop ? "up" : "down"]
|
||||
: position.includes("left")
|
||||
? ["left", isTop ? "up" : "down"]
|
||||
: ["right", isTop ? "up" : "down"]
|
||||
}
|
||||
toast={toast}
|
||||
>
|
||||
<Toast.Content className="pointer-events-auto flex items-center justify-between gap-1.5 overflow-hidden px-3.5 py-3 text-sm transition-opacity duration-250 data-behind:not-data-expanded:pointer-events-none data-behind:opacity-0 data-expanded:opacity-100">
|
||||
<div className="flex gap-2">
|
||||
{Icon && (
|
||||
<div
|
||||
className="[&>svg]:h-lh [&>svg]:w-4 [&_svg]:pointer-events-none [&_svg]:shrink-0"
|
||||
data-slot="toast-icon"
|
||||
>
|
||||
{toast.actionProps.children}
|
||||
</Toast.Action>
|
||||
<Icon className="in-data-[type=loading]:animate-spin in-data-[type=error]:text-destructive in-data-[type=info]:text-info in-data-[type=success]:text-success in-data-[type=warning]:text-warning in-data-[type=loading]:opacity-80" />
|
||||
</div>
|
||||
)}
|
||||
</Toast.Content>
|
||||
</Toast.Root>
|
||||
);
|
||||
})}
|
||||
|
||||
<div className="flex flex-col gap-0.5">
|
||||
<Toast.Title className="font-medium" data-slot="toast-title" />
|
||||
<Toast.Description
|
||||
className="text-muted-foreground"
|
||||
data-slot="toast-description"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{toast.actionProps && (
|
||||
<Toast.Action className={buttonVariants({ size: "xs" })} data-slot="toast-action">
|
||||
{toast.actionProps.children}
|
||||
</Toast.Action>
|
||||
)}
|
||||
</Toast.Content>
|
||||
</Toast.Root>
|
||||
);
|
||||
})}
|
||||
</Toast.Viewport>
|
||||
</Toast.Portal>
|
||||
);
|
||||
@@ -186,80 +164,76 @@ function AnchoredToastProvider({ children, ...props }: Toast.Provider.Props) {
|
||||
}
|
||||
|
||||
function AnchoredToasts() {
|
||||
const { state } = useStore();
|
||||
const { toasts } = Toast.useToastManager<ThreadToastData>();
|
||||
const activeThreadId = state.activeThreadId;
|
||||
const { toasts } = Toast.useToastManager();
|
||||
|
||||
return (
|
||||
<Toast.Portal data-slot="toast-portal-anchored">
|
||||
<Toast.Viewport className="outline-none" data-slot="toast-viewport-anchored">
|
||||
{toasts
|
||||
.filter((toast) => shouldRenderForActiveThread(toast.data, activeThreadId))
|
||||
.map((toast) => {
|
||||
const Icon = toast.type ? TOAST_ICONS[toast.type as keyof typeof TOAST_ICONS] : null;
|
||||
const tooltipStyle = toast.data?.tooltipStyle ?? false;
|
||||
const positionerProps = toast.positionerProps;
|
||||
{toasts.map((toast) => {
|
||||
const Icon = toast.type ? TOAST_ICONS[toast.type as keyof typeof TOAST_ICONS] : null;
|
||||
const tooltipStyle = (toast.data as { tooltipStyle?: boolean })?.tooltipStyle ?? false;
|
||||
const positionerProps = toast.positionerProps;
|
||||
|
||||
if (!positionerProps?.anchor) {
|
||||
return null;
|
||||
}
|
||||
if (!positionerProps?.anchor) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<Toast.Positioner
|
||||
className="z-50 max-w-[min(--spacing(64),var(--available-width))]"
|
||||
data-slot="toast-positioner"
|
||||
key={toast.id}
|
||||
sideOffset={positionerProps.sideOffset ?? 4}
|
||||
return (
|
||||
<Toast.Positioner
|
||||
className="z-50 max-w-[min(--spacing(64),var(--available-width))]"
|
||||
data-slot="toast-positioner"
|
||||
key={toast.id}
|
||||
sideOffset={positionerProps.sideOffset ?? 4}
|
||||
toast={toast}
|
||||
>
|
||||
<Toast.Root
|
||||
className={cn(
|
||||
"relative text-balance border bg-popover not-dark:bg-clip-padding text-popover-foreground text-xs transition-[scale,opacity] before:pointer-events-none before:absolute before:inset-0 before:shadow-[0_1px_--theme(--color-black/4%)] data-ending-style:scale-98 data-starting-style:scale-98 data-ending-style:opacity-0 data-starting-style:opacity-0 dark:before:shadow-[0_-1px_--theme(--color-white/6%)]",
|
||||
tooltipStyle
|
||||
? "rounded-md shadow-md/5 before:rounded-[calc(var(--radius-md)-1px)]"
|
||||
: "rounded-lg shadow-lg/5 before:rounded-[calc(var(--radius-lg)-1px)]",
|
||||
)}
|
||||
data-slot="toast-popup"
|
||||
toast={toast}
|
||||
>
|
||||
<Toast.Root
|
||||
className={cn(
|
||||
"relative text-balance border bg-popover not-dark:bg-clip-padding text-popover-foreground text-xs transition-[scale,opacity] before:pointer-events-none before:absolute before:inset-0 before:shadow-[0_1px_--theme(--color-black/4%)] data-ending-style:scale-98 data-starting-style:scale-98 data-ending-style:opacity-0 data-starting-style:opacity-0 dark:before:shadow-[0_-1px_--theme(--color-white/6%)]",
|
||||
tooltipStyle
|
||||
? "rounded-md shadow-md/5 before:rounded-[calc(var(--radius-md)-1px)]"
|
||||
: "rounded-lg shadow-lg/5 before:rounded-[calc(var(--radius-lg)-1px)]",
|
||||
)}
|
||||
data-slot="toast-popup"
|
||||
toast={toast}
|
||||
>
|
||||
{tooltipStyle ? (
|
||||
<Toast.Content className="pointer-events-auto px-2 py-1">
|
||||
<Toast.Title data-slot="toast-title" />
|
||||
</Toast.Content>
|
||||
) : (
|
||||
<Toast.Content className="pointer-events-auto flex items-center justify-between gap-1.5 overflow-hidden px-3.5 py-3 text-sm">
|
||||
<div className="flex gap-2">
|
||||
{Icon && (
|
||||
<div
|
||||
className="[&>svg]:h-lh [&>svg]:w-4 [&_svg]:pointer-events-none [&_svg]:shrink-0"
|
||||
data-slot="toast-icon"
|
||||
>
|
||||
<Icon className="in-data-[type=loading]:animate-spin in-data-[type=error]:text-destructive in-data-[type=info]:text-info in-data-[type=success]:text-success in-data-[type=warning]:text-warning in-data-[type=loading]:opacity-80" />
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex flex-col gap-0.5">
|
||||
<Toast.Title className="font-medium" data-slot="toast-title" />
|
||||
<Toast.Description
|
||||
className="text-muted-foreground"
|
||||
data-slot="toast-description"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{toast.actionProps && (
|
||||
<Toast.Action
|
||||
className={buttonVariants({ size: "xs" })}
|
||||
data-slot="toast-action"
|
||||
{tooltipStyle ? (
|
||||
<Toast.Content className="pointer-events-auto px-2 py-1">
|
||||
<Toast.Title data-slot="toast-title" />
|
||||
</Toast.Content>
|
||||
) : (
|
||||
<Toast.Content className="pointer-events-auto flex items-center justify-between gap-1.5 overflow-hidden px-3.5 py-3 text-sm">
|
||||
<div className="flex gap-2">
|
||||
{Icon && (
|
||||
<div
|
||||
className="[&>svg]:h-lh [&>svg]:w-4 [&_svg]:pointer-events-none [&_svg]:shrink-0"
|
||||
data-slot="toast-icon"
|
||||
>
|
||||
{toast.actionProps.children}
|
||||
</Toast.Action>
|
||||
<Icon className="in-data-[type=loading]:animate-spin in-data-[type=error]:text-destructive in-data-[type=info]:text-info in-data-[type=success]:text-success in-data-[type=warning]:text-warning in-data-[type=loading]:opacity-80" />
|
||||
</div>
|
||||
)}
|
||||
</Toast.Content>
|
||||
)}
|
||||
</Toast.Root>
|
||||
</Toast.Positioner>
|
||||
);
|
||||
})}
|
||||
|
||||
<div className="flex flex-col gap-0.5">
|
||||
<Toast.Title className="font-medium" data-slot="toast-title" />
|
||||
<Toast.Description
|
||||
className="text-muted-foreground"
|
||||
data-slot="toast-description"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{toast.actionProps && (
|
||||
<Toast.Action
|
||||
className={buttonVariants({ size: "xs" })}
|
||||
data-slot="toast-action"
|
||||
>
|
||||
{toast.actionProps.children}
|
||||
</Toast.Action>
|
||||
)}
|
||||
</Toast.Content>
|
||||
)}
|
||||
</Toast.Root>
|
||||
</Toast.Positioner>
|
||||
);
|
||||
})}
|
||||
</Toast.Viewport>
|
||||
</Toast.Portal>
|
||||
);
|
||||
|
||||
@@ -108,7 +108,7 @@ export function gitRunStackedActionMutationOptions(input: {
|
||||
...(commitMessage ? { commitMessage } : {}),
|
||||
});
|
||||
},
|
||||
onSettled: async () => {
|
||||
onSuccess: async () => {
|
||||
await invalidateGitQueries(input.queryClient);
|
||||
},
|
||||
});
|
||||
@@ -124,49 +124,7 @@ export function gitPullMutationOptions(input: {
|
||||
if (!input.api || !input.cwd) throw new Error("Git pull is unavailable.");
|
||||
return input.api.git.pull({ cwd: input.cwd });
|
||||
},
|
||||
onSettled: async () => {
|
||||
await invalidateGitQueries(input.queryClient);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function gitCreateWorktreeMutationOptions(input: {
|
||||
api: NativeApi | undefined;
|
||||
queryClient: QueryClient;
|
||||
}) {
|
||||
return mutationOptions({
|
||||
mutationFn: async ({
|
||||
cwd,
|
||||
branch,
|
||||
newBranch,
|
||||
}: {
|
||||
cwd: string;
|
||||
branch: string;
|
||||
newBranch: string;
|
||||
}) => {
|
||||
if (!input.api) {
|
||||
throw new Error("Git worktree creation is unavailable.");
|
||||
}
|
||||
return input.api.git.createWorktree({ cwd, branch, newBranch });
|
||||
},
|
||||
onSettled: async () => {
|
||||
await invalidateGitQueries(input.queryClient);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function gitRemoveWorktreeMutationOptions(input: {
|
||||
api: NativeApi | undefined;
|
||||
queryClient: QueryClient;
|
||||
}) {
|
||||
return mutationOptions({
|
||||
mutationFn: async ({ cwd, path }: { cwd: string; path: string }) => {
|
||||
if (!input.api) {
|
||||
throw new Error("Git worktree removal is unavailable.");
|
||||
}
|
||||
return input.api.git.removeWorktree({ cwd, path });
|
||||
},
|
||||
onSettled: async () => {
|
||||
onSuccess: async () => {
|
||||
await invalidateGitQueries(input.queryClient);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -269,7 +269,6 @@ function closeThreadTerminal(thread: Thread, terminalId: string): Thread {
|
||||
|
||||
const remainingTerminalIds = thread.terminalIds.filter((id) => id !== terminalId);
|
||||
if (remainingTerminalIds.length === 0) {
|
||||
const nextTerminalGroupId = fallbackGroupId(DEFAULT_THREAD_TERMINAL_ID);
|
||||
return normalizeThreadTerminals({
|
||||
...thread,
|
||||
terminalOpen: false,
|
||||
@@ -278,11 +277,11 @@ function closeThreadTerminal(thread: Thread, terminalId: string): Thread {
|
||||
activeTerminalId: DEFAULT_THREAD_TERMINAL_ID,
|
||||
terminalGroups: [
|
||||
{
|
||||
id: nextTerminalGroupId,
|
||||
id: fallbackGroupId(DEFAULT_THREAD_TERMINAL_ID),
|
||||
terminalIds: [DEFAULT_THREAD_TERMINAL_ID],
|
||||
},
|
||||
],
|
||||
activeTerminalGroupId: nextTerminalGroupId,
|
||||
activeTerminalGroupId: fallbackGroupId(DEFAULT_THREAD_TERMINAL_ID),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user