Files
buzz/desktop/src/features/projects/ui/useOpenProjectTerminal.ts
Clay Delk f5f3102108 feat(desktop): polish system message and toast copy
Sweep the desktop toast surface for a consistent voice:
- error toasts use "Couldn't …" instead of "Failed to …" (git/PR
  service toasts keep "Failed" as more accurate for that surface)
- drop terminal periods on single-clause toasts; keep them only on
  multi-sentence messages
- name the member in relay promote/demote/remove confirmations
- archive toasts say "in this community" instead of "on this relay"
- clearer copy for repos-directory, DM agent-mention, storage-full,
  and stop-turn toasts
- "added by" (not "was added by") in membership rows, fixing the
  "You was added by" grammar bug
- template apply names the agents that failed; member timeout echoes
  the chosen duration

error.message/err.message branches are preserved throughout; only
fallback literals changed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-27 11:31:58 -04:00

54 lines
1.8 KiB
TypeScript

import { useQueryClient } from "@tanstack/react-query";
import * as React from "react";
import { toast } from "sonner";
import type { Project } from "@/features/projects/hooks";
import { openProjectTerminal } from "@/shared/api/projectGit";
export function projectTerminalLabel(hasLocalCheckout: boolean) {
return hasLocalCheckout ? "Open in Terminal" : "Clone & open in Terminal";
}
/**
* Opens the OS terminal at a project's local checkout, cloning first when
* only a remote exists. Handles the clone progress/success/error toasts and
* refreshes project queries after a clone so local-checkout state updates.
*/
export function useOpenProjectTerminal(reposDir?: string | null) {
const queryClient = useQueryClient();
return React.useCallback(
async (
project: Project,
options: { branch?: string | null; hasLocalCheckout: boolean },
) => {
const toastId = options.hasLocalCheckout
? undefined
: toast.loading(`Cloning ${project.name}…`);
try {
const result = await openProjectTerminal({
reposDir,
projectDtag: project.dtag,
cloneUrl: project.cloneUrls[0] ?? null,
defaultBranch: options.branch ?? project.defaultBranch ?? null,
});
if (result.cloned) {
toast.success(`Cloned to ${result.path}`, { id: toastId });
void queryClient.invalidateQueries({
queryKey: ["project", project.id],
});
void queryClient.invalidateQueries({ queryKey: ["projects"] });
} else if (toastId !== undefined) {
toast.dismiss(toastId);
}
} catch (error) {
toast.error(
error instanceof Error ? error.message : "Couldn't open the terminal",
{ id: toastId },
);
}
},
[queryClient, reposDir],
);
}