Skip to content

Commit 4fbe3f8

Browse files
authored
feat: FIT-155: Playground preview only mode (#7604)
1 parent 6982605 commit 4fbe3f8

File tree

3 files changed

+41
-22
lines changed

3 files changed

+41
-22
lines changed
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
import { atom } from "jotai";
2+
import { getQueryParams } from "../utils/query";
23

34
export const defaultConfig = "<View>\n <!-- Paste your XML config here -->\n</View>";
45

56
export const configAtom = atom<string>(defaultConfig);
67
export const loadingAtom = atom<boolean>(false);
78
export const errorAtom = atom<string | null>(null);
8-
export const interfacesAtom = atom<string[]>(["side-column"]);
9+
export const interfacesAtom = atom<string[]>([]);
910
export const showPreviewAtom = atom<boolean>(true);
1011
export const sampleTaskAtom = atom<any>({});
1112
export const annotationAtom = atom<any>([]);
13+
export const modeAtom = atom<"preview" | "editor" | "">("editor");
14+
export const displayModeAtom = atom<"preview" | "all">(() => {
15+
const params = getQueryParams();
16+
const mode = params.get("mode");
17+
if (mode === "preview") return "preview";
18+
return "all";
19+
});

web/apps/playground/src/components/PlaygroundApp/PlaygroundApp.tsx

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import { useEffect, useMemo, useRef, useState, useCallback } from "react";
22
import type { MouseEvent } from "react";
3-
import { useSetAtom } from "jotai";
3+
import { useAtomValue, useSetAtom } from "jotai";
44
import { ToastProvider, ToastViewport } from "@humansignal/ui/lib/toast/toast";
55
import { cnm } from "@humansignal/shad/utils";
66
import { PreviewPanel } from "../PreviewPanel";
7-
import { configAtom, loadingAtom, errorAtom, interfacesAtom } from "../../atoms/configAtoms";
7+
import { EditorPanel } from "../EditorPanel";
8+
import { TopBar } from "./TopBar";
9+
import { configAtom, loadingAtom, errorAtom, interfacesAtom, displayModeAtom } from "../../atoms/configAtoms";
810
import {
911
getQueryParams,
1012
replaceBrTagsWithNewlines,
1113
getInterfacesFromParams,
1214
throwUnlessXmlLike,
1315
} from "../../utils/query";
14-
import { TopBar } from "./TopBar";
15-
import { EditorPanel } from "../EditorPanel";
1616
import styles from "./PlaygroundApp.module.scss";
1717

1818
const DEFAULT_EDITOR_WIDTH_PERCENT = 50;
@@ -24,6 +24,7 @@ export const PlaygroundApp = () => {
2424
const setLoading = useSetAtom(loadingAtom);
2525
const setError = useSetAtom(errorAtom);
2626
const setInterfaces = useSetAtom(interfacesAtom);
27+
const displayMode = useAtomValue(displayModeAtom);
2728
const [editorWidth, setEditorWidth] = useState(DEFAULT_EDITOR_WIDTH_PERCENT);
2829
const dragging = useRef(false);
2930

@@ -118,26 +119,34 @@ export const PlaygroundApp = () => {
118119
>
119120
<ToastProvider>
120121
{/* Minimal top bar */}
121-
<TopBar />
122+
{displayMode !== "preview" && <TopBar />}
122123
{/* Editor/Preview split */}
123124
<div className="flex flex-1 min-h-0 min-w-0 relative">
124125
{/* Editor Panel */}
125-
<EditorPanel editorWidth={editorWidth} />
126+
{displayMode !== "preview" && <EditorPanel editorWidth={editorWidth} />}
126127
{/* Resizable Divider */}
127-
<div
128-
className="w-2 cursor-col-resize bg-neutral-emphasis hover:bg-primary-border active:bg-primary-border transition-colors duration-100 z-10"
129-
onMouseDown={(e: MouseEvent) => {
130-
if (e.button !== 0) return;
131-
e.preventDefault();
132-
dragging.current = true;
133-
}}
134-
onDoubleClick={handleDividerDoubleClick}
135-
role="separator"
136-
aria-orientation="vertical"
137-
tabIndex={-1}
138-
/>
128+
{displayMode !== "preview" && (
129+
<div
130+
className="w-2 cursor-col-resize bg-neutral-emphasis hover:bg-primary-border active:bg-primary-border transition-colors duration-100 z-10"
131+
onMouseDown={(e: MouseEvent) => {
132+
if (e.button !== 0) return;
133+
e.preventDefault();
134+
dragging.current = true;
135+
}}
136+
onDoubleClick={handleDividerDoubleClick}
137+
role="separator"
138+
aria-orientation="vertical"
139+
tabIndex={-1}
140+
/>
141+
)}
142+
139143
{/* Preview Panel */}
140-
<div className="flex flex-col min-w-0 h-full" style={previewPanelStyle}>
144+
<div
145+
className={cnm("flex flex-col min-w-0 h-full", {
146+
"flex-row flex-1 w-full": displayMode !== "all",
147+
})}
148+
style={previewPanelStyle}
149+
>
141150
<div className="flex-1 min-h-0 min-w-0">
142151
<PreviewPanel />
143152
</div>

web/apps/playground/src/components/PreviewPanel/PreviewPanel.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
interfacesAtom,
1111
annotationAtom,
1212
sampleTaskAtom,
13+
displayModeAtom,
1314
} from "../../atoms/configAtoms";
1415
import { onSnapshot } from "mobx-state-tree";
1516

@@ -29,6 +30,7 @@ export const PreviewPanel: FC<PreviewPanelProps> = memo(
2930
const interfaces = useAtomValue(interfacesAtom);
3031
const setAnnotation = useSetAtom(annotationAtom);
3132
const setSampleTask = useSetAtom(sampleTaskAtom);
33+
const displayMode = useAtomValue(displayModeAtom);
3234
const [showPreview, setShowPreview] = useAtom(showPreviewAtom);
3335
const rootRef = useRef<HTMLDivElement>(null);
3436
const lsfInstance = useRef<any>(null);
@@ -82,7 +84,7 @@ export const PreviewPanel: FC<PreviewPanelProps> = memo(
8284
settings: {
8385
forceBottomPanel: true,
8486
collapsibleBottomPanel: true,
85-
defaultCollapsedBottomPanel: true,
87+
defaultCollapsedBottomPanel: displayMode === "all",
8688
fullscreen: false,
8789
},
8890
onStorageInitialized: (LS: any) => {
@@ -93,7 +95,7 @@ export const PreviewPanel: FC<PreviewPanelProps> = memo(
9395

9496
const annotation = as.selected;
9597
if (annotation) {
96-
snapshotDisposer = onSnapshot(annotation, (snapshot) => {
98+
snapshotDisposer = onSnapshot(annotation, () => {
9799
setAnnotation(annotation.serializeAnnotation());
98100
});
99101
}

0 commit comments

Comments
 (0)