feat(web): add Copy Thread ID to the sidebar and chat header thread context menu (#5574)
Co-authored-by: shivam <[email protected]>
This commit is contained in:
1 parent
752acbf654
commit
65b005f1e4
4 files changed
+37
-3
No files matched your search
@@ -29,7 +29,7 @@ import {
|
||||
scopeThreadRef,
|
||||
scopedThreadKey,
|
||||
} from "@t3tools/client-runtime/environment";
|
||||
import type { ScopedThreadRef } from "@t3tools/contracts";
|
||||
import type { ScopedThreadRef, ThreadId } from "@t3tools/contracts";
|
||||
import type { TimestampFormat } from "@t3tools/contracts/settings";
|
||||
import {
|
||||
AlarmClockIcon,
|
||||
@@ -1647,6 +1647,24 @@ export default function Sidebar() {
|
||||
);
|
||||
},
|
||||
});
|
||||
const { copyToClipboard: copyThreadIdToClipboard } = useCopyToClipboard<{ threadId: ThreadId }>({
|
||||
onCopy: ({ threadId }) => {
|
||||
toastManager.add({
|
||||
type: "success",
|
||||
title: "Thread ID copied",
|
||||
description: threadId,
|
||||
});
|
||||
},
|
||||
onError: (error) => {
|
||||
toastManager.add(
|
||||
stackedThreadToast({
|
||||
type: "error",
|
||||
title: "Failed to copy thread ID",
|
||||
description: error instanceof Error ? error.message : "An error occurred.",
|
||||
}),
|
||||
);
|
||||
},
|
||||
});
|
||||
const [projectScopeMenuOpen, setProjectScopeMenuOpen] = useState(false);
|
||||
const newThreadContext = useHandleNewThread();
|
||||
const openAddProjectCommandPalette = useCallback(
|
||||
@@ -3037,6 +3055,9 @@ export default function Sidebar() {
|
||||
copyBranchToClipboard(thread.branch, { branch: thread.branch });
|
||||
}
|
||||
return;
|
||||
case "copy-thread-id":
|
||||
copyThreadIdToClipboard(thread.id, { threadId: thread.id });
|
||||
return;
|
||||
case "delete": {
|
||||
if (confirmThreadDelete) {
|
||||
const confirmed = await settlePromise(() =>
|
||||
@@ -3079,6 +3100,7 @@ export default function Sidebar() {
|
||||
confirmThreadDelete,
|
||||
copyBranchToClipboard,
|
||||
copyPathToClipboard,
|
||||
copyThreadIdToClipboard,
|
||||
deleteThread,
|
||||
handleMultiSelectContextMenu,
|
||||
markThreadUnread,
|
||||
|
||||
@@ -26,7 +26,7 @@ describe("buildThreadActionMenuItems", () => {
|
||||
...baseState,
|
||||
supports: { settlement: false, snooze: false, pinning: false, titleRegeneration: false },
|
||||
}),
|
||||
).toEqual(["rename", "mark-unread", "copy-path", "delete"]);
|
||||
).toEqual(["rename", "mark-unread", "copy-path", "copy-thread-id", "delete"]);
|
||||
});
|
||||
|
||||
it("includes branch items only for threads with a branch", () => {
|
||||
|
||||
@@ -20,6 +20,7 @@ export type ThreadActionMenuId =
|
||||
| "mark-unread"
|
||||
| "copy-path"
|
||||
| "copy-branch"
|
||||
| "copy-thread-id"
|
||||
| "delete";
|
||||
|
||||
export interface ThreadActionMenuState {
|
||||
@@ -100,6 +101,7 @@ export function buildThreadActionMenuItems(
|
||||
{ id: "mark-unread", label: "Mark unread" },
|
||||
{ id: "copy-path", label: "Copy path", icon: "copy" },
|
||||
...(state.branch ? [{ id: "copy-branch" as const, label: "Copy branch", icon: "copy" }] : []),
|
||||
{ id: "copy-thread-id", label: "Copy thread ID", icon: "copy" },
|
||||
{ id: "delete", label: "Delete", destructive: true, icon: "trash" },
|
||||
];
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
effectiveSnoozed,
|
||||
type ChangeRequestStateLike,
|
||||
} from "@t3tools/client-runtime/state/thread-settled";
|
||||
import type { ScopedThreadRef } from "@t3tools/contracts";
|
||||
import type { ScopedThreadRef, ThreadId } from "@t3tools/contracts";
|
||||
import { useCallback } from "react";
|
||||
|
||||
import { resolveSnoozePresets, snoozeWakeDescription } from "../components/Sidebar.snooze";
|
||||
@@ -95,6 +95,12 @@ export function useThreadActionMenu(input: {
|
||||
},
|
||||
onError: (error) => failureToast("Failed to copy branch", error),
|
||||
});
|
||||
const { copyToClipboard: copyThreadIdToClipboard } = useCopyToClipboard<{ threadId: ThreadId }>({
|
||||
onCopy: ({ threadId }) => {
|
||||
toastManager.add({ type: "success", title: "Thread ID copied", description: threadId });
|
||||
},
|
||||
onError: (error) => failureToast("Failed to copy thread ID", error),
|
||||
});
|
||||
|
||||
const openMenu = useCallback(
|
||||
(position: { x: number; y: number }) => {
|
||||
@@ -242,6 +248,9 @@ export function useThreadActionMenu(input: {
|
||||
copyBranchToClipboard(thread.branch, { branch: thread.branch });
|
||||
}
|
||||
return;
|
||||
case "copy-thread-id":
|
||||
copyThreadIdToClipboard(thread.id, { threadId: thread.id });
|
||||
return;
|
||||
case "delete": {
|
||||
if (confirmThreadDelete) {
|
||||
const confirmed = await settlePromise(() =>
|
||||
@@ -279,6 +288,7 @@ export function useThreadActionMenu(input: {
|
||||
confirmThreadDelete,
|
||||
copyBranchToClipboard,
|
||||
copyPathToClipboard,
|
||||
copyThreadIdToClipboard,
|
||||
deleteThread,
|
||||
handleNewThread,
|
||||
markThreadUnread,
|
||||
|
||||
Reference in new issue
Block a user