Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

Add copy action to error toast messages (#1416)

Julius Marminge8888f6a0c9ad
diff --git a/apps/web/src/components/ui/toast.tsx b/apps/web/src/components/ui/toast.tsx
index 768a083e2..a55e36c19 100644
--- a/apps/web/src/components/ui/toast.tsx
+++ b/apps/web/src/components/ui/toast.tsx
@@ -5,8 +5,10 @@ import { useEffect, type CSSProperties } from "react";
import { useParams } from "@tanstack/react-router";
import { ThreadId } from "@t3tools/contracts";
import {
+ CheckIcon,
CircleAlertIcon,
CircleCheckIcon,
+ CopyIcon,
InfoIcon,
LoaderCircleIcon,
TriangleAlertIcon,
@@ -14,6 +16,7 @@ import {
import { cn } from "~/lib/utils";
import { buttonVariants } from "~/components/ui/button";
+import { useCopyToClipboard } from "~/hooks/useCopyToClipboard";
import { buildVisibleToastLayout, shouldHideCollapsedToastContent } from "./toast.logic";
type ThreadToastData = {
@@ -35,6 +38,25 @@ const TOAST_ICONS = {
warning: TriangleAlertIcon,
} as const;
+function CopyErrorButton({ text }: { text: string }) {
+ const { copyToClipboard, isCopied } = useCopyToClipboard();
+
+ return (
+ <button
+ className="shrink-0 cursor-pointer rounded-md p-1 text-muted-foreground opacity-60 transition-opacity hover:opacity-100"
+ onClick={() => copyToClipboard(text)}
+ title="Copy error"
+ type="button"
+ >
+ {isCopied ? (
+ <CheckIcon className="size-3.5 text-success" />
+ ) : (
+ <CopyIcon className="size-3.5" />
+ )}
+ </button>
+ );
+}
+
type ToastPosition =
| "top-left"
| "top-center"
@@ -284,12 +306,17 @@ function Toasts({ position = "top-right" }: { position: ToastPosition }) {
)}
<div className="flex min-w-0 flex-1 flex-col gap-0.5">
- <Toast.Title
- className="min-w-0 break-words font-medium"
- data-slot="toast-title"
- />
+ <div className="flex items-center justify-between gap-1">
+ <Toast.Title
+ className="min-w-0 break-words font-medium"
+ data-slot="toast-title"
+ />
+ {toast.type === "error" && typeof toast.description === "string" && (
+ <CopyErrorButton text={toast.description} />
+ )}
+ </div>
<Toast.Description
- className="min-w-0 break-words text-muted-foreground"
+ className="min-w-0 select-text break-words text-muted-foreground"
data-slot="toast-description"
/>
</div>
@@ -373,12 +400,17 @@ function AnchoredToasts() {
)}
<div className="flex min-w-0 flex-1 flex-col gap-0.5">
- <Toast.Title
- className="min-w-0 break-words font-medium"
- data-slot="toast-title"
- />
+ <div className="flex items-center gap-1">
+ <Toast.Title
+ className="min-w-0 break-words font-medium"
+ data-slot="toast-title"
+ />
+ {toast.type === "error" && typeof toast.description === "string" && (
+ <CopyErrorButton text={toast.description} />
+ )}
+ </div>
<Toast.Description
- className="min-w-0 break-words text-muted-foreground"
+ className="min-w-0 select-text break-words text-muted-foreground"
data-slot="toast-description"
/>
</div>