Skip to content

Commit b80b33e

Browse files
authored
feat(app): add sidebar resize support and improve light mode vibrancy (anomalyco#1686)
1 parent ed26bea commit b80b33e

4 files changed

Lines changed: 38 additions & 4 deletions

File tree

‎apps/app/src/react-app/domains/session/chat/session-page.tsx‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/** @jsxImportSource react */
2+
import type { CSSProperties } from "react";
23
import { useCallback, useEffect, useMemo, useState } from "react";
34
import { Check, Globe, Loader2, Minimize2, Redo2, Undo2, Zap } from "lucide-react";
45

@@ -35,6 +36,8 @@ import { OwDotTicker } from "../../../shell/dot-ticker";
3536
import { useReactRenderWatchdog } from "../../../shell/react-render-watchdog";
3637
import { isElectronRuntime } from "../../../../app/utils";
3738
import { BrowserPanel } from "../browser/browser-panel";
39+
import { useWorkspaceShellLayout } from "../../../shell/workspace-shell-layout";
40+
import { cn } from "@/lib/utils";
3841

3942
type StatusBarOverrides = Pick<
4043
StatusBarProps,
@@ -189,6 +192,12 @@ export function SessionPage(props: SessionPageProps) {
189192
const unsubClose = browser.onPanelClosed?.(() => setBrowserPanelOpen(false));
190193
return () => { unsubOpen?.(); unsubClose?.(); };
191194
}, []);
195+
const { leftSidebarResizing, leftSidebarWidth, startLeftSidebarResize } = useWorkspaceShellLayout({
196+
expandedRightWidth: 520,
197+
});
198+
const sidebarProviderStyle: CSSProperties & Record<"--sidebar-width", string> = {
199+
"--sidebar-width": `${leftSidebarWidth}px`,
200+
};
192201
const [showDelayedSessionLoadingState, setShowDelayedSessionLoadingState] = useState(false);
193202

194203
const selectedSessionTitle = useMemo(
@@ -297,7 +306,14 @@ export function SessionPage(props: SessionPageProps) {
297306

298307
return (
299308
<div className="flex h-full min-h-0 flex-col bg-[radial-gradient(circle_at_top,rgba(74,111,255,0.12),transparent_42%),var(--app-bg,#0b1020)] text-dls-text mac:bg-transparent">
300-
<SidebarProvider className="relative min-h-0 flex-1 mac:bg-transparent">
309+
<SidebarProvider
310+
className={cn(
311+
"relative min-h-0 flex-1 mac:bg-transparent",
312+
leftSidebarResizing &&
313+
"**:data-[slot=sidebar-container]:transition-none **:data-[slot=sidebar-gap]:transition-none",
314+
)}
315+
style={sidebarProviderStyle}
316+
>
301317
<AppSidebar
302318
workspaceSessionGroups={props.sidebar.workspaceSessionGroups}
303319
selectedWorkspaceId={props.sidebar.selectedWorkspaceId}
@@ -326,6 +342,7 @@ export function SessionPage(props: SessionPageProps) {
326342
onEditWorkspaceConnection={props.sidebar.onEditWorkspaceConnection}
327343
onForgetWorkspace={props.sidebar.onForgetWorkspace}
328344
onOpenCreateWorkspace={props.sidebar.onOpenCreateWorkspace}
345+
onStartResize={startLeftSidebarResize}
329346
/>
330347
<SidebarInset className="min-h-0 overflow-hidden bg-background mac:bg-background/80 mac:[&_header]:transition-[padding-left] mac:[&_header]:duration-200 mac:[&_header]:ease-linear mac:peer-data-[state=collapsed]:[&_header]:pl-28 mac:max-md:[&_header]:pl-28 flex flex-row">
331348
<main className="flex min-w-0 flex-1 flex-col overflow-hidden border-r border-border">

‎apps/app/src/react-app/domains/session/sidebar/app-sidebar.tsx‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
SidebarMenuSub,
4040
SidebarMenuSubButton,
4141
SidebarMenuSubItem,
42+
SidebarRail,
4243
} from "@/components/ui/sidebar";
4344
import {
4445
Collapsible,
@@ -255,6 +256,7 @@ export type AppSidebarProps = {
255256
onEditWorkspaceConnection: (workspaceId: string) => void;
256257
onForgetWorkspace: (workspaceId: string) => void;
257258
onOpenCreateWorkspace: () => void;
259+
onStartResize?: React.PointerEventHandler<HTMLButtonElement>;
258260
};
259261

260262
function useSessionTree(
@@ -420,6 +422,14 @@ export function AppSidebar(props: AppSidebarProps) {
420422
</SidebarMenuItem>
421423
</SidebarMenu>
422424
</SidebarFooter>
425+
<SidebarRail
426+
aria-label={props.onStartResize ? t("session.resize_workspace_column") : undefined}
427+
title={props.onStartResize ? t("session.resize_workspace_column") : undefined}
428+
onClick={props.onStartResize ? (event) => {
429+
event.preventDefault();
430+
} : undefined}
431+
onPointerDown={props.onStartResize}
432+
/>
423433
</Sidebar>
424434
</SidebarContext.Provider>
425435
);

‎apps/app/src/react-app/shell/workspace-shell-layout.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export function useWorkspaceShellLayout(options: WorkspaceShellLayoutOptions) {
6767
}, []);
6868

6969
const [leftSidebarWidth, setLeftSidebarWidth] = useState(readLeftSidebarWidth);
70+
const [leftSidebarResizing, setLeftSidebarResizing] = useState(false);
7071
const [rightSidebarExpanded, setRightSidebarExpanded] = useState(readRightSidebarExpanded);
7172
const dragCleanupRef = useRef<(() => void) | null>(null);
7273

@@ -89,6 +90,7 @@ export function useWorkspaceShellLayout(options: WorkspaceShellLayoutOptions) {
8990
const stopLeftSidebarResize = useCallback(() => {
9091
dragCleanupRef.current?.();
9192
dragCleanupRef.current = null;
93+
setLeftSidebarResizing(false);
9294
if (typeof document === "undefined") return;
9395
document.body.style.removeProperty("cursor");
9496
document.body.style.removeProperty("user-select");
@@ -99,6 +101,7 @@ export function useWorkspaceShellLayout(options: WorkspaceShellLayoutOptions) {
99101
if (event.button !== 0 || typeof window === "undefined") return;
100102

101103
stopLeftSidebarResize();
104+
setLeftSidebarResizing(true);
102105
const initialX = event.clientX;
103106
const initialWidth = leftSidebarWidth;
104107

@@ -142,6 +145,7 @@ export function useWorkspaceShellLayout(options: WorkspaceShellLayoutOptions) {
142145

143146
return {
144147
leftSidebarWidth,
148+
leftSidebarResizing,
145149
rightSidebarExpanded,
146150
rightSidebarWidth,
147151
setRightSidebarExpanded,

‎apps/desktop/electron/main.mjs‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,15 +1090,18 @@ function activeWindowFromEvent(event) {
10901090
return BrowserWindow.fromWebContents(event.sender) ?? mainWindow ?? undefined;
10911091
}
10921092

1093+
function macosVibrancyForCurrentTheme() {
1094+
return nativeTheme.shouldUseDarkColors ? "under-window" : "sidebar";
1095+
}
1096+
10931097
function applyNativeTheme(mode) {
10941098
nativeTheme.themeSource = mode;
10951099

10961100
if (process.platform !== "darwin") {
10971101
return true;
10981102
}
1099-
// const isDark = nativeTheme.shouldUseDarkColors;
11001103

1101-
mainWindow?.setVibrancy("under-window");
1104+
mainWindow?.setVibrancy(macosVibrancyForCurrentTheme());
11021105
mainWindow?.setBackgroundColor("#00000001");
11031106

11041107
return true;
@@ -1705,7 +1708,7 @@ async function createMainWindow() {
17051708
Object.assign(windowAppearanceOptions, {
17061709
backgroundColor: "#00000001",
17071710
titleBarStyle: "hiddenInset",
1708-
vibrancy: "under-window",
1711+
vibrancy: macosVibrancyForCurrentTheme(),
17091712
visualEffectState: "active",
17101713
});
17111714
}

0 commit comments

Comments
 (0)