Open History to see the last commit
1import {
2 mapAtomCommandResult,
3 type AtomCommandResult,
4} from "@t3tools/client-runtime/state/runtime";
5import type { ScopedThreadRef } from "@t3tools/contracts";
6
7import type { BrowserSettingsReadError, OpenPreviewMutation } from "~/browser/openFileInPreview";
8import { useRightPanelStore } from "~/rightPanelStore";
9
10import { openPreviewSession } from "./openPreviewSession";
11
12export async function addBrowserSurface<E>(input: {
13 readonly threadRef: ScopedThreadRef;
14 readonly openPreview: OpenPreviewMutation<E>;
15 readonly profileId?: string | undefined;
16}): Promise<AtomCommandResult<void, E | BrowserSettingsReadError>> {
17 const result = await openPreviewSession({
18 openPreview: input.openPreview,
19 threadRef: input.threadRef,
20 ...(input.profileId === undefined ? {} : { profileId: input.profileId }),
21 });
22 return mapAtomCommandResult(result, (snapshot) => {
23 useRightPanelStore.getState().openBrowser(input.threadRef, snapshot.tabId);
24 });
25}