Skip to content

Commit acf3522

Browse files
committed
fix: Implement /share copy to clipboard (anomalyco#3372)
1 parent 641e777 commit acf3522

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

  • packages/opencode/src/cli/cmd/tui/routes/session

‎packages/opencode/src/cli/cmd/tui/routes/session/index.tsx‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import type { TaskTool } from "@/tool/task"
3636
import { useKeyboard, useTerminalDimensions, type BoxProps, type JSX } from "@opentui/solid"
3737
import { useSDK } from "@tui/context/sdk"
3838
import { useCommandDialog } from "@tui/component/dialog-command"
39-
import { Clipboard } from "@tui/util/clipboard"
4039
import { Shimmer } from "@tui/ui/shimmer"
4140
import { useKeybind } from "@tui/context/keybind"
4241
import { Header } from "./header"
@@ -49,8 +48,9 @@ import { DialogConfirm } from "@tui/ui/dialog-confirm"
4948
import { DialogTimeline } from "./dialog-timeline"
5049
import { Sidebar } from "./sidebar"
5150
import { LANGUAGE_EXTENSIONS } from "@/lsp/language"
52-
5351
import parsers from "../../../../../../parsers-config.json"
52+
import { Clipboard } from "../../util/clipboard"
53+
import { Toast, useToast } from "../../ui/toast"
5454

5555
addDefaultParsers(parsers.parsers)
5656

@@ -84,6 +84,8 @@ export function Session() {
8484

8585
createEffect(() => sync.session.sync(route.sessionID))
8686

87+
const toast = useToast()
88+
8789
const sdk = useSDK()
8890

8991
let scroll: ScrollBoxRenderable
@@ -175,13 +177,18 @@ export function Session() {
175177
disabled: !!session()?.share?.url,
176178
category: "Session",
177179
onSelect: async (dialog) => {
178-
const result = await sdk.client.session.share({
179-
path: {
180-
id: route.sessionID,
181-
},
182-
})
183-
if (result.data?.share?.url) {
184-
await Clipboard.copy(result.data.share.url)
180+
try {
181+
const response = await sdk.client.session.share({
182+
path: {
183+
id: route.sessionID,
184+
},
185+
})
186+
Clipboard.copy(response.data!.share!.url).catch(() =>
187+
toast.show({ message: "Failed to copy URL to clipboard", type: "error", duration: 3000 })
188+
)
189+
toast.show({ message: "Share URL copied to clipboard!", type: "success", duration: 3000 })
190+
} catch {
191+
toast.show({ message: "Failed to share session", type: "error", duration: 3000 })
185192
}
186193
dialog.clear()
187194
},

0 commit comments

Comments
 (0)