Yuchen Yuan commited on
Commit
4637580
·
1 Parent(s): 27dc77b

Make left/right side panels resizable and bump default widths

Browse files

- Pipeline input (left aside) was fixed at 280px and couldn't be widened,
which made the new sample-diagram preview feel cramped. Bump the
default to 320px and add a drag handle (220px..560px range).
- Mirror the same affordance on the right Results pane (was 400px fixed;
now 300px..720px, default 400px).
- Widths persist to localStorage so the user's choice sticks across
reloads.
- Double-click a handle to snap back to the default width.

Files changed (1) hide show
  1. frontend/src/App.tsx +130 -3
frontend/src/App.tsx CHANGED
@@ -1,4 +1,4 @@
1
- import { useEffect, useState } from "react";
2
  import { ReactFlowProvider } from "@xyflow/react";
3
  import "@xyflow/react/dist/style.css";
4
  import { api } from "./lib/api";
@@ -10,11 +10,57 @@ import { ResultsPane } from "./components/ResultsPane";
10
  import { CircuitPicker } from "./components/CircuitPicker";
11
  import { WelcomeTour, useFirstVisitTour } from "./components/WelcomeTour";
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  export default function App() {
14
  const setHealth = useApp((s) => s.setHealth);
15
  const [ready, setReady] = useState(false);
16
  const [tourOpen, setTourOpen] = useFirstVisitTour();
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  useEffect(() => {
19
  api
20
  .health()
@@ -29,16 +75,36 @@ export default function App() {
29
  <div className="h-screen w-screen flex flex-col overflow-hidden">
30
  <TopBar onOpenTour={() => setTourOpen(true)} />
31
  <div className="flex-1 flex min-h-0">
32
- <aside className="w-[280px] shrink-0 border-r border-edge flex flex-col min-h-0 overflow-y-auto">
 
 
 
33
  <CircuitPicker />
34
  </aside>
 
 
 
 
 
 
 
35
  <main className="flex-1 min-w-0 flex flex-col min-h-0">
36
  <NodePalette />
37
  <ReactFlowProvider>
38
  <FlowCanvas />
39
  </ReactFlowProvider>
40
  </main>
41
- <aside className="w-[400px] shrink-0 border-l border-edge flex flex-col min-h-0">
 
 
 
 
 
 
 
 
 
 
42
  <ResultsPane />
43
  </aside>
44
  </div>
@@ -51,3 +117,64 @@ export default function App() {
51
  </div>
52
  );
53
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { useCallback, useEffect, useRef, useState } from "react";
2
  import { ReactFlowProvider } from "@xyflow/react";
3
  import "@xyflow/react/dist/style.css";
4
  import { api } from "./lib/api";
 
10
  import { CircuitPicker } from "./components/CircuitPicker";
11
  import { WelcomeTour, useFirstVisitTour } from "./components/WelcomeTour";
12
 
13
+ // Default + clamp bounds for the two side panels. The middle canvas flexes.
14
+ const LEFT_DEFAULT = 320;
15
+ const LEFT_MIN = 220;
16
+ const LEFT_MAX = 560;
17
+ const RIGHT_DEFAULT = 400;
18
+ const RIGHT_MIN = 300;
19
+ const RIGHT_MAX = 720;
20
+ const LS_LEFT = "jqub.leftPaneWidth";
21
+ const LS_RIGHT = "jqub.rightPaneWidth";
22
+
23
+ function loadWidth(key: string, def: number, min: number, max: number): number {
24
+ if (typeof window === "undefined") return def;
25
+ try {
26
+ const raw = window.localStorage.getItem(key);
27
+ if (!raw) return def;
28
+ const n = Number(raw);
29
+ if (!Number.isFinite(n)) return def;
30
+ return Math.min(max, Math.max(min, n));
31
+ } catch {
32
+ return def;
33
+ }
34
+ }
35
+
36
  export default function App() {
37
  const setHealth = useApp((s) => s.setHealth);
38
  const [ready, setReady] = useState(false);
39
  const [tourOpen, setTourOpen] = useFirstVisitTour();
40
 
41
+ const [leftW, setLeftW] = useState<number>(() =>
42
+ loadWidth(LS_LEFT, LEFT_DEFAULT, LEFT_MIN, LEFT_MAX),
43
+ );
44
+ const [rightW, setRightW] = useState<number>(() =>
45
+ loadWidth(LS_RIGHT, RIGHT_DEFAULT, RIGHT_MIN, RIGHT_MAX),
46
+ );
47
+
48
+ // Persist user's preferred widths.
49
+ useEffect(() => {
50
+ try {
51
+ window.localStorage.setItem(LS_LEFT, String(leftW));
52
+ } catch {
53
+ /* ignore quota errors */
54
+ }
55
+ }, [leftW]);
56
+ useEffect(() => {
57
+ try {
58
+ window.localStorage.setItem(LS_RIGHT, String(rightW));
59
+ } catch {
60
+ /* ignore quota errors */
61
+ }
62
+ }, [rightW]);
63
+
64
  useEffect(() => {
65
  api
66
  .health()
 
75
  <div className="h-screen w-screen flex flex-col overflow-hidden">
76
  <TopBar onOpenTour={() => setTourOpen(true)} />
77
  <div className="flex-1 flex min-h-0">
78
+ <aside
79
+ style={{ width: leftW }}
80
+ className="shrink-0 border-r border-edge flex flex-col min-h-0 overflow-y-auto"
81
+ >
82
  <CircuitPicker />
83
  </aside>
84
+ <PaneResizer
85
+ onResize={(dx) =>
86
+ setLeftW((w) => Math.min(LEFT_MAX, Math.max(LEFT_MIN, w + dx)))
87
+ }
88
+ onDoubleClick={() => setLeftW(LEFT_DEFAULT)}
89
+ ariaLabel="Resize pipeline input pane"
90
+ />
91
  <main className="flex-1 min-w-0 flex flex-col min-h-0">
92
  <NodePalette />
93
  <ReactFlowProvider>
94
  <FlowCanvas />
95
  </ReactFlowProvider>
96
  </main>
97
+ <PaneResizer
98
+ onResize={(dx) =>
99
+ setRightW((w) => Math.min(RIGHT_MAX, Math.max(RIGHT_MIN, w - dx)))
100
+ }
101
+ onDoubleClick={() => setRightW(RIGHT_DEFAULT)}
102
+ ariaLabel="Resize results pane"
103
+ />
104
+ <aside
105
+ style={{ width: rightW }}
106
+ className="shrink-0 border-l border-edge flex flex-col min-h-0"
107
+ >
108
  <ResultsPane />
109
  </aside>
110
  </div>
 
117
  </div>
118
  );
119
  }
120
+
121
+ /**
122
+ * 4-px wide vertical drag handle between two panes.
123
+ *
124
+ * - Report deltas in page pixels via onResize(dx) where dx is the movement
125
+ * relative to the mousedown position. The parent decides whether to add
126
+ * or subtract dx depending on which edge the handle sits on.
127
+ * - Double-click snaps the parent's width back to its default.
128
+ */
129
+ function PaneResizer({
130
+ onResize,
131
+ onDoubleClick,
132
+ ariaLabel,
133
+ }: {
134
+ onResize: (dx: number) => void;
135
+ onDoubleClick?: () => void;
136
+ ariaLabel: string;
137
+ }) {
138
+ const dragging = useRef(false);
139
+ const lastX = useRef(0);
140
+
141
+ const onMouseMove = useCallback(
142
+ (e: MouseEvent) => {
143
+ if (!dragging.current) return;
144
+ const dx = e.clientX - lastX.current;
145
+ lastX.current = e.clientX;
146
+ if (dx !== 0) onResize(dx);
147
+ },
148
+ [onResize],
149
+ );
150
+
151
+ const onMouseUp = useCallback(() => {
152
+ dragging.current = false;
153
+ document.body.style.cursor = "";
154
+ document.body.style.userSelect = "";
155
+ window.removeEventListener("mousemove", onMouseMove);
156
+ window.removeEventListener("mouseup", onMouseUp);
157
+ }, [onMouseMove]);
158
+
159
+ const onMouseDown = (e: React.MouseEvent) => {
160
+ e.preventDefault();
161
+ dragging.current = true;
162
+ lastX.current = e.clientX;
163
+ document.body.style.cursor = "col-resize";
164
+ document.body.style.userSelect = "none";
165
+ window.addEventListener("mousemove", onMouseMove);
166
+ window.addEventListener("mouseup", onMouseUp);
167
+ };
168
+
169
+ return (
170
+ <div
171
+ role="separator"
172
+ aria-orientation="vertical"
173
+ aria-label={ariaLabel}
174
+ title="Drag to resize. Double-click to reset."
175
+ onMouseDown={onMouseDown}
176
+ onDoubleClick={onDoubleClick}
177
+ className="group shrink-0 w-1 cursor-col-resize bg-edge/40 hover:bg-accent/60 active:bg-accent transition-colors"
178
+ />
179
+ );
180
+ }