| 1 | import { |
| 2 | mapAtomCommandResult, |
| 3 | type AtomCommandResult, |
| 4 | } from "@t3tools/client-runtime/state/runtime"; |
| 5 | import type { ScopedThreadRef } from "@t3tools/contracts"; |
| 6 | |
| 7 | import type { BrowserSettingsReadError, OpenPreviewMutation } from "~/browser/openFileInPreview"; |
| 8 | import { useRightPanelStore } from "~/rightPanelStore"; |
| 9 | |
| 10 | import { openPreviewSession } from "./openPreviewSession"; |
| 11 | |
| 12 | /** Creates a new browser tab. Reopening an existing tab is a separate UI action. */ |
| 13 | export async function addBrowserSurface<E>(input: { |
| 14 | readonly threadRef: ScopedThreadRef; |
| 15 | readonly openPreview: OpenPreviewMutation<E>; |
| 16 | /** Omit to use the configured default profile. */ |
| 17 | readonly profileId?: string | undefined; |
| 18 | }): Promise<AtomCommandResult<void, E | BrowserSettingsReadError>> { |
| 19 | const result = await openPreviewSession({ |
| 20 | openPreview: input.openPreview, |
| 21 | threadRef: input.threadRef, |
| 22 | ...(input.profileId === undefined ? {} : { profileId: input.profileId }), |
| 23 | }); |
| 24 | return mapAtomCommandResult(result, (snapshot) => { |
| 25 | useRightPanelStore.getState().openBrowser(input.threadRef, snapshot.tabId); |
| 26 | }); |
| 27 | } |