Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(view-shell): remember every sidebar's resized width (#9830)

Peter Chinmanfffff7616ae8
diff --git a/apps/web/src/components/view-shell/ViewShell.test.tsx b/apps/web/src/components/view-shell/ViewShell.test.tsx
index a6888e228f..4d84b5ea52 100644
--- a/apps/web/src/components/view-shell/ViewShell.test.tsx
+++ b/apps/web/src/components/view-shell/ViewShell.test.tsx
@@ -116,21 +116,17 @@ it('keeps navigation controls inside their own workspaces', () => {
expect(collapsed.get('mail')?.()).toBe(true);
});
-function setup(preserveDuringResize: boolean, persistWidth = false) {
+function setup(preserveDuringResize: boolean, app = 'tasks') {
const [width, setWidth] = createSignal(1200);
- const [configuredWidth, setConfiguredWidth] = createSignal(256);
measurement.width = width;
- const onWidthChangeEnd = vi.fn((width: number) => {
- if (persistWidth) setConfiguredWidth(width);
- });
const view = render(() => (
<ViewShell.Root
resizable
- asidePreferenceKey="tasks"
- aside={{ width: configuredWidth(), preserveDuringResize }}
+ asidePreferenceKey={app}
+ aside={{ preserveDuringResize }}
main={{ preferredWidth: 640 }}
>
- <ViewShell.Aside onWidthChangeEnd={onWidthChangeEnd}>
+ <ViewShell.Aside>
<ViewSidebar.Header>
<ViewSidebar.Title>Tasks</ViewSidebar.Title>
</ViewSidebar.Header>
@@ -157,14 +153,15 @@ function setup(preserveDuringResize: boolean, persistWidth = false) {
fireEvent(window, new MouseEvent('pointermove', { clientX: 296 }));
fireEvent(window, new MouseEvent('pointerup', { clientX: 296 }));
};
+ const savedWidth = () =>
+ localStorage.getItem(`macro:pref:view-sidebar:width:${app}`);
return {
...view,
asideWidth,
growAside,
dragAside,
setWidth,
- setConfiguredWidth,
- onWidthChangeEnd,
+ savedWidth,
};
}
@@ -181,24 +178,21 @@ describe('ViewShell aside resize preference', () => {
}
});
- it.each([false, true])(
- 'keeps a manual resize in a constrained split stable as the split grows (persist=%s)',
- async (persistWidth) => {
- const view = setup(false, persistWidth);
- view.setWidth(890);
- expect(view.asideWidth()).toBeCloseTo(249);
- await view.growAside();
- expect(view.asideWidth()).toBeCloseTo(269);
- for (const width of [891, 900, 1000, 1200]) {
- view.setWidth(width);
- expect(view.asideWidth()).toBeCloseTo(269);
- }
- view.setWidth(880);
- expect(view.asideWidth()).toBeCloseTo(259);
- view.setWidth(1200);
+ it('keeps a manual resize in a constrained split stable as the split grows', async () => {
+ const view = setup(false);
+ view.setWidth(890);
+ expect(view.asideWidth()).toBeCloseTo(249);
+ await view.growAside();
+ expect(view.asideWidth()).toBeCloseTo(269);
+ for (const width of [891, 900, 1000, 1200]) {
+ view.setWidth(width);
expect(view.asideWidth()).toBeCloseTo(269);
}
- );
+ view.setWidth(880);
+ expect(view.asideWidth()).toBeCloseTo(259);
+ view.setWidth(1200);
+ expect(view.asideWidth()).toBeCloseTo(269);
+ });
it('preserves the chosen width through manual collapse and narrow overlays', async () => {
const view = setup(false);
@@ -223,7 +217,7 @@ describe('ViewShell aside resize preference', () => {
expect(view.asideWidth()).toBeCloseTo(276);
view.setWidth(1100);
expect(view.asideWidth()).toBeCloseTo(276);
- expect(view.onWidthChangeEnd).toHaveBeenCalledOnce();
+ expect(Number(view.savedWidth())).toBeCloseTo(276);
});
it('remembers the width after a pointer drag', () => {
@@ -232,7 +226,7 @@ describe('ViewShell aside resize preference', () => {
expect(view.asideWidth()).toBeCloseTo(296);
view.setWidth(1100);
expect(view.asideWidth()).toBeCloseTo(296);
- expect(view.onWidthChangeEnd).toHaveBeenCalledOnce();
+ expect(Number(view.savedWidth())).toBeCloseTo(296);
});
it.each([true, false])(
@@ -240,18 +234,33 @@ describe('ViewShell aside resize preference', () => {
async (preserve) => {
const view = setup(preserve);
expect(view.asideWidth()).toBeCloseTo(256);
+ expect(view.savedWidth()).toBeNull();
await view.growAside();
expect(view.asideWidth()).toBeCloseTo(276);
- expect(view.onWidthChangeEnd).toHaveBeenCalledOnce();
- expect(view.onWidthChangeEnd.mock.calls[0][0]).toBeCloseTo(276);
view.setWidth(1100);
expect(view.asideWidth()).toBeCloseTo(276);
view.setWidth(1400);
expect(view.asideWidth()).toBeCloseTo(276);
- expect(view.onWidthChangeEnd).toHaveBeenCalledOnce();
+ expect(Number(view.savedWidth())).toBeCloseTo(276);
}
);
+ it('restores the dragged width per app after the view remounts', () => {
+ const first = setup(false);
+ first.dragAside();
+ first.unmount();
+
+ expect(setup(false).asideWidth()).toBeCloseTo(296);
+ cleanup();
+ expect(setup(false, 'email').asideWidth()).toBeCloseTo(256);
+ });
+
+ it('fits a saved width to the current bounds', () => {
+ localStorage.setItem('macro:pref:view-sidebar:width:tasks', '900');
+ const view = setup(false);
+ expect(view.asideWidth()).toBeCloseTo(360);
+ });
+
it('yields to the main preference, then restores the chosen width', async () => {
const view = setup(false);
await view.growAside();
@@ -263,15 +272,6 @@ describe('ViewShell aside resize preference', () => {
view.setWidth(1200);
expect(view.asideWidth()).toBeCloseTo(276);
});
-
- it('honors a new configured width after a manual resize', async () => {
- const view = setup(true);
- await view.growAside();
- view.setConfiguredWidth(300);
- expect(view.asideWidth()).toBeCloseTo(300);
- view.setWidth(1100);
- expect(view.asideWidth()).toBeCloseTo(300);
- });
});
function Workspace(props: {
diff --git a/apps/web/src/components/view-shell/ViewShell.tsx b/apps/web/src/components/view-shell/ViewShell.tsx
index 612739d437..a4b42f0a4f 100644
--- a/apps/web/src/components/view-shell/ViewShell.tsx
+++ b/apps/web/src/components/view-shell/ViewShell.tsx
@@ -85,6 +85,7 @@ type ViewShellInternal = ViewShellLayout & {
id: string;
atLayoutBreakpoint: Accessor<boolean>;
asideHost: Accessor<'docked' | 'closing' | 'overlay'>;
+ chooseAsideWidth: (width: number) => void;
};
const RESIZE_GUTTER = 1;
@@ -134,8 +135,10 @@ export type ViewShellRootProps = Omit<
/** Set to false when the workspace has no navigation region. */
aside?: false | Partial<AsideLayout>;
/**
- * Sticky navigation visibility, scoped to this app type rather than an entry.
- * Only the first split uses it; other splits start collapsed.
+ * Sticky navigation visibility and width, scoped to this app type rather
+ * than an entry. Only the first split follows the saved visibility; other
+ * splits start collapsed. Every split opens at the last saved width; a drag
+ * in one split leaves the others' current widths alone.
*/
asidePreferenceKey?: string;
/**
@@ -200,6 +203,13 @@ function Root(props: ViewShellRootProps) {
{ default: false }
)
: createSignal(false);
+ // A width the user dragged to wins over the configured default.
+ const [chosenAsideWidth, setChosenAsideWidth] = local.asidePreferenceKey
+ ? usePreference<number | undefined>(
+ `macro:pref:view-sidebar:width:${local.asidePreferenceKey}`,
+ { default: undefined }
+ )
+ : createSignal<number>();
const id = createUniqueId();
const [root, setRoot] = createSignal<HTMLDivElement>();
const animateSidebar = createSidebarMotion(root);
@@ -217,10 +227,17 @@ function Root(props: ViewShellRootProps) {
return key;
};
- const asideLayout = (): AsideLayout => ({
- ...DEFAULT_ASIDE_LAYOUT,
- ...(local.aside || {}),
- });
+ const asideLayout = (): AsideLayout => {
+ const layout = { ...DEFAULT_ASIDE_LAYOUT, ...(local.aside || {}) };
+ const chosen = chosenAsideWidth();
+ // A saved width from older bounds still fits the current ones.
+ if (chosen === undefined || !Number.isFinite(chosen)) return layout;
+
+ return {
+ ...layout,
+ width: Math.min(layout.max, Math.max(layout.min, chosen)),
+ };
+ };
const mainLayout = (): MainLayout => ({
...DEFAULT_MAIN_LAYOUT,
@@ -372,6 +389,7 @@ function Root(props: ViewShellRootProps) {
breakpoints,
atLayoutBreakpoint,
asideHost,
+ chooseAsideWidth: setChosenAsideWidth,
aside: {
layout: asideLayout,
mode: asideMode,
@@ -450,33 +468,13 @@ function Root(props: ViewShellRootProps) {
* Sizing region for navigation. Renders a div, not aside.
* ViewSidebar.Root inside keeps the landmark.
*/
-type ViewShellAsideProps = JSX.HTMLAttributes<HTMLDivElement> & {
- /** Called with the solved aside width after a drag or keyboard resize. */
- onWidthChangeEnd?: (width: number) => void;
-};
-
-function Aside(props: ViewShellAsideProps) {
- const [local, rest] = splitProps(props, [
- 'children',
- 'class',
- 'onWidthChangeEnd',
- ]);
+function Aside(props: JSX.HTMLAttributes<HTMLDivElement>) {
+ const [local, rest] = splitProps(props, ['children', 'class']);
const ws = useViewShellInternal();
const asideTarget = tourTarget(VIEW_SHELL_TOUR.aside);
- const [resizedWidth, setResizedWidth] = createSignal<{
- configuredWidth: number;
- width: number;
- mainWidth?: number;
- }>();
- const resizePreference = () => {
- const resized = resizedWidth();
- return resized?.configuredWidth === ws.aside.layout().width
- ? resized
- : undefined;
- };
- const preferredWidth = () => {
- return resizePreference()?.width ?? ws.aside.layout().width;
- };
+ // Main's width after this mount's last drag; only the aside width is saved.
+ const [resizedMainWidth, setResizedMainWidth] = createSignal<number>();
+ const preferredWidth = () => ws.aside.layout().width;
const onWidthChangeEnd = (width: number) => {
const shellWidth = ws.width();
// A drag also chooses how much space Main gives up. Keeping its old soft
@@ -486,13 +484,8 @@ function Aside(props: ViewShellAsideProps) {
? shellWidth - RESIZE_GUTTER - width
: undefined;
batch(() => {
- local.onWidthChangeEnd?.(width);
- // A consumer may persist the width back into the layout in this callback.
- setResizedWidth({
- configuredWidth: ws.aside.layout().width,
- width,
- mainWidth,
- });
+ ws.chooseAsideWidth(width);
+ setResizedMainWidth(mainWidth);
});
};
const redistributionPreferredSize = () => {
@@ -514,10 +507,7 @@ function Aside(props: ViewShellAsideProps) {
shellWidth -
RESIZE_GUTTER -
Math.max(
- Math.min(
- mainLayout.preferredWidth,
- resizePreference()?.mainWidth ?? Infinity
- ),
+ Math.min(mainLayout.preferredWidth, resizedMainWidth() ?? Infinity),
mainLayout.min
);
diff --git a/apps/web/src/features/channels-view/channels-view-context.tsx b/apps/web/src/features/channels-view/channels-view-context.tsx
index 7ae672371d..41002eaa21 100644
--- a/apps/web/src/features/channels-view/channels-view-context.tsx
+++ b/apps/web/src/features/channels-view/channels-view-context.tsx
@@ -25,11 +25,7 @@ import type { ContextProviderProps } from '@solid-primitives/context';
import { type Accessor, createEffect, createMemo, on } from 'solid-js';
import { createStore, type Store } from 'solid-js/store';
import { channelsSearch, channelsSearchCodec } from './channels-route';
-import {
- CHANNELS_DEFAULT_RAIL_WIDTH,
- CHANNELS_DEFAULT_SORT_BY,
- clampChannelsRailWidth,
-} from './constants';
+import { CHANNELS_DEFAULT_SORT_BY } from './constants';
import { createChannelsViewPersistence } from './persistence';
import type {
ChannelListSort,
@@ -76,7 +72,6 @@ export type ChannelsViewContext = {
preferences: ChannelSectionPreferences
) => void;
setSectionOrder: (sections: ChannelSectionKey[]) => void;
- setAsideWidth: (width: number) => void;
};
function createInitialState(
@@ -103,14 +98,11 @@ function createInitialState(
},
sectionPreferences: { ...initial.sectionPreferences },
sectionOrder: initial.sectionOrder ?? [],
- asideWidth: clampChannelsRailWidth(
- initial.asideWidth ?? CHANNELS_DEFAULT_RAIL_WIDTH
- ),
};
}
function shouldRestorePreferences(initial: ChannelsViewStateOptions): boolean {
- return initial.asideWidth === undefined && initial.sortBy === undefined;
+ return initial.sortBy === undefined;
}
export const [ChannelsViewProvider, useChannelsView] =
@@ -271,8 +263,6 @@ export const [ChannelsViewProvider, useChannelsView] =
[section]: { ...current[section], ...preferences },
})),
setSectionOrder: (sections) => setState('sectionOrder', sections),
- setAsideWidth: (width) =>
- setState('asideWidth', clampChannelsRailWidth(width)),
};
}
);
diff --git a/apps/web/src/features/channels-view/channels-view.test.tsx b/apps/web/src/features/channels-view/channels-view.test.tsx
index e21c26d5cf..4cfc06f37a 100644
--- a/apps/web/src/features/channels-view/channels-view.test.tsx
+++ b/apps/web/src/features/channels-view/channels-view.test.tsx
@@ -193,7 +193,6 @@ vi.mock('./channels-view-context', () => ({
ChannelsViewProvider: mocks.pass,
useChannelsView: () => ({
state: {
- asideWidth: 256,
tab: 'browse',
sortBy: { channels: 'updated_at', direct_messages: 'updated_at' },
},
@@ -212,7 +211,6 @@ vi.mock('./channels-view-context', () => ({
target: mocks.target(),
}
: undefined,
- setAsideWidth: vi.fn(),
}),
}));
vi.mock('./queries', () => ({
diff --git a/apps/web/src/features/channels-view/channels-view.tsx b/apps/web/src/features/channels-view/channels-view.tsx
index db9a5a51f7..1c08ad87ce 100644
--- a/apps/web/src/features/channels-view/channels-view.tsx
+++ b/apps/web/src/features/channels-view/channels-view.tsx
@@ -146,14 +146,8 @@ function DesktopChannelThreads(props: { sources: ChannelsSources }) {
}
function ChannelsViewRoot() {
const panel = useSplitPanelOrThrow();
- const {
- state,
- tab,
- mobileLayout,
- sectionsLoading,
- selectedChannel,
- setAsideWidth,
- } = useChannelsView();
+ const { state, tab, mobileLayout, sectionsLoading, selectedChannel } =
+ useChannelsView();
const threadsTab = () => !mobileLayout() && tab() === 'threads';
const [railSearchOpen, setRailSearchOpen] = createSignal(false);
@@ -198,14 +192,11 @@ function ChannelsViewRoot() {
asideRequired={selectedChannel() === undefined}
// Keep tab changes from resetting a narrow navigation overlay.
asidePinned={threadsTab()}
- aside={{
- width: state.asideWidth,
- preserveDuringResize: false,
- }}
+ aside={{ preserveDuringResize: false }}
main={{ preferredWidth: 640 }}
resizable
>
- <ViewShell.Aside onWidthChangeEnd={setAsideWidth}>
+ <ViewShell.Aside>
<DebugSuspense
name="ChannelsView.rail"
fallback={
diff --git a/apps/web/src/features/channels-view/constants.ts b/apps/web/src/features/channels-view/constants.ts
index 70ee735b47..d94cf6cd9f 100644
--- a/apps/web/src/features/channels-view/constants.ts
+++ b/apps/web/src/features/channels-view/constants.ts
@@ -1,10 +1,5 @@
-import { DEFAULT_ASIDE_LAYOUT } from '@app/components/view-shell/view-shell-layout';
import type { ChannelListSort, ChannelsSortGroup } from './types';
-export const CHANNELS_DEFAULT_RAIL_WIDTH = DEFAULT_ASIDE_LAYOUT.width;
-export const CHANNELS_MIN_RAIL_WIDTH = DEFAULT_ASIDE_LAYOUT.min;
-export const CHANNELS_MAX_RAIL_WIDTH = DEFAULT_ASIDE_LAYOUT.max;
-
export const CHANNEL_SECTION_ROW_HEIGHT = 34;
export const CHANNEL_SECTION_MIN_ITEMS = 2;
export const CHANNEL_SECTION_MIN_HEIGHT =
@@ -22,12 +17,3 @@ export const CHANNELS_DEFAULT_SORT_BY = {
direct_messages: 'updated_at',
threads: 'updated_at',
} satisfies Record<ChannelsSortGroup, ChannelListSort>;
-
-export function clampChannelsRailWidth(width: number): number {
- if (!Number.isFinite(width)) return CHANNELS_DEFAULT_RAIL_WIDTH;
-
- return Math.min(
- CHANNELS_MAX_RAIL_WIDTH,
- Math.max(CHANNELS_MIN_RAIL_WIDTH, width)
- );
-}
diff --git a/apps/web/src/features/channels-view/persistence.ts b/apps/web/src/features/channels-view/persistence.ts
index b30a7b0e9f..f2d5e1bb35 100644
--- a/apps/web/src/features/channels-view/persistence.ts
+++ b/apps/web/src/features/channels-view/persistence.ts
@@ -10,10 +10,8 @@ import { createUserScopedStorage } from '@core/util/userScopedStorage';
import type { Accessor } from 'solid-js';
import { z } from 'zod';
import {
- CHANNELS_DEFAULT_RAIL_WIDTH,
CHANNELS_DEFAULT_SORT_BY,
clampChannelSectionHeight,
- clampChannelsRailWidth,
} from './constants';
import type { ChannelsViewState } from './types';
@@ -75,11 +73,6 @@ const DEFAULT_CHANNELS_ENTRY_STATE = {
const channelsPreferencesSchema = z.object({
version: z.literal(1).default(1),
- asideWidth: z
- .number()
- .finite()
- .default(CHANNELS_DEFAULT_RAIL_WIDTH)
- .transform(clampChannelsRailWidth),
sortBy: z
.object({
team_channels: z
@@ -130,7 +123,6 @@ type ChannelsPreferences = z.infer<typeof channelsPreferencesSchema>;
const DEFAULT_CHANNELS_PREFERENCES = {
version: 1,
- asideWidth: CHANNELS_DEFAULT_RAIL_WIDTH,
sortBy: CHANNELS_DEFAULT_SORT_BY,
sectionPreferences: {},
sectionOrder: [],
@@ -227,7 +219,6 @@ function createChannelsPreferencesStorage(options: {
const serialize = (state: ChannelsViewState) =>
JSON.stringify({
version: 1,
- asideWidth: clampChannelsRailWidth(state.asideWidth),
sortBy: state.sortBy,
sectionPreferences: state.sectionPreferences,
sectionOrder: state.sectionOrder,
@@ -251,7 +242,6 @@ function createChannelsPreferencesStorage(options: {
return {
...current,
- asideWidth: restored.asideWidth,
sortBy: restored.sortBy,
sectionPreferences: restored.sectionPreferences,
sectionOrder: options.restoreSectionOrder
@@ -261,7 +251,6 @@ function createChannelsPreferencesStorage(options: {
} catch {
return {
...current,
- asideWidth: DEFAULT_CHANNELS_PREFERENCES.asideWidth,
sortBy: DEFAULT_CHANNELS_PREFERENCES.sortBy,
sectionPreferences: DEFAULT_CHANNELS_PREFERENCES.sectionPreferences,
sectionOrder: options.restoreSectionOrder
diff --git a/apps/web/src/features/channels-view/types.ts b/apps/web/src/features/channels-view/types.ts
index 6439f8765c..7095d4e441 100644
--- a/apps/web/src/features/channels-view/types.ts
+++ b/apps/web/src/features/channels-view/types.ts
@@ -41,7 +41,6 @@ export type ChannelsViewState = {
>;
/** Personal display order, independent of shared section membership. */
sectionOrder: ChannelSectionKey[];
- asideWidth: number;
};
export type ChannelsViewStateOptions = Partial<
diff --git a/apps/web/src/features/external-view/external-view-skeleton.tsx b/apps/web/src/features/external-view/external-view-skeleton.tsx
index 7800148d40..c292ef7b96 100644
--- a/apps/web/src/features/external-view/external-view-skeleton.tsx
+++ b/apps/web/src/features/external-view/external-view-skeleton.tsx
@@ -6,7 +6,10 @@ export function ExternalViewSkeleton() {
return (
<ViewSkeleton.Root
asidePreferenceKey="external"
- aside={isTouchDevice() ? false : undefined}
+ // The loaded view keeps the shell's default sizing; match it so a saved
+ // sidebar width does not shift when the view replaces the skeleton.
+ aside={isTouchDevice() ? false : {}}
+ main={{}}
>
<ViewSkeleton.Sidebar title="External" />
<ViewSkeleton.Main title="WhatsApp" />
diff --git a/docs/agent-guide/navigation.md b/docs/agent-guide/navigation.md
index 0d86b102db..975d96b30b 100644
--- a/docs/agent-guide/navigation.md
+++ b/docs/agent-guide/navigation.md
@@ -673,7 +673,9 @@ opens Home. Excluded background panels do not count toward close eligibility.
These buttons and Home items activate on primary-button
press; keyboard activation remains supported. Home, Chat, Email,
Tasks, and other views using the shared inner
-sidebar layout default to 256px; manually resized Chat widths remain saved.
+sidebar layout default to 256px. Each view type saves a manually resized width
+(`asidePreferenceKey`) and restores it after reloads, view switches, and in
+other splits.
After dragging a view's inner sidebar divider (or using its arrow keys), resizing
the containing split preserves the chosen sidebar width while space permits.