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(settings): have settings use the split layout (#4610)

Aidan Holloway-Bidwell0db9c7e13cdf
diff --git a/js/app/packages/app/component/Layout.tsx b/js/app/packages/app/component/Layout.tsx
index 2253d44330..1a0a64d5e1 100644
--- a/js/app/packages/app/component/Layout.tsx
+++ b/js/app/packages/app/component/Layout.tsx
@@ -1,5 +1,6 @@
import {
AppSidebar,
+ GoToHotkeys,
type SidebarState,
} from '@app/component/app-sidebar/sidebar';
import {
@@ -11,7 +12,7 @@ import { mountGlobalFocusListener } from '@app/signal/focus';
import { AutomationComposer } from '@block-automation/component';
import { useIsAuthenticated } from '@core/auth';
import { usePaywallState } from '@core/constant/PaywallState';
-import { isSettingsPath } from '@core/constant/SettingsState';
+import { isSoloSettings } from '@core/constant/SettingsState';
import { isMobile } from '@core/mobile/isMobile';
import { virtualKeyboardVisible } from '@core/mobile/virtualKeyboard';
import { updateCookie } from '@core/util/cookies';
@@ -79,12 +80,9 @@ export function Layout(props: RouteSectionProps) {
!isMobile() &&
isAuthenticated() === true &&
!AUTH_URLS.includes(location.pathname) &&
- // Settings is a full-cover route with its own tab nav — hide app chrome.
- !isSettingsPath(location.pathname)
+ // Settings-as-the-sole-split has its own tab nav — hide app chrome.
+ !isSoloSettings()
);
- createEffect(() => {
- console.log('VIZ', sidebarVisible());
- });
return (
<SidebarVisibilityContext.Provider value={sidebarVisible}>
@@ -142,6 +140,7 @@ function LayoutInner(props: RouteSectionProps) {
</Show>
<GlobalShortcuts />
<Show when={!isMobile()}>
+ <GoToHotkeys />
<Suspense>
<FavoritesCommands />
<CommandMenu />
diff --git a/js/app/packages/app/component/Root.tsx b/js/app/packages/app/component/Root.tsx
index 5f11e76e02..1c499d6904 100644
--- a/js/app/packages/app/component/Root.tsx
+++ b/js/app/packages/app/component/Root.tsx
@@ -106,7 +106,6 @@ import { Layout } from './Layout';
import { SearchProvider } from './next-soup/search-context';
import { usePendingNotificationNavigationEffect } from './PendingNotificationNavigationEffect';
import { ReactiveFavicon } from './ReactiveFavicon';
-import { SettingsRoute } from './settings/SettingsRoute';
import { LAYOUT_ROUTE } from './split-layout/SplitLayoutRoute';
import { TeamInviteAcceptance } from './TeamInviteAcceptance';
@@ -265,13 +264,6 @@ const { EmailCallback, CALLBACK_PATH, EmailLinkCallback, LINK_CALLBACK_PATH } =
const ROUTES: RouteDefinition[] = [
LAYOUT_ROUTE,
- // Settings is its own place (`/settings/:tab`) rather than a layout split, so
- // it's linkable without dragging the workspace layout into the URL. The static
- // prefix outranks the `/*splits` splat.
- {
- path: '/settings/:tab?',
- component: SettingsRoute,
- },
/** BEGIN - APP ROUTES */
{
path: '/inbox',
diff --git a/js/app/packages/app/component/app-sidebar/sidebar.tsx b/js/app/packages/app/component/app-sidebar/sidebar.tsx
index 4e6fba1aa5..7518c6ee61 100644
--- a/js/app/packages/app/component/app-sidebar/sidebar.tsx
+++ b/js/app/packages/app/component/app-sidebar/sidebar.tsx
@@ -284,13 +284,8 @@ type AppSidebarProps = {
};
type SidebarHotkeyDeps = {
- links: () => SidebarItem[];
- hotkeyVisible: () => boolean;
- setHotkeyVisible: (visible: boolean) => void;
- resetHotkeysState: VoidFunction;
isSlim: () => boolean;
onOpenChange: (open: boolean) => void;
- openWithSplit: ReturnType<typeof useSplitLayout>['openWithSplit'];
};
type OpenWithSplitFn = ReturnType<typeof useSplitLayout>['openWithSplit'];
@@ -349,19 +344,82 @@ function navigateToSidebarView(args: {
}
const registerSidebarHotkeys = ({
- links,
isSlim,
onOpenChange,
- openWithSplit,
- hotkeyVisible,
- setHotkeyVisible,
- resetHotkeysState,
}: SidebarHotkeyDeps) => {
- const debounceResetHotkeysState = debounce(resetHotkeysState, 2000);
- const debounceSetHotkeyVisible = debounce(() => setHotkeyVisible(true), 200);
+ // Scoped to the sidebar's lifecycle on purpose: it toggles sidebar +
+ // side-panel state, which is force-hidden (and thus a no-op) on full-cover
+ // routes like solo settings, where `AppSidebar` unmounts. Genuinely global
+ // shortcuts that must survive those routes live in `GoToHotkeys` instead.
+ registerHotkey({
+ hotkey: 'cmd+.',
+ scopeId: 'global',
+ hotkeyToken: TOKENS.global.toggleSidebar,
+ description: 'Toggle sidebar and side panels',
+ runWithInputFocused: true,
+ keyDownHandler: (e) => {
+ e?.preventDefault();
+ const show = isSlim();
+ onOpenChange(show);
+ setAllSidePanelsOpen(show);
+ return true;
+ },
+ });
+};
+
+/**
+ * Whether the "g" leader key is currently awaiting a destination key. Lives
+ * at module scope so it can drive the hint overlay on `AppSidebar`'s nav
+ * icons even though the registration below is owned by `GoToHotkeys`, which
+ * stays mounted regardless of whether the sidebar itself is visible.
+ */
+const [goToHotkeyVisible, setGoToHotkeyVisible] = createSignal(false);
+
+const resetGoToHotkeysState = () => {
+ setGoToHotkeyVisible(false);
+ // To prevent the next key from triggering the hotkey handler,
+ // we reset the pressed keys state and exit the command scope
+ clearPressedKeys();
+ activateClosestDOMScope();
+};
+
+/**
+ * Hosts the always-on global shortcuts that must keep working even on
+ * full-cover routes like solo settings: the "g" leader key with its per-link
+ * "go to" nav hotkeys (e.g. "g i" for inbox), plus Send Invites. Rendered
+ * unconditionally from `Layout` — unlike `AppSidebar`, which unmounts on those
+ * routes — so none of them go dead there.
+ */
+export const GoToHotkeys = () => {
+ const { openWithSplit } = useSplitLayout();
+
+ const inviteHotkey = registerHotkey({
+ scopeId: 'global',
+ hotkeyToken: TOKENS.global.inviteTeam,
+ description: 'Send Invites',
+ keyDownHandler: (e) => {
+ e?.preventDefault();
+ setInviteModalOpen(true);
+ return true;
+ },
+ });
+
+ const homeViewEnabled = useFeatureFlag('enable-home-view', {
+ enabledOverride: ENABLE_HOME_OVERRIDE,
+ });
+
+ const links = createMemo((): SidebarItem[] =>
+ buildSidebarLinks(homeViewEnabled().enabled)
+ );
+
+ const debounceResetHotkeysState = debounce(resetGoToHotkeysState, 2000);
+ const debounceSetHotkeyVisible = debounce(
+ () => setGoToHotkeyVisible(true),
+ 200
+ );
// Register 'g' as a leader key that activates the global GO_TO command scope
- registerHotkey({
+ const leaderHotkey = registerHotkey({
hotkey: GO_TO_LEADER_KEY,
scopeId: 'global',
hotkeyToken: TOKENS.sidebar.goToLeader,
@@ -378,6 +436,16 @@ const registerSidebarHotkeys = ({
registrationType: 'add',
});
+ // These two register in the 'global' scope, which outlives this component, so
+ // dispose them on unmount. Otherwise a remount (e.g. crossing the mobile
+ // breakpoint) leaks: the 'add' leader stacks duplicate handlers and the
+ // token-only invite command accumulates in the registry. The per-link nav
+ // hotkeys below are disposed by their own effect cleanup.
+ onCleanup(() => {
+ inviteHotkey.dispose();
+ leaderHotkey.dispose();
+ });
+
const registeredGoToKeys = () =>
new Set<ValidHotkey>(links().map((link) => link.hotkey));
@@ -389,7 +457,7 @@ const registerSidebarHotkeys = ({
// If a hotkey is going to be fired, but the hotkeys are not
// visible, then it's not a sidebar nav hotkey and we can
// ignore it and reset our visible state
- if (!hotkeyVisible()) {
+ if (!goToHotkeyVisible()) {
debounceSetHotkeyVisible.clear();
return false;
}
@@ -403,38 +471,12 @@ const registerSidebarHotkeys = ({
return false;
}
- resetHotkeysState();
+ resetGoToHotkeysState();
debounceResetHotkeysState.clear();
return true;
});
- registerHotkey({
- scopeId: 'global',
- hotkeyToken: TOKENS.global.inviteTeam,
- description: 'Send Invites',
- keyDownHandler: (e) => {
- e?.preventDefault();
- setInviteModalOpen(true);
- return true;
- },
- });
-
- registerHotkey({
- hotkey: 'cmd+.',
- scopeId: 'global',
- hotkeyToken: TOKENS.global.toggleSidebar,
- description: 'Toggle sidebar and side panels',
- runWithInputFocused: true,
- keyDownHandler: (e) => {
- e?.preventDefault();
- const show = isSlim();
- onOpenChange(show);
- setAllSidePanelsOpen(show);
- return true;
- },
- });
-
// Register navigation shortcuts in the global GO_TO command scope.
// This must be reactive because prod feature flags can add links after the
// initial render (e.g. Home), and Hotkey UI resolves tokens from the registry.
@@ -442,8 +484,8 @@ const registerSidebarHotkeys = ({
const disposers = links().map((link) => {
const openSidebarView = (e?: KeyboardEvent) => {
e?.preventDefault();
- if (hotkeyVisible()) {
- resetHotkeysState();
+ if (goToHotkeyVisible()) {
+ resetGoToHotkeysState();
debounceResetHotkeysState.clear();
}
@@ -489,6 +531,8 @@ const registerSidebarHotkeys = ({
}
});
});
+
+ return null;
};
/** Session-only signal so a hint shows after dismissal until the user acknowledges or the timer expires. */
@@ -695,6 +739,30 @@ const DASHBOARD_LINK: SidebarItem = {
hotkeyToken: TOKENS.sidebar.goTo.home,
};
+/**
+ * Assemble the ordered sidebar link list: the static links plus the flag-gated
+ * Home and Calls entries in their correct positions. Shared by the rendered
+ * sidebar (`AppSidebar.visibleLinks`) and the always-mounted `GoToHotkeys`
+ * registrar so their link sets can't drift. Call from a reactive context — it
+ * reads `ENABLE_CALLS()`; `homeEnabled` is passed in so the caller tracks the
+ * feature-flag read. `visibleLinks` additionally drops `hiddenFromSidebar`
+ * entries, which have hotkeys but no sidebar row.
+ */
+const buildSidebarLinks = (homeEnabled: boolean): SidebarItem[] => {
+ let links: SidebarItem[] = [...SIDEBAR_LINKS];
+
+ if (homeEnabled) {
+ links = [DASHBOARD_LINK, ...links];
+ }
+
+ if (ENABLE_CALLS()) {
+ const idx = links.findIndex((l) => l.id === 'channels');
+ links = [...links.slice(0, idx + 1), CALLS_LINK, ...links.slice(idx + 1)];
+ }
+
+ return links;
+};
+
/**
* Settings tabs surfaced as always-visible quick links above the settings
* widget. Label/icon come from the settings tab config (see
@@ -707,7 +775,6 @@ const PROMOTED_SETTINGS_TABS: SettingsTab[] = [
];
export const AppSidebar = (props: AppSidebarProps) => {
- const layout = useSplitLayout();
const { openSettings, selectTab, settingsOpen } = useSettingsState();
const isTabAvailable = useSettingsTabAvailable();
const callCtx = useCallContextOptional();
@@ -728,46 +795,11 @@ export const AppSidebar = (props: AppSidebarProps) => {
enabledOverride: ENABLE_NEW_PRICING_OVERRIDE,
});
- const [hotkeyVisible, setHotkeyVisible] = createSignal(false);
-
- const visibleLinks = createMemo((): SidebarItem[] => {
- let links: SidebarItem[] = [...SIDEBAR_LINKS];
-
- if (homeViewEnabled().enabled) {
- links = [DASHBOARD_LINK, ...links];
- }
-
- if (ENABLE_CALLS()) {
- const idx = links.findIndex((l) => l.id === 'channels');
- links = [...links.slice(0, idx + 1), CALLS_LINK, ...links.slice(idx + 1)];
- }
-
- return links.filter((link) => !link.hiddenFromSidebar);
- });
-
- const hotkeyLinks = createMemo((): SidebarItem[] => {
- let links: SidebarItem[] = [...SIDEBAR_LINKS];
-
- if (homeViewEnabled().enabled) {
- links = [DASHBOARD_LINK, ...links];
- }
-
- if (ENABLE_CALLS()) {
- const idx = links.findIndex((l) => l.id === 'channels');
- links = [...links.slice(0, idx + 1), CALLS_LINK, ...links.slice(idx + 1)];
- }
-
- return links;
- });
-
- const resetHotkeysState = () => {
- setHotkeyVisible(false);
-
- // To prevent the next key from triggering the hotkey handler,
- // we reset the pressed keys state and exit the command scope
- clearPressedKeys();
- activateClosestDOMScope();
- };
+ const visibleLinks = createMemo((): SidebarItem[] =>
+ buildSidebarLinks(homeViewEnabled().enabled).filter(
+ (link) => !link.hiddenFromSidebar
+ )
+ );
const openSettingsTab = (tab: SettingsTab) => {
if (!isTabAvailable(tab)) return;
@@ -789,13 +821,8 @@ export const AppSidebar = (props: AppSidebarProps) => {
});
registerSidebarHotkeys({
- links: hotkeyLinks,
- hotkeyVisible,
- setHotkeyVisible,
- resetHotkeysState,
isSlim,
onOpenChange: handleSidebarOpenChange,
- openWithSplit: layout.openWithSplit,
});
return (
@@ -848,7 +875,7 @@ export const AppSidebar = (props: AppSidebarProps) => {
component={link.id === 'mail' ? SidebarMailLink : SidebarLink}
{...link}
sidebarState={props.sidebarState ?? 'expanded'}
- hotkeyVisible={hotkeyVisible()}
+ hotkeyVisible={goToHotkeyVisible()}
/>
</li>
)}
diff --git a/js/app/packages/app/component/settings/Settings.tsx b/js/app/packages/app/component/settings/Settings.tsx
index 2fac748aeb..9454cf2c4c 100644
--- a/js/app/packages/app/component/settings/Settings.tsx
+++ b/js/app/packages/app/component/settings/Settings.tsx
@@ -2,6 +2,7 @@ import { Billing } from '@app/component/settings/Billing';
import { useLogout } from '@core/auth/logout';
import { TabsInsetDropdown } from '@core/component/TabsInsetDropdown';
import {
+ isSoloSettings,
type SettingsTab,
settingsTabFromSplitPath,
useSettingsState,
@@ -68,7 +69,7 @@ export function SettingsPanelComponentWrapper() {
const tab = settingsTabFromSplitPath(location.pathname);
if (tab && untrack(activeTabId) !== tab) setActiveTabId(tab);
});
- return <SettingsPanel />;
+ return <SettingsPanel variant={isSoloSettings() ? 'fullscreen' : 'split'} />;
}
type SettingsPanelProps = {
@@ -81,7 +82,7 @@ export function SettingsPanel(props: SettingsPanelProps) {
const {
closeSettings,
moveSettingsToSplit,
- moveSettingsToFullscreen,
+ moveSettingsToSolo,
activeTabId,
selectTab,
} = useSettingsState();
@@ -223,7 +224,7 @@ export function SettingsPanel(props: SettingsPanelProps) {
);
}
- // "Back to app" — the full-page route's only close affordance. Laid out like a nav row.
+ // "Back to app" — the close affordance for solo settings. Laid out like a nav row.
const backToApp = () => (
<button
type="button"
@@ -276,13 +277,13 @@ export function SettingsPanel(props: SettingsPanelProps) {
</div>
</Show>
</SplitHeaderLeft>
- {/* Pop the split back out into the full-page settings route (desktop only). */}
+ {/* Collapse the other splits so settings becomes the sole one (desktop only). */}
<Show when={!isMobile()}>
<SplitHeaderRight>
<Button
class="p-1 rounded-lg"
label="Open fullscreen"
- onClick={() => moveSettingsToFullscreen()}
+ onClick={() => moveSettingsToSolo()}
>
<ArrowsOut class="size-4" />
</Button>
diff --git a/js/app/packages/app/component/settings/SettingsRoute.tsx b/js/app/packages/app/component/settings/SettingsRoute.tsx
deleted file mode 100644
index b00f8e4082..0000000000
--- a/js/app/packages/app/component/settings/SettingsRoute.tsx
+++ /dev/null
@@ -1,64 +0,0 @@
-import { useSettingsState } from '@core/constant/SettingsState';
-import { settingsSlugToTab } from '@core/constant/settingsTabsConfig';
-import { isMobile } from '@core/mobile/isMobile';
-import { Navigate, useParams } from '@solidjs/router';
-import { Layer } from '@ui';
-import { createEffect, Show } from 'solid-js';
-import { SettingsPanel } from './Settings';
-
-/**
- * Settings as a full-page route (`/settings/:tab`). This replaces the old
- * signal-driven fullscreen overlay: the URL is now the source of truth for
- * whether settings is open and which page is showing, so it's linkable and
- * survives reload — without leaking the workspace layout that a query param on
- * the split path would have carried.
- *
- * The app sidebar is hidden on this route (see Layout's `sidebarVisible`), so
- * the panel fills the window. "Move to split" still docks settings into the
- * layout as a `settings/<tab>` split.
- *
- * Desktop-only: on mobile this route redirects into the docked-split form.
- */
-export function SettingsRoute() {
- const params = useParams<{ tab?: string }>();
- const { setActiveTabId } = useSettingsState();
-
- const tab = () => settingsSlugToTab(params.tab);
-
- // Route → state: keep the shared panel's active tab in sync with the URL.
- // Known-but-unavailable tabs (gated behind a flag/permission) still set the
- // tab; the panel renders it blank until the gate resolves, which preserves
- // deep links rather than bouncing legitimate users off mid-load.
- createEffect(() => {
- const current = tab();
- if (current) setActiveTabId(current);
- });
-
- // Mobile never shows the full-page route: its exit affordances ("Back to
- // app", "Move to split") all live in desktop-only chrome, so rendering it
- // would trap the user. Bounce into the docked-split form instead — the way
- // settings opens on mobile (see SettingsState.openSettings). Reached by deep
- // links, URLs persisted before mobile went back to split-docked settings,
- // and width changes (e.g. phone rotation) while on the route.
- const MobileSettingsRedirect = () => {
- // Carry the requested tab into the docked panel via the shared signal —
- // the docked form's URL (`component/settings`) doesn't encode it. Set
- // synchronously (not via the effect above) since navigation can unmount
- // this route before effects run.
- const initialTab = tab();
- if (initialTab) setActiveTabId(initialTab);
- return <Navigate href="/component/settings" />;
- };
-
- return (
- <Show when={!isMobile()} fallback={<MobileSettingsRedirect />}>
- <Show when={tab()} fallback={<Navigate href="/settings/account" />}>
- <div class="h-full w-full bg-surface">
- <Layer depth={0}>
- <SettingsPanel variant="fullscreen" />
- </Layer>
- </div>
- </Show>
- </Show>
- );
-}
diff --git a/js/app/packages/app/component/split-layout/components/SplitPanel.tsx b/js/app/packages/app/component/split-layout/components/SplitPanel.tsx
index a656c5bced..db01ef9a25 100644
--- a/js/app/packages/app/component/split-layout/components/SplitPanel.tsx
+++ b/js/app/packages/app/component/split-layout/components/SplitPanel.tsx
@@ -4,6 +4,7 @@ import { SoupContextProvider } from '@app/component/next-soup/soup-context';
import { SoupViewContextProvider } from '@app/component/next-soup/soup-view/soup-view-context';
import { isListViewID, LIST_VIEW_ID } from '@app/constants/list-views';
import { globalSplitManager } from '@app/signal/splitLayout';
+import { isSoloSettings } from '@core/constant/SettingsState';
import { splitContainerAttribute } from '@core/dom-selectors';
import { isMobile } from '@core/mobile/isMobile';
import { getSafeAreaInset } from '@core/mobile/safeAreaInsets';
@@ -142,7 +143,9 @@ export function SplitPanel(props: SplitPanelProps) {
}
const shouldHideSplitHeader = createMemo(
- () => isMobile() && isListViewID(props.handle.content().id)
+ () =>
+ (isMobile() && isListViewID(props.handle.content().id)) ||
+ isSoloSettings()
);
return (
diff --git a/js/app/packages/app/component/split-layout/layout.ts b/js/app/packages/app/component/split-layout/layout.ts
index f326220754..989fca3a37 100644
--- a/js/app/packages/app/component/split-layout/layout.ts
+++ b/js/app/packages/app/component/split-layout/layout.ts
@@ -16,13 +16,13 @@ export function useSplitLayout() {
options?: OpenWithSplitOptions
) {
const splitManager = globalSplitManager();
+ const preferNewSplit = isMobile() ? false : options?.preferNewSplit;
+
if (!splitManager) {
console.error('No split manager found');
return;
}
- const preferNewSplit = isMobile() ? false : options?.preferNewSplit;
-
return splitManager.openWithSplit(content, {
...options,
preferNewSplit,
@@ -33,12 +33,6 @@ export function useSplitLayout() {
content: SplitContent,
referredFrom: ReferredFrom = null
) {
- const splitManager = globalSplitManager();
- if (!splitManager) {
- console.error('No split manager found');
- return;
- }
-
return openWithSplit(content, {
referredFrom,
handle: splitPanelContext?.handle,
@@ -83,6 +77,18 @@ export function useSplitLayout() {
return splitManager.createPopoverSplit({ content: content });
}
+ function replaceAllSplits(
+ content: SplitContent,
+ options?: { referredFrom?: ReferredFrom }
+ ) {
+ const splitManager = globalSplitManager();
+ if (!splitManager) {
+ console.error('No split manager found');
+ return;
+ }
+ return splitManager.replaceAllSplits(content, options);
+ }
+
function resetSplit() {
if (!splitPanelContext) {
console.error('No split panel context found');
@@ -108,5 +114,6 @@ export function useSplitLayout() {
insertSplit,
resetSplit,
popoverSplit,
+ replaceAllSplits,
};
}
diff --git a/js/app/packages/app/component/split-layout/layoutManager.ts b/js/app/packages/app/component/split-layout/layoutManager.ts
index fd0ea2bd06..9a0f4625b5 100644
--- a/js/app/packages/app/component/split-layout/layoutManager.ts
+++ b/js/app/packages/app/component/split-layout/layoutManager.ts
@@ -8,7 +8,6 @@ import type {
import type { ResizeZoneCtx } from '@core/component/Resize/types';
import { isBlockAlias, resolveBlockAlias } from '@core/constant/allBlocks';
import { settingsTabToSlug } from '@core/constant/settingsTabsConfig';
-import { isMobile } from '@core/mobile/isMobile';
import type {
BlockInstanceHandle,
BlockOrchestrator,
@@ -87,21 +86,20 @@ function getAliasOrType(content: SplitContent): string {
}
/**
- * The `type/id` URL pair for a split's content. The docked settings panel is
- * stored internally as the `component/settings` content, but it serializes as
+ * The `type/id` URL pair for a split's content. The settings panel is stored
+ * internally as `component/settings` content, but serializes as
* `settings/<active-tab-slug>` so the URL reflects (and can restore) which
- * settings page is open — matching the full-page `/settings/:tab` route. Reads
- * the active-tab signal, so the URL updates reactively as the tab changes.
+ * settings page is open. Reads the active-tab signal, so the URL updates
+ * reactively as the tab changes. `decodePairs` maps `settings/<tab>` back to
+ * the internal `component/settings` content on the way in.
*
- * On mobile the panel keeps its internal `component/settings` form instead:
- * mobile serializes only the foreground split, and a bare `settings/<tab>`
- * path would be claimed by the full-page `/settings/:tab` route — unmounting
- * the split layout whose back button / swipe-back gesture are the reason
- * settings docks into a split on mobile in the first place.
+ * This applies on mobile too: settings docks as a split there, and now that
+ * settings is no longer a standalone `/settings/:tab` route, `settings/<tab>`
+ * is claimed by the split layout like any other split — so there's no reason
+ * to keep the tab out of the URL.
*/
function contentUrlSegments(content: SplitContent): string[] {
if (content.type === 'component' && content.id === 'settings') {
- if (isMobile()) return ['component', 'settings'];
return ['settings', settingsTabToSlug(activeTabId())];
}
return [getAliasOrType(content), content.id].map(String);
@@ -362,6 +360,9 @@ export type SplitManager = {
/** Close all popover splits */
closeAllPopovers: () => void;
+ /** Splits not excluded by the current exclusion filter, in order. */
+ getVisibleSplits: () => SplitState[];
+
/** Count of splits not excluded by the current exclusion filter. */
getVisibleSplitCount: () => number;
@@ -1362,6 +1363,8 @@ export function createSplitLayout(
return id ? getSplit(id) : undefined;
};
+ const getVisibleSplits = () => state.splits.filter((s) => !isExcluded(s));
+
return {
splits: () => state.splits,
activeSplitId: () => state.activeSplitId,
@@ -1392,8 +1395,8 @@ export function createSplitLayout(
closeAllPopovers,
popovers: () => state.popovers,
canAppendSplit,
- getVisibleSplitCount: () =>
- state.splits.filter((s) => !isExcluded(s)).length,
+ getVisibleSplits,
+ getVisibleSplitCount: () => getVisibleSplits().length,
setExclusionFilter: (fn) => {
exclusionFilter = fn;
},
diff --git a/js/app/packages/core/constant/SettingsState.tsx b/js/app/packages/core/constant/SettingsState.tsx
index a2e68997e1..ce12d3b1fa 100644
--- a/js/app/packages/core/constant/SettingsState.tsx
+++ b/js/app/packages/core/constant/SettingsState.tsx
@@ -9,6 +9,20 @@ import { useLocation, useNavigate } from '@solidjs/router';
import { createMemo, createSignal } from 'solid-js';
import { settingsSlugToTab, settingsTabToSlug } from './settingsTabsConfig';
+/**
+ * Strip the router base from a `location.pathname` (which includes it, e.g.
+ * `/app/settings`) so it can be compared to — and reused with — the
+ * base-relative paths that `navigate()` and route definitions use.
+ */
+const toBaseRelative = (pathname: string) => {
+ if (ROUTER_BASE === '/') return pathname;
+ if (pathname === ROUTER_BASE) return '/';
+ if (pathname.startsWith(`${ROUTER_BASE}/`)) {
+ return pathname.slice(ROUTER_BASE.length);
+ }
+ return pathname;
+};
+
export type SettingsTab =
| 'Account'
| 'Billing'
@@ -33,31 +47,6 @@ export type SettingsTab =
// which case we fall back to DEFAULT_ROUTE.
const [settingsReturnTo, setSettingsReturnTo] = createSignal<string>();
-const SETTINGS_PATH = '/settings';
-
-const settingsPathFor = (tab: SettingsTab) =>
- `${SETTINGS_PATH}/${settingsTabToSlug(tab)}`;
-
-/**
- * Strip the router base from a `location.pathname` (which includes it, e.g.
- * `/app/settings`) so it can be compared to — and reused with — the
- * base-relative paths that `navigate()` and route definitions use.
- */
-const toBaseRelative = (pathname: string) => {
- if (ROUTER_BASE === '/') return pathname;
- if (pathname === ROUTER_BASE) return '/';
- if (pathname.startsWith(`${ROUTER_BASE}/`)) {
- return pathname.slice(ROUTER_BASE.length);
- }
- return pathname;
-};
-
-/** Whether a `location.pathname` (base included) is the settings route. */
-export const isSettingsPath = (pathname: string) => {
- const path = toBaseRelative(pathname);
- return path === SETTINGS_PATH || path.startsWith(`${SETTINGS_PATH}/`);
-};
-
/**
* Drop a settings split from a split-layout path, if present. Handles both the
* URL encoding (`settings/<tab>`) and the legacy internal form
@@ -95,13 +84,32 @@ export const settingsTabFromSplitPath = (
return undefined;
};
+/**
+ * Whether settings is the only visible split — the "clobbered" mode that
+ * looks and behaves like the old fullscreen route (app sidebar hidden,
+ * settings owns its own back/move-to-split affordances). Mobile is excluded:
+ * its swipe layout always reports a visible count of 1 for the active split
+ * (the backgrounded split is excluded from that count), which would
+ * otherwise misidentify every mobile settings-open as "solo".
+ */
+export const isSoloSettings = () => {
+ if (isMobile()) return false;
+ const splitManager = globalSplitManager();
+ if (!splitManager) return false;
+ // Derive the sole split from the visible set (not `splits()[0]`) so the
+ // count check and the identity check agree even if an exclusion filter ever
+ // hides a split ahead of settings.
+ const visible = splitManager.getVisibleSplits();
+ if (visible.length !== 1) return false;
+ const [sole] = visible;
+ return sole?.content.type === 'component' && sole.content.id === 'settings';
+};
+
export const useSettingsState = () => {
- const { openWithSplit } = useSplitLayout();
+ const { openWithSplit, replaceAllSplits } = useSplitLayout();
const navigate = useNavigate();
const location = useLocation();
- const isOnSettingsRoute = () => isSettingsPath(location.pathname);
-
const getSettingsSplit = () => {
const splitManager = globalSplitManager();
if (!splitManager) return undefined;
@@ -113,10 +121,6 @@ export const useSettingsState = () => {
const splitOpen = createMemo(() => getSettingsSplit() !== undefined);
- // Settings are considered open whether shown as the full-page route or docked
- // in a split.
- const isOpen = createMemo(() => isOnSettingsRoute() || splitOpen());
-
const focusSettingsPanel = () => {
if (isTouchDevice()) return;
setTimeout(() => {
@@ -129,32 +133,44 @@ export const useSettingsState = () => {
}, 10);
};
+ // Capture the current layout (minus any settings split) as where "Back to
+ // app"/"Move to split" should return to, then clobber every other split so
+ // settings becomes the sole one. Shared by opening settings fresh and by
+ // collapsing a docked-alongside layout back down to solo.
+ const collapseToSoloSettings = (tab: SettingsTab) => {
+ setSettingsReturnTo(stripSettingsSplit(toBaseRelative(location.pathname)));
+ setActiveTabId(tab);
+ replaceAllSplits({ type: 'component', id: 'settings' });
+ };
+
// Default activation. On mobile, dock settings into the split layout so it
// inherits the split navigation chrome (back button, swipe-back gesture) —
- // the full-page route's exit affordances all live in desktop-only UI. On
- // desktop, navigate to the settings route, remembering where we came from so
- // "Back to app" can return there. Opening without a specific tab always
- // lands on Account rather than the last-viewed page — a fresh open shouldn't
- // resume a prior session's tab.
+ // the solo-settings chrome's exit affordances all live in desktop-only UI.
+ // On desktop, clobber down to a lone settings split, remembering where we
+ // came from so "Back to app" can return there. Opening without a specific
+ // tab always lands on Account rather than the last-viewed page — a fresh
+ // open shouldn't resume a prior session's tab. Re-invoking while settings
+ // is already showing (solo or docked alongside other splits) just switches
+ // the tab rather than re-clobbering the layout.
const openSettings = (tab?: SettingsTab) => {
if (isMobile()) {
openSettingsInSplit(tab ?? 'Account');
return;
}
- if (!isOnSettingsRoute()) {
- setSettingsReturnTo(toBaseRelative(location.pathname));
+ if (splitOpen()) {
+ setActiveTabId(tab ?? 'Account');
+ return;
}
- navigate(settingsPathFor(tab ?? 'Account'));
+ collapseToSoloSettings(tab ?? 'Account');
};
- // Switch the active settings page. On the route this is a URL change (so the
- // page is reflected/shareable); in a split it's just the in-memory signal.
+ // Switch the active settings page. The split's URL segment is derived
+ // reactively from `activeTabId` (see `contentUrlSegments`), so the
+ // layout's bidirectional URL sync reflects this automatically — no
+ // explicit navigation needed, whether settings is solo or docked alongside
+ // other splits.
const selectTab = (tab: SettingsTab) => {
- if (isOnSettingsRoute()) {
- navigate(settingsPathFor(tab), { replace: true });
- } else {
- setActiveTabId(tab);
- }
+ setActiveTabId(tab);
};
// Opt-in: dock settings into the split layout (the pre-route behavior).
@@ -182,16 +198,17 @@ export const useSettingsState = () => {
};
const closeSettings = () => {
- if (isOnSettingsRoute()) {
+ if (isSoloSettings()) {
navigate(settingsReturnTo() ?? DEFAULT_ROUTE, { replace: true });
return;
}
removeSettingsSplit();
};
- // Promote the route into the split layout: rebuild the layout we came from and
- // dock settings into it as a `settings/<tab>` pair. Navigating straight to the
- // composed path avoids racing the split manager's mount.
+ // Dock settings alongside the layout we came from: rebuild that layout and
+ // add settings back as a `settings/<tab>` split. Navigating straight to the
+ // composed path (rather than mutating splits directly) lets the URL→layout
+ // sync rebuild everything in one pass.
const moveSettingsToSplit = (tab?: SettingsTab) => {
if (tab) setActiveTabId(tab);
// Strip any settings split already in the target layout before re-adding
@@ -203,19 +220,18 @@ export const useSettingsState = () => {
navigate(`${base}/settings/${settingsTabToSlug(activeTabId())}`);
};
- // Pop the docked split back out into the full-page route. The return layout is
- // the current path minus the settings split, so "Back to app" lands correctly.
- const moveSettingsToFullscreen = (tab?: SettingsTab) => {
- if (tab) setActiveTabId(tab);
- setSettingsReturnTo(stripSettingsSplit(toBaseRelative(location.pathname)));
- navigate(settingsPathFor(tab ?? activeTabId()));
+ // Collapse a docked-alongside layout back down to a lone settings split.
+ // The return layout is the current path minus the settings split, so "Back
+ // to app" / "Move to split" land correctly.
+ const moveSettingsToSolo = (tab?: SettingsTab) => {
+ collapseToSoloSettings(tab ?? activeTabId());
};
// Focus-aware toggle: bring settings to the user rather than destroying it,
// and only close when settings is what they're actually looking at.
const toggleSettings = () => {
- // Route takes priority: if it's the current page, leave it.
- if (isOnSettingsRoute()) {
+ // Solo takes priority: if it's the only thing showing, leave it.
+ if (isSoloSettings()) {
closeSettings();
return;
}
@@ -234,19 +250,18 @@ export const useSettingsState = () => {
return;
}
- // Nothing open → open settings (route on desktop, docked split on mobile).
+ // Nothing open → open settings (solo split on desktop, docked on mobile).
openSettings();
};
return {
- settingsOpen: isOpen,
- settingsSplitOpen: splitOpen,
+ settingsOpen: splitOpen,
openSettings,
openSettingsInSplit,
selectTab,
closeSettings,
moveSettingsToSplit,
- moveSettingsToFullscreen,
+ moveSettingsToSolo,
activeTabId,
setActiveTabId,
toggleSettings,