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.

feat(new-layout): new channels view (#6146)

dev-rbd44e884eaa79
diff --git a/apps/web/src/components/app/PreviewPanel.tsx b/apps/web/src/components/app/PreviewPanel.tsx
index df73b93f9b..ece59a9b65 100644
--- a/apps/web/src/components/app/PreviewPanel.tsx
+++ b/apps/web/src/components/app/PreviewPanel.tsx
@@ -34,6 +34,10 @@ import {
} from 'solid-js';
import { Dynamic } from 'solid-js/web';
import { match, P } from 'ts-pattern';
+import {
+ createPriorityCollapseController,
+ PriorityCollapseOverflowSensor,
+} from './split-layout/components/PriorityCollapseOverflowSensor';
import {
SplitPanelContext,
type SplitPanelContextType,
@@ -66,6 +70,8 @@ function PreviewPanelContent(
props: PreviewPanelProps & { selectedEntity: EntityData }
) {
const scopedLayoutRefs: SplitPanelContextType['layoutRefs'] = {};
+ const headerCollapseController = createPriorityCollapseController();
+ const toolbarCollapseController = createPriorityCollapseController();
const [interactedWith, setInteractedWith] = createSignal(false);
const [attachHotkeys, previewHotkeyScope] =
useHotkeyDOMScope('preview-panel');
@@ -201,25 +207,36 @@ function PreviewPanelContent(
onPointerDown={() => setInteractedWith(true)}
tabIndex={-1}
>
- <div class="relative flex min-h-10 w-full shrink-0 items-center justify-between bg-surface px-2">
- <div
- class="flex h-full items-center gap-1"
- ref={(ref) => {
- scopedLayoutRefs.headerLeft = ref;
+ <div
+ ref={headerCollapseController.setRow}
+ class="relative flex min-h-10 w-full shrink-0 items-center justify-between bg-surface px-2"
+ >
+ <PriorityCollapseOverflowSensor
+ controller={headerCollapseController}
+ truncateAsLastResort
+ class="relative h-full min-w-0 shrink overflow-hidden"
+ contentClass="flex h-full items-center gap-1"
+ contentRef={(element) => {
+ scopedLayoutRefs.headerLeft = element;
}}
/>
<div
- class="flex h-full items-center gap-1"
+ class="flex h-full grow shrink items-center justify-end gap-1"
ref={(ref) => {
scopedLayoutRefs.headerRight = ref;
}}
/>
</div>
- <div class="relative flex min-h-0 w-full shrink-0 items-center justify-between bg-surface px-2">
- <div
- class="flex h-full items-center gap-1"
- ref={(ref) => {
- scopedLayoutRefs.toolbarLeft = ref;
+ <div
+ ref={toolbarCollapseController.setRow}
+ class="relative flex min-h-0 w-full shrink-0 items-center justify-between bg-surface px-2"
+ >
+ <PriorityCollapseOverflowSensor
+ controller={toolbarCollapseController}
+ class="min-w-0 flex-1 overflow-hidden"
+ contentClass="flex items-center gap-1"
+ contentRef={(element) => {
+ scopedLayoutRefs.toolbarLeft = element;
}}
/>
<div
@@ -236,6 +253,8 @@ function PreviewPanelContent(
splitHotkeyScope: previewHotkeyScope,
isInlinePreview: true,
layoutRefs: scopedLayoutRefs,
+ headerCollapser: headerCollapseController.collapser,
+ toolbarCollapser: toolbarCollapseController.collapser,
}}
>
<PreviewPanelContext
diff --git a/apps/web/src/components/app/split-layout/componentRegistry.tsx b/apps/web/src/components/app/split-layout/componentRegistry.tsx
index 768889dc7f..17ff2f9cc9 100644
--- a/apps/web/src/components/app/split-layout/componentRegistry.tsx
+++ b/apps/web/src/components/app/split-layout/componentRegistry.tsx
@@ -1,6 +1,7 @@
import { useActivityFeedFlag } from '@app/features/activity/use-activity-feed-flag';
import type { EventEditorInitialValues } from '@app/features/calendar/components/composer/event-form-model';
import type { CalendarEvent } from '@app/features/calendar/types';
+import { ChannelsView } from '@app/features/channels-view/channels-view';
import { GettingStarted } from '@app/features/getting-started';
import { Home } from '@app/features/home';
import { InboxView } from '@app/features/inbox-view/inbox-view';
@@ -38,6 +39,7 @@ import {
LOCAL_ONLY,
} from '@core/constant/featureFlags';
import { useUserContext } from '@core/context/user';
+import { isTouchDevice } from '@core/mobile/isTouchDevice';
import type { ViewId } from '@core/types/view';
import EmptyStatePreviewIcon from '@design/empty-state-doc.svg';
import { useAutomationEntities } from '@queries/agent-schedule/entities';
@@ -47,8 +49,10 @@ import {
createRenderEffect,
type JSXElement,
lazy,
+ Match,
onMount,
Show,
+ Switch,
} from 'solid-js';
import type { SplitContent } from './layoutManager';
import { useSplitPanelOrThrow } from './layoutUtils';
@@ -441,21 +445,47 @@ registerComponent(
})
);
-registerComponent(
- 'channels',
- withAuth(() => {
- usePageViewTracking('channels');
- const preset = getViewPreset('channels');
- return (
- <SoupView
- viewName="Channels"
- initialFilters={preset?.filters}
- initialClientFilters={preset?.clientFilters}
- initialGroupBy={preset?.groupBy}
- />
- );
- })
-);
+function LegacyChannelsView() {
+ const preset = getViewPreset('channels');
+
+ return (
+ <SoupView
+ viewName="Channels"
+ initialFilters={preset?.filters}
+ initialClientFilters={preset?.clientFilters}
+ initialGroupBy={preset?.groupBy}
+ />
+ );
+}
+
+function FeatureGatedChannelsView() {
+ const newAppViews = useNewAppViews();
+
+ return (
+ <Show when={newAppViews.ready()} fallback={<LoadingBlock />}>
+ <Show when={newAppViews.enabled()} fallback={<LegacyChannelsView />}>
+ <ChannelsView />
+ </Show>
+ </Show>
+ );
+}
+
+function RegisteredChannelsView() {
+ usePageViewTracking('channels');
+
+ return (
+ <Switch>
+ <Match when={isTouchDevice()}>
+ <LegacyChannelsView />
+ </Match>
+ <Match when={!isTouchDevice()}>
+ <FeatureGatedChannelsView />
+ </Match>
+ </Switch>
+ );
+}
+
+registerComponent('channels', withAuth(RegisteredChannelsView));
registerComponent(
'calls',
diff --git a/apps/web/src/components/app/split-layout/components/PreviewButton.tsx b/apps/web/src/components/app/split-layout/components/PreviewButton.tsx
index 35b4c3077a..512e74ecc9 100644
--- a/apps/web/src/components/app/split-layout/components/PreviewButton.tsx
+++ b/apps/web/src/components/app/split-layout/components/PreviewButton.tsx
@@ -1,11 +1,10 @@
import { useAnalytics } from '@app/lib/analytics/analytics-context';
-import { registerHotkey } from '@core/hotkey/hotkeys';
import { TOKENS } from '@core/hotkey/tokens';
import EyeIcon from '@phosphor-icons/core/regular/eye.svg?component-solid';
import EyeSlashIcon from '@phosphor-icons/core/regular/eye-slash.svg?component-solid';
-import { Button, Tooltip } from '@ui';
+import { Button, cn, Tooltip } from '@ui';
import { Show } from 'solid-js';
-import { useSplitPanelOrThrow } from '../layoutUtils';
+import { usePreviewToggle } from '../usePreviewToggle';
/** Toggle Preview mode for eligible Controller content outside a Viewer. */
export function PreviewButton(
@@ -15,64 +14,48 @@ export function PreviewButton(
onEngage?: () => void;
onOpenChange?: (open: boolean) => void;
hideLabel?: boolean;
+ iconOnly?: boolean;
+ class?: string;
+ registerHotkey?: boolean;
} = {}
) {
- const panel = useSplitPanelOrThrow();
const analytics = useAnalytics();
- const isViewer = () => panel.handle.isViewerSplit();
- const isController = () => panel.handle.isControllerSplit();
- const canEngage = () => !props.disabled && panel.handle.canEngagePreview();
+ const preview = usePreviewToggle({
+ disabled: () => props.disabled ?? false,
+ onEngage: () => {
+ analytics.track('preview_panel_use');
+ props.onEngage?.();
+ },
+ onOpenChange: props.onOpenChange,
+ registerHotkey: props.registerHotkey ?? true,
+ });
+
const unavailableLabel = () =>
props.disabled
? (props.disabledLabel ?? 'Preview unavailable')
: 'No space for preview';
- const togglePreview = () => {
- if (isController()) {
- panel.handle.disengagePreview();
- props.onOpenChange?.(false);
- return;
- }
- if (!canEngage()) return;
-
- analytics.track('preview_panel_use');
- panel.handle.engagePreview();
- if (panel.handle.isControllerSplit()) {
- props.onOpenChange?.(true);
- props.onEngage?.();
- }
- };
-
- registerHotkey({
- hotkeyToken: TOKENS.unifiedList.togglePreview,
- scopeId: panel.splitHotkeyScope,
- description: 'Toggle preview',
- condition: () => !isViewer() && canEngage(),
- keyDownHandler: () => {
- togglePreview();
- return true;
- },
- hotkey: 'space',
- });
-
return (
- <Show when={!isViewer()}>
+ <Show when={!preview.isViewer()}>
<Tooltip
- hotkey={canEngage() ? TOKENS.unifiedList.togglePreview : undefined}
- label={canEngage() ? 'Preview' : unavailableLabel()}
+ hotkey={
+ preview.canToggle() ? TOKENS.unifiedList.togglePreview : undefined
+ }
+ label={preview.canToggle() ? 'Preview' : unavailableLabel()}
>
<Button
- onClick={togglePreview}
+ onClick={preview.toggle}
variant="outline"
- size="sm"
+ size={props.iconOnly ? 'md' : 'sm'}
+ square={props.iconOnly}
depth={2}
- class="bg-surface"
- disabled={!canEngage()}
- aria-label={props.hideLabel ? 'Preview' : undefined}
+ class={cn('bg-surface', props.class)}
+ disabled={!preview.canToggle()}
+ aria-label={props.hideLabel || props.iconOnly ? 'Preview' : undefined}
>
- {isController() ? <EyeSlashIcon /> : <EyeIcon />}
- <Show when={!props.hideLabel}>
+ {preview.isOpen() ? <EyeSlashIcon /> : <EyeIcon />}
+ <Show when={!props.hideLabel && !props.iconOnly}>
<span>Preview</span>
</Show>
</Button>
diff --git a/apps/web/src/components/app/split-layout/entry-persistence.ts b/apps/web/src/components/app/split-layout/entry-persistence.ts
index 824bc60f43..5ceef38e66 100644
--- a/apps/web/src/components/app/split-layout/entry-persistence.ts
+++ b/apps/web/src/components/app/split-layout/entry-persistence.ts
@@ -19,16 +19,16 @@ export type CreateEntryPersistenceStorageOptions<TState, TStored> = {
* TODO: Replace the split layout's captor pattern with direct entry-state
* persistence.
*
- * Writes update a deferred capture value. The split manager commits that
- * value to the current history entry immediately before navigation.
+ * The split manager reads the latest canonical value and commits its selected
+ * projection to the current history entry immediately before navigation.
*/
export function createEntryPersistenceStorage<TState, TStored>(
options: CreateEntryPersistenceStorageOptions<TState, TStored>
): PersistenceStorage<TState> {
let captured: TStored | undefined;
- const dispose = options.handle.registerEntryStateCaptor(
- options.key,
- () => captured
+ let readCurrent: (() => TState) | undefined;
+ const dispose = options.handle.registerEntryStateCaptor(options.key, () =>
+ readCurrent ? options.select(readCurrent()) : captured
);
const update = (state: TState) => {
captured = options.select(state);
@@ -41,7 +41,10 @@ export function createEntryPersistenceStorage<TState, TStored>(
? undefined
: options.restore(current, stored);
},
- initialize: update,
+ initialize: (state, read) => {
+ update(state);
+ readCurrent = read;
+ },
write: update,
dispose,
};
diff --git a/apps/web/src/components/app/split-layout/usePreviewToggle.ts b/apps/web/src/components/app/split-layout/usePreviewToggle.ts
new file mode 100644
index 0000000000..fc0a9ef385
--- /dev/null
+++ b/apps/web/src/components/app/split-layout/usePreviewToggle.ts
@@ -0,0 +1,58 @@
+import { registerHotkey } from '@core/hotkey/hotkeys';
+import { TOKENS } from '@core/hotkey/tokens';
+import type { Accessor } from 'solid-js';
+import { useSplitPanelOrThrow } from './layoutUtils';
+
+export type UsePreviewToggleOptions = {
+ disabled?: Accessor<boolean>;
+ onEngage?: VoidFunction;
+ onOpenChange?: (open: boolean) => void;
+ registerHotkey?: boolean;
+};
+
+export function usePreviewToggle(options: UsePreviewToggleOptions = {}) {
+ const panel = useSplitPanelOrThrow();
+ const isViewer = () => panel.handle.isViewerSplit();
+ const isOpen = () => panel.handle.isControllerSplit();
+ const canEngage = () =>
+ !(options.disabled?.() ?? false) && panel.handle.canEngagePreview();
+ const canToggle = () => isOpen() || canEngage();
+
+ const toggle = () => {
+ if (isViewer()) return false;
+
+ if (isOpen()) {
+ panel.handle.disengagePreview();
+ options.onOpenChange?.(false);
+ return true;
+ }
+
+ if (!canEngage()) return false;
+
+ panel.handle.engagePreview();
+ if (!panel.handle.isControllerSplit()) return false;
+
+ options.onOpenChange?.(true);
+ options.onEngage?.();
+ return true;
+ };
+
+ if (options.registerHotkey) {
+ registerHotkey({
+ hotkeyToken: TOKENS.unifiedList.togglePreview,
+ scopeId: panel.splitHotkeyScope,
+ description: 'Toggle preview',
+ condition: () => !isViewer() && canToggle(),
+ keyDownHandler: toggle,
+ hotkey: 'space',
+ });
+ }
+
+ return {
+ canEngage,
+ canToggle,
+ isOpen,
+ isViewer,
+ toggle,
+ };
+}
diff --git a/apps/web/src/components/view-shell/ListDropdowns.tsx b/apps/web/src/components/view-shell/ListDropdowns.tsx
index f1dd72ba5a..38ab0a25d7 100644
--- a/apps/web/src/components/view-shell/ListDropdowns.tsx
+++ b/apps/web/src/components/view-shell/ListDropdowns.tsx
@@ -186,7 +186,7 @@ export function ListFilterDropdown<
</Dropdown.SubTrigger>
<Dropdown.SubContent
class={cn(
- 'max-h-72 min-w-24 max-w-[90vw] overflow-y-auto',
+ 'max-h-72 min-w-24 max-w-[min(16rem,calc(100vw-1rem))] overflow-y-auto',
group.contentClass
)}
>
diff --git a/apps/web/src/components/view-shell/ViewShell.tsx b/apps/web/src/components/view-shell/ViewShell.tsx
index 8499a7c150..873baea106 100644
--- a/apps/web/src/components/view-shell/ViewShell.tsx
+++ b/apps/web/src/components/view-shell/ViewShell.tsx
@@ -278,6 +278,7 @@ function Aside(props: JSX.HTMLAttributes<HTMLDivElement>) {
index={0}
minSize={ws.aside.layout().min}
maxSize={ws.aside.layout().max}
+ redistributionPreferredSize={ws.aside.layout().width}
target={{ kind: 'px', px: ws.aside.layout().width }}
collapsed={() => ws.aside.isCollapsed()}
>
diff --git a/apps/web/src/features/channels-view/channels-view-context.tsx b/apps/web/src/features/channels-view/channels-view-context.tsx
new file mode 100644
index 0000000000..3b8c986fce
--- /dev/null
+++ b/apps/web/src/features/channels-view/channels-view-context.tsx
@@ -0,0 +1,58 @@
+import { makePersistedState } from '@app/lib/persistence';
+import { useSplitPanelOrThrow } from '@components/app/split-layout/layoutUtils';
+import { createAssertedContextProvider } from '@core/context/createContext';
+import { useUserId } from '@core/context/user';
+import type { ContextProviderProps } from '@solid-primitives/context';
+import { createStore, type Store } from 'solid-js/store';
+import { createChannelsViewPersistence } from './persistence';
+import type {
+ ChannelsGroup,
+ ChannelsTab,
+ ChannelsViewState,
+ ChannelsViewStateOptions,
+} from './types';
+
+type ChannelsViewProviderProps = ContextProviderProps & {
+ initialState?: ChannelsViewStateOptions;
+};
+
+export type ChannelsViewContext = {
+ state: Store<ChannelsViewState>;
+ setTab: (tab: ChannelsTab) => void;
+ setSelectedChannelId: (channelId: string | undefined) => void;
+ setGroupOpen: (group: ChannelsGroup, open: boolean) => void;
+};
+
+export const [ChannelsViewProvider, useChannelsView] =
+ createAssertedContextProvider<ChannelsViewContext, ChannelsViewProviderProps>(
+ 'ChannelsView',
+ (props) => {
+ const panel = useSplitPanelOrThrow();
+ const userId = useUserId();
+ const initial = props.initialState ?? {};
+ const [state, setState] = makePersistedState(
+ createStore<ChannelsViewState>({
+ tab: initial.tab ?? 'browse',
+ selectedChannelId: initial.selectedChannelId,
+ expandedGroups: {
+ channels: initial.expandedGroups?.channels ?? true,
+ direct_messages: initial.expandedGroups?.direct_messages ?? true,
+ },
+ }),
+ createChannelsViewPersistence({
+ handle: panel.handle,
+ userId,
+ restoreEntryState: props.initialState === undefined,
+ restoreLocalState: props.initialState === undefined,
+ })
+ );
+
+ return {
+ state,
+ setTab: (tab) => setState('tab', tab),
+ setSelectedChannelId: (channelId) =>
+ setState('selectedChannelId', channelId),
+ setGroupOpen: (group, open) => setState('expandedGroups', group, open),
+ };
+ }
+ );
diff --git a/apps/web/src/features/channels-view/channels-view.tsx b/apps/web/src/features/channels-view/channels-view.tsx
new file mode 100644
index 0000000000..2939abd491
--- /dev/null
+++ b/apps/web/src/features/channels-view/channels-view.tsx
@@ -0,0 +1,144 @@
+import { ViewShell } from '@app/components/view-shell';
+import {
+ compileToAst,
+ defineQueryFilters,
+ queryStateFrom,
+} from '@app/features/next-soup/filters/filter-store';
+import { createSizeBreakpoints } from '@app/util/create-size-breakpoints';
+import { useGlobalBlockOrchestrator } from '@components/app/GlobalAppState';
+import { PreviewPanel } from '@components/app/PreviewPanel';
+import { useSplitPanelOrThrow } from '@components/app/split-layout/layoutUtils';
+import { SplitPanel } from '@components/app/split-panel';
+import { StaticMarkdownContext } from '@core/component/LexicalMarkdown/component/core/StaticMarkdown';
+import { isChannelEntity, ListEntityMetadataQueryProvider } from '@entity';
+import { useSoupAstItemsQuery } from '@queries/soup/items';
+import { createElementSize } from '@solid-primitives/resize-observer';
+import { createMemo, createSignal, onMount, Show, Suspense } from 'solid-js';
+import { ChannelsViewProvider, useChannelsView } from './channels-view-context';
+import { ChannelsRail } from './components/ChannelsRail';
+import type { ChannelsViewStateOptions } from './types';
+
+const SIDEBAR_CHANNEL_LIMIT = 100;
+const NARROW_RAIL_WIDTH = 64;
+const DEFAULT_RAIL_WIDTH = 360;
+const MIN_RAIL_WIDTH = 224;
+const MAX_RAIL_WIDTH = 420;
+
+export type ChannelsViewProps = {
+ /** Explicit navigation state. When present, it wins over entry restoration. */
+ initialState?: ChannelsViewStateOptions;
+};
+
+function ChannelsViewRoot() {
+ const panel = useSplitPanelOrThrow();
+ const orchestrator = useGlobalBlockOrchestrator();
+ const { state } = useChannelsView();
+ const [workspace, setWorkspace] = createSignal<HTMLDivElement>();
+ const workspaceSize = createElementSize(workspace);
+ const breakpoints = createSizeBreakpoints(
+ () => workspaceSize.width ?? undefined,
+ { narrow: 720 }
+ );
+ const railMode = () => (breakpoints.narrow() ? 'slim' : 'full');
+ const railLayout = () =>
+ railMode() === 'slim'
+ ? {
+ width: NARROW_RAIL_WIDTH,
+ min: NARROW_RAIL_WIDTH,
+ max: NARROW_RAIL_WIDTH,
+ }
+ : {
+ width: DEFAULT_RAIL_WIDTH,
+ min: MIN_RAIL_WIDTH,
+ max: MAX_RAIL_WIDTH,
+ };
+
+ const channelsQuery = useSoupAstItemsQuery(
+ () => ({
+ params: {
+ limit: SIDEBAR_CHANNEL_LIMIT,
+ sort_method: 'updated_at',
+ },
+ body: compileToAst(
+ queryStateFrom(
+ defineQueryFilters({
+ include: {
+ channelImportance: true,
+ channelIsParticipant: [true],
+ },
+ })
+ )
+ ),
+ }),
+ () => ({ staleTime: 30_000 })
+ );
+ const channels = createMemo(() =>
+ (channelsQuery.data?.entities ?? []).filter(isChannelEntity)
+ );
+ const selectedChannel = createMemo(() =>
+ channels().find((channel) => channel.id === state.selectedChannelId)
+ );
+
+ onMount(() => panel.handle.setDisplayName('Channels'));
+
+ return (
+ <ListEntityMetadataQueryProvider>
+ <StaticMarkdownContext>
+ <SplitPanel.Root>
+ <SplitPanel.Body>
+ <div ref={setWorkspace} class="size-full min-h-0 bg-panel">
+ <ViewShell.Root
+ aside={railLayout()}
+ breakpoints={{ collapsed: 0 }}
+ layoutBreakpoint="collapsed"
+ main={{ min: 224 }}
+ resizable={railMode() === 'full'}
+ >
+ <ViewShell.Aside>
+ <ChannelsRail channels={channels()} mode={railMode()} />
+ </ViewShell.Aside>
+ <ViewShell.Main class="overflow-hidden">
+ <Show
+ when={selectedChannel()}
+ fallback={
+ <div class="flex size-full items-center justify-center px-6 text-center">
+ <div class="flex max-w-sm flex-col gap-2">
+ <h2 class="text-base font-semibold text-ink">
+ Select a conversation
+ </h2>
+ <p class="text-sm leading-5 text-ink-muted">
+ Choose a channel or person from the sidebar to open
+ the conversation here.
+ </p>
+ </div>
+ </div>
+ }
+ >
+ {(channel) => (
+ <Suspense>
+ <PreviewPanel
+ selectedEntity={channel()}
+ orchestrator={orchestrator}
+ splitPanelContext={panel}
+ />
+ </Suspense>
+ )}
+ </Show>
+ </ViewShell.Main>
+ </ViewShell.Root>
+ </div>
+ </SplitPanel.Body>
+ </SplitPanel.Root>
+ </StaticMarkdownContext>
+ </ListEntityMetadataQueryProvider>
+ );
+}
+
+/** Channels workspace matching the V2 Chat rail experiment. */
+export function ChannelsView(props: ChannelsViewProps) {
+ return (
+ <ChannelsViewProvider initialState={props.initialState}>
+ <ChannelsViewRoot />
+ </ChannelsViewProvider>
+ );
+}
diff --git a/apps/web/src/features/channels-view/components/ChannelRailItems.tsx b/apps/web/src/features/channels-view/components/ChannelRailItems.tsx
new file mode 100644
index 0000000000..8194215818
--- /dev/null
+++ b/apps/web/src/features/channels-view/components/ChannelRailItems.tsx
@@ -0,0 +1,305 @@
+import { StaticMarkdown } from '@core/component/LexicalMarkdown/component/core/StaticMarkdown';
+import { useUserId } from '@core/context/user';
+import { getDisplayName, tryMacroId } from '@core/user';
+import type { MacroId } from '@core/user/macroId';
+import { type ChannelEntity, Entity } from '@entity';
+import ReplyIcon from '@phosphor/arrow-bend-up-left.svg';
+import AtIcon from '@phosphor/at.svg';
+import { cn, Tooltip } from '@ui';
+import { Show } from 'solid-js';
+import { channelInitials, formatDetailedTimestamp } from '../utils';
+
+function ChannelAvatar(props: { channel: ChannelEntity; size?: 'sm' | 'md' }) {
+ const sizeClass = () =>
+ props.size === 'md' ? 'size-9 [&_svg]:size-4.5' : 'size-6 [&_svg]:size-3.5';
+
+ return (
+ <Show
+ when={props.channel.channelType === 'direct_message'}
+ fallback={
+ <span
+ class={cn(
+ 'flex shrink-0 items-center justify-center text-ink-muted [&_svg]:shrink-0',
+ sizeClass()
+ )}
+ >
+ <Entity.Icon
+ entity={props.channel}
+ suppressClick
+ showTooltip={false}
+ />
+ </span>
+ }
+ >
+ <span
+ class={cn(
+ 'relative flex shrink-0 items-center justify-center overflow-hidden rounded-full border border-edge bg-lift [&_img]:size-full [&_svg]:shrink-0',
+ sizeClass()
+ )}
+ >
+ <Entity.Icon entity={props.channel} suppressClick showTooltip={false} />
+ </span>
+ </Show>
+ );
+}
+
+function SlimChannelAvatar(props: { channel: ChannelEntity }) {
+ return (
+ <Show
+ when={props.channel.channelType === 'direct_message'}
+ fallback={
+ <span class="flex size-6 shrink-0 items-center justify-center rounded-full border border-edge bg-lift text-xxs font-semibold tracking-wide text-ink">
+ {channelInitials(props.channel.name)}
+ </span>
+ }
+ >
+ <span class="relative flex size-6 shrink-0 items-center justify-center overflow-hidden rounded-full border border-edge bg-lift [&_img]:size-full [&_svg]:size-3.5 [&_svg]:shrink-0">
+ <Entity.Icon entity={props.channel} suppressClick showTooltip={false} />
+ </span>
+ </Show>
+ );
+}
+
+type ChannelOptionProps = {
+ id: string;
+ channel: ChannelEntity;
+ unread: boolean;
+ selected: boolean;
+ focused: boolean;
+ onActivate: () => void;
+};
+
+export function ChannelOption(props: ChannelOptionProps) {
+ return (
+ <button
+ id={props.id}
+ type="button"
+ role="treeitem"
+ tabIndex={-1}
+ class={cn(
+ 'relative flex w-full min-w-0 items-center gap-2 rounded-xl px-2 text-left outline-none transition-colors focus-visible:ring-2 focus-visible:ring-accent',
+ props.channel.channelType === 'direct_message'
+ ? 'min-h-10 py-2'
+ : 'h-8',
+ props.selected && 'bg-active text-ink',
+ !props.selected && props.focused && 'bg-hover text-ink',
+ !props.selected &&
+ !props.focused &&
+ 'text-ink-muted hover:bg-hover hover:text-ink'
+ )}
+ aria-current={props.selected ? 'page' : undefined}
+ onClick={props.onActivate}
+ >
+ <ChannelAvatar channel={props.channel} />
+ <span class="min-w-0 flex-1 truncate text-sm font-medium">
+ {props.channel.name}
+ </span>
+ <Show when={props.unread}>
+ <span
+ aria-label="Unread"
+ class="size-2 shrink-0 rounded-full bg-accent"
+ />
+ </Show>
+ </button>
+ );
+}
+
+export function SlimChannelOption(props: ChannelOptionProps) {
+ return (
+ <Tooltip label={props.channel.name} placement="right" class="size-10">
+ <button
+ id={props.id}
+ type="button"
+ role="treeitem"
+ tabIndex={-1}
+ class={cn(
+ 'relative flex size-10 min-h-10 items-center justify-center rounded-full text-left outline-none transition-colors focus-visible:ring-2 focus-visible:ring-accent',
+ props.selected && 'bg-active text-ink',
+ !props.selected && props.focused && 'bg-hover text-ink',
+ !props.selected &&
+ !props.focused &&
+ 'text-ink-muted hover:bg-hover hover:text-ink'
+ )}
+ aria-current={props.selected ? 'page' : undefined}
+ onClick={props.onActivate}
+ >
+ <SlimChannelAvatar channel={props.channel} />
+ <Show when={props.unread}>
+ <span
+ aria-label="Unread"
+ class="absolute right-1.5 top-1 size-2 rounded-full bg-accent"
+ />
+ </Show>
+ </button>
+ </Tooltip>
+ );
+}
+
+type ConversationCardProps = {
+ id: string;
+ channel: ChannelEntity;
+ senderId?: string;
+ mentionedCurrentUser: boolean;
+ unread: boolean;
+ selected: boolean;
+ focused: boolean;
+ onActivate: () => void;
+};
+
+function UserDisplayName(props: { id: MacroId }) {
+ const displayName = () =>
+ getDisplayName(props.id, {
+ emailFallback: 'local-part',
+ });
+
+ return <>{displayName()}</>;
+}
+
+function MessageSenderName(props: { id?: string }) {
+ const currentUserId = useUserId();
+ const macroId = () => (props.id ? tryMacroId(props.id) : undefined);
+ const isCurrentUser = () =>
+ props.id?.toLocaleLowerCase() === currentUserId()?.toLocaleLowerCase();
+
+ return (
+ <Show when={props.id} fallback={<>Unknown sender</>}>
+ {(senderId) => (
+ <Show when={!isCurrentUser()} fallback={<>You</>}>
+ <Show
+ when={macroId()}
+ fallback={senderId().startsWith('bot|') ? 'Bot' : 'Someone'}
+ >
+ {(id) => <UserDisplayName id={id()} />}
+ </Show>
+ </Show>
+ )}
+ </Show>
+ );
+}
+
+export function ConversationCard(props: ConversationCardProps) {
+ const latestRootMessage = () => props.channel.latestRootMessage;
+
+ return (
+ <div
+ id={props.id}
+ role="treeitem"
+ tabIndex={-1}
+ class={cn(
+ 'w-full min-w-0 overflow-hidden px-2 py-3 text-left outline-none transition-colors focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-accent',
+ props.selected && 'bg-active',
+ !props.selected && props.focused && 'bg-hover',
+ !props.selected && !props.focused && 'bg-transparent hover:bg-hover'
+ )}
+ aria-current={props.selected ? 'page' : undefined}
+ onClick={props.onActivate}
+ >
+ <div class="flex min-w-0 items-start gap-3 overflow-hidden">
+ <ChannelAvatar channel={props.channel} size="md" />
+ <div class="min-w-0 flex-1 overflow-hidden">
+ <span class="flex min-w-0 items-center gap-2">
+ <span class="min-w-0 flex-1 truncate text-sm font-medium text-ink">
+ {props.channel.name}
+ </span>
+ <Show when={props.unread}>
+ <span
+ aria-label="Unread"
+ class="size-2 shrink-0 rounded-full bg-accent"
+ />
+ </Show>
+ <Show when={latestRootMessage()?.createdAt}>
+ {(createdAt) => (
+ <Tooltip
+ label={formatDetailedTimestamp(createdAt())}
+ placement="top"
+ >
+ <span class="shrink-0 text-xxs text-ink-extra-muted">
+ <Entity.Timestamp
+ entity={props.channel}
+ overrideTimeStamp={createdAt()}
+ />
+ </span>
+ </Tooltip>
+ )}
+ </Show>
+ </span>
+ <Show
+ when={latestRootMessage()?.threadId || props.mentionedCurrentUser}
+ >
+ <span class="flex min-w-0 items-center gap-2 text-xxs leading-4 text-ink-extra-muted">
+ <Show when={latestRootMessage()?.threadId}>
+ <span
+ class="flex shrink-0 items-center gap-1"
+ title="Reply in thread"
+ >
+ <ReplyIcon class="size-3" />
+ <span>Reply</span>
+ </span>
+ </Show>
+ <Show when={props.mentionedCurrentUser}>
+ <span class="flex shrink-0 items-center gap-1 text-accent">
+ <AtIcon class="size-3" />
+ <span>Mentioned you</span>
+ </span>
+ </Show>
+ </span>
+ </Show>
+ <div class="flex min-w-0 items-center gap-1 overflow-hidden whitespace-nowrap text-xs leading-4">
+ <span class="shrink-0 font-medium text-ink-muted">
+ <MessageSenderName id={props.senderId} />:
+ </span>
+ <Show
+ when={latestRootMessage()?.content.trim()}
+ fallback={
+ <span class="min-w-0 flex-1 text-ink-extra-muted">
+ No messages yet
+ </span>
+ }
+ >
+ {(content) => (
+ <div class="min-w-0 flex-1 truncate text-ink-muted [&_*]:my-0 [&_*]:truncate">
+ <StaticMarkdown markdown={content()} singleLine />
+ </div>
+ )}
+ </Show>
+ </div>
+ </div>
+ </div>
+ </div>
+ );
+}
+
+export function SlimConversationCard(props: ConversationCardProps) {
+ return (
+ <Tooltip
+ label={props.channel.name}
+ placement="right"
+ class="size-10 self-center"
+ >
+ <button
+ id={props.id}
+ type="button"
+ role="treeitem"
+ tabIndex={-1}
+ class={cn(
+ 'flex size-10 items-center justify-center rounded-full outline-none transition-colors focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-accent',
+ props.selected && 'bg-active',
+ !props.selected && props.focused && 'bg-hover',
+ !props.selected && !props.focused && 'bg-transparent hover:bg-hover'
+ )}
+ aria-current={props.selected ? 'page' : undefined}
+ onClick={props.onActivate}
+ >
+ <span class="relative">
+ <SlimChannelAvatar channel={props.channel} />
+ <Show when={props.unread}>
+ <span
+ aria-label="Unread"
+ class="absolute -right-0.5 -top-0.5 size-2 rounded-full bg-accent ring-2 ring-surface"
+ />
+ </Show>
+ </span>
+ </button>
+ </Tooltip>
+ );
+}
diff --git a/apps/web/src/features/channels-view/components/ChannelsRail.tsx b/apps/web/src/features/channels-view/components/ChannelsRail.tsx
new file mode 100644
index 0000000000..4a50f97fdf
--- /dev/null
+++ b/apps/web/src/features/channels-view/components/ChannelsRail.tsx
@@ -0,0 +1,846 @@
+import {
+ createListController,
+ type ListScrollHandle,
+ listOwnedSlotName,
+ useListInteractions,
+} from '@app/components/list';
+import { useViewTabHotkeys } from '@app/components/view-shell';
+import { CommandState } from '@app/features/command';
+import { openNewChannelModal } from '@channel/CreateChannelModal';
+import { useGlobalNotificationSource } from '@components/app/GlobalAppState';
+import {
+ useSplitPanelOrThrow,
+ withSplitPanelOwner,
+} from '@components/app/split-layout/layoutUtils';
+import { SplitPanel } from '@components/app/split-panel';
+import { useUserId } from '@core/context/user';
+import { createHotkeyGroup, registerHotkey } from '@core/hotkey/hotkeys';
+import { compareDateDesc } from '@core/util/date';
+import type { ChannelEntity } from '@entity';
+import { notificationIsRead } from '@entity/utils/notification';
+import ChannelIcon from '@icon/wide-channel.svg';
+import CaretDownIcon from '@phosphor/caret-down.svg';
+import ChatTeardropIcon from '@phosphor/chat-teardrop.svg';
+import ChatTextIcon from '@phosphor/chat-text.svg';
+import ChatsIcon from '@phosphor/chats-circle.svg';
+import { Key } from '@solid-primitives/keyed';
+import { cn, Tabs } from '@ui';
+import {
+ createEffect,
+ createMemo,
+ createUniqueId,
+ Match,
+ on,
+ onCleanup,
+ Show,
+ Switch,
+} from 'solid-js';
+import { useChannelsView } from '../channels-view-context';
+import type { ChannelsGroup, ChannelsTab } from '../types';
+import {
+ ChannelOption,
+ ConversationCard,
+ SlimChannelOption,
+ SlimConversationCard,
+} from './ChannelRailItems';
+import { CollapsibleSection, CreateRailAction } from './ChannelsRailSection';
+
+const CHANNEL_TABS = [
+ {
+ value: 'browse',
+ label: 'Browse',
+ },
+ {
+ value: 'recents',
+ label: 'Recents',
+ },
+];
+const SLIM_CHANNEL_TABS = [
+ {
+ value: 'browse',
+ label: (
+ <>
+ <span class="sr-only">Browse</span>
+ <span aria-hidden="true" class="[&_svg]:size-4">
+ <ChatsIcon />
+ </span>
+ </>
+ ),
+ },
+ {
+ value: 'recents',
+ label: (
+ <>
+ <span class="sr-only">Recents</span>
+ <span aria-hidden="true" class="[&_svg]:size-4">
+ <ChatTextIcon />
+ </span>
+ </>
+ ),
+ },
+];
+const CHANNEL_TAB_IDS: ChannelsTab[] = ['browse', 'recents'];
+const CHANNEL_GROUPS: ChannelsGroup[] = ['channels', 'direct_messages'];
+
+type ChannelRailRow =
+ | {
+ kind: 'section';
+ id: `section:${ChannelsGroup}`;
+ group: ChannelsGroup;
+ }
+ | {
+ kind: 'conversation';
+ id: `channel:${string}`;
+ group?: ChannelsGroup;
+ channel: ChannelEntity;
+ };
+
+const sectionRow = (group: ChannelsGroup): ChannelRailRow => ({
+ kind: 'section',
+ id: `section:${group}`,
+ group,
+});
+
+const conversationRow = (
+ channel: ChannelEntity,
+ group?: ChannelsGroup
+): ChannelRailRow => ({
+ kind: 'conversation',
+ id: `channel:${channel.id}`,
+ group,
+ channel,
+});
+
+const rowKeyForChannel = (channelId: string) => `channel:${channelId}`;
+const rowKeyForSection = (group: ChannelsGroup) => `section:${group}`;
+
+/** V2 Chat navigation rail with Browse and Recents destinations. */
+export function ChannelsRail(props: {
+ channels: ChannelEntity[];
+ mode: 'full' | 'slim';
+}) {
+ const { state, setGroupOpen, setSelectedChannelId, setTab } =
+ useChannelsView();
+ const panel = useSplitPanelOrThrow();
+ const currentUserId = useUserId();
+ const notificationSource = useGlobalNotificationSource();
+ const listDomId = createUniqueId();
+ const sectionScrollRoots: Partial<Record<ChannelsGroup, HTMLDivElement>> = {};
+
+ useViewTabHotkeys({
+ scopeId: panel.splitHotkeyScope,
+ enabled: panel.isPanelActive,
+ ids: () => CHANNEL_TAB_IDS,
+ activeId: () => state.tab,
+ setActiveId: setTab,
+ });
+
+ const unreadChannelIds = createMemo(() => {
+ const ids = new Set<string>();
+
+ for (const notification of notificationSource.notifications()) {
+ if (
+ notification.entity_type === 'channel' &&
+ !notificationIsRead(notification)
+ ) {
+ ids.add(notification.entity_id);
+ }
+ }
+
+ return ids;
+ });
+
+ const teamChannels = createMemo(() =>
+ props.channels.filter((channel) => channel.channelType !== 'direct_message')
+ );
+ const directMessages = createMemo(() =>
+ props.channels.filter((channel) => channel.channelType === 'direct_message')
+ );
+ const unreadTeamChannelCount = createMemo(
+ () =>
+ teamChannels().filter((channel) => unreadChannelIds().has(channel.id))
+ .length
+ );
+ const unreadDirectMessageCount = createMemo(
+ () =>
+ directMessages().filter((channel) => unreadChannelIds().has(channel.id))
+ .length
+ );
+ const recentConversations = createMemo(() =>
+ props.channels
+ .filter((channel) => channel.latestRootMessage)
+ .sort((a, b) =>
+ compareDateDesc(
+ a.latestRootMessage?.createdAt,
+ b.latestRootMessage?.createdAt
+ )
+ )
+ );
+ const visibleRows = createMemo<ChannelRailRow[]>(() => {
+ if (state.tab === 'recents') {
+ return recentConversations().map((channel) => conversationRow(channel));
+ }
+
+ const rows: ChannelRailRow[] = [sectionRow('channels')];
+ if (state.expandedGroups.channels) {
+ rows.push(
+ ...teamChannels().map((channel) => conversationRow(channel, 'channels'))
+ );
+ }
+
+ rows.push(sectionRow('direct_messages'));
+ if (state.expandedGroups.direct_messages) {
+ rows.push(
+ ...directMessages().map((channel) =>
+ conversationRow(channel, 'direct_messages')
+ )
+ );
+ }
+
+ return rows;
+ });
+
+ const list = withSplitPanelOwner(listOwnedSlotName('controller'), () =>
+ createListController<ChannelRailRow>({
+ items: visibleRows,
+ getKey: (row) => row.id,
+ isSelectable: () => false,
+ initialFocusKey:
+ state.selectedChannelId === undefined
+ ? undefined
+ : rowKeyForChannel(state.selectedChannelId),
+ onActivate: ({ item }) => {
+ if (item.kind === 'section') {
+ setGroupOpen(item.group, !state.expandedGroups[item.group]);
+ return;
+ }
+
+ setSelectedChannelId(item.channel.id);
+ },
+ })
+ );
+
+ const domIdForRow = (rowId: string) => `${listDomId}-${rowId}`;
+ let listRoot: HTMLDivElement | undefined;
+ const setSectionScrollRoot =
+ (group: ChannelsGroup) => (element: HTMLDivElement) => {
+ sectionScrollRoots[group] = element;
+ };
+ const scrollHandle: ListScrollHandle = {
+ scrollToIndex: (index) => {
+ const row = list.items.at(index);
+ if (!row) return;
+
+ const element = document.getElementById(domIdForRow(row.id));
+ const scrollRoot =
+ row.kind === 'conversation' && row.group
+ ? sectionScrollRoots[row.group]
+ : state.tab === 'recents'
+ ? listRoot
+ : undefined;
+ if (!element || !scrollRoot) return;
+
+ const elementBounds = element.getBoundingClientRect();
+ const scrollBounds = scrollRoot.getBoundingClientRect();
+ if (elementBounds.top < scrollBounds.top) {
+ scrollRoot.scrollTop -= scrollBounds.top - elementBounds.top;
+ } else if (elementBounds.bottom > scrollBounds.bottom) {
+ scrollRoot.scrollTop += elementBounds.bottom - scrollBounds.bottom;
+ }
+ },
+ };
+
+ withSplitPanelOwner(listOwnedSlotName('navigation-hotkeys'), () =>
+ useListInteractions({
+ controller: list,
+ scopeId: panel.splitHotkeyScope,
+ scrollHandle: () => scrollHandle,
+ enabled: panel.isPanelActive,
+ navigation: {
+ onNavigate: (event) => {
+ listRoot?.focus({ preventScroll: true });
+
+ const row = event.result?.item;
+ if (row?.kind === 'conversation') {
+ setSelectedChannelId(row.channel.id);
+ }
+ },
+ },
+ disclosure: {
+ getKey: (row) => row.group,
+ isExpanded: (group) => state.expandedGroups[group as ChannelsGroup],
+ setExpanded: (group, expanded) =>
+ setGroupOpen(group as ChannelsGroup, expanded),
+ getFocusKey: (group) => rowKeyForSection(group as ChannelsGroup),
+ },
+ })
+ );
+
+ const jumpToSection = (offset: 1 | -1) => {
+ const currentGroup = list.focus.item()?.group;
+ const currentIndex = currentGroup
+ ? CHANNEL_GROUPS.indexOf(currentGroup)
+ : -1;
+ const origin = currentIndex === -1 ? (offset === 1 ? -1 : 0) : currentIndex;
+
+ const nextIndex =
+ (origin + offset + CHANNEL_GROUPS.length) % CHANNEL_GROUPS.length;
+ const nextGroup = CHANNEL_GROUPS[nextIndex];
+ if (!nextGroup) return false;
+
+ const result = list.focus.set(rowKeyForSection(nextGroup), {
+ reason: 'keyboard',
+ });
+ if (!result) return false;
+
+ listRoot?.focus({ preventScroll: true });
+ scrollHandle.scrollToIndex(result.index);
+ return true;
+ };
+
+ withSplitPanelOwner(listOwnedSlotName('section-hotkeys'), () => {
+ const group = createHotkeyGroup();
+ const enabled = () => panel.isPanelActive() && state.tab === 'browse';
+
+ registerHotkey({
+ hotkey: ']',
+ scopeId: panel.splitHotkeyScope,
+ description: 'Next channel section',
+ condition: enabled,
+ keyDownHandler: () => jumpToSection(1),
+ }).withGroup(group);
+
+ registerHotkey({
+ hotkey: '[',
+ scopeId: panel.splitHotkeyScope,
+ description: 'Previous channel section',
+ condition: enabled,
+ keyDownHandler: () => jumpToSection(-1),
+ }).withGroup(group);
+
+ onCleanup(() => group.dispose());
+ return group;
+ });
+
+ const mentionsCurrentUser = (channel: ChannelEntity) => {
+ const userId = currentUserId()?.toLocaleLowerCase();
+
+ return Boolean(
+ userId &&
+ channel.latestRootMessage?.mentions.some(
+ (mention) => mention.toLocaleLowerCase() === userId
+ )
+ );
+ };
+ const activateRow = (rowId: string) => {
+ list.activate.key(rowId, { reason: 'pointer' });
+ };
+ const activeDescendant = () => {
+ const rowId = list.focus.key();
+ return rowId === undefined ? undefined : domIdForRow(rowId);
+ };
+
+ createEffect(
+ on(
+ () => props.mode,
+ () => {
+ const focusedIndex = list.focus.index();
+ if (focusedIndex < 0) return;
+
+ const frame = requestAnimationFrame(() => {
+ scrollHandle.scrollToIndex(focusedIndex);
+ });
+
+ onCleanup(() => cancelAnimationFrame(frame));
+ },
+ { defer: true }
+ )
+ );
+
+ return (
+ <aside
+ aria-label="Chat navigation"
+ class="flex size-full min-h-0 flex-col bg-inset pb-5 pt-2"
+ >
+ <Switch>
+ <Match when={props.mode === 'full'}>
+ <div class="flex min-h-8 shrink-0 items-center px-4">
+ <SplitPanel.ControlGroup>
+ <SplitPanel.CloseButton />
+ <SplitPanel.BackButton />
+ <SplitPanel.ForwardButton />
+ </SplitPanel.ControlGroup>
+ </div>
+ <div class="flex shrink-0 items-center px-4 pt-3">
+ <h1 class="m-0 min-w-0 flex-1 truncate text-2xl font-semibold tracking-[-0.03em] text-ink">
+ Chat
+ </h1>
+ </div>
+
+ <div class="shrink-0 px-4 pt-3">
+ <Tabs
+ aria-label="Chat sidebar views"
+ fullWidth
+ list={CHANNEL_TABS}
+ value={state.tab}
+ onChange={(value) => {
+ if (value !== 'browse' && value !== 'recents') return;
+
+ setTab(value);
+ }}
+ />
+ </div>
+
+ <div
+ ref={(element) => {
+ listRoot = element;
+ }}
+ role="tree"
+ tabIndex={-1}
+ aria-activedescendant={activeDescendant()}
+ class={cn(
+ 'scrollbar-hidden min-h-0 flex-1 pt-3 outline-none',
+ state.tab === 'browse' ? 'overflow-hidden' : 'overflow-y-auto'
+ )}
+ >
+ <Switch>
+ <Match when={state.tab === 'browse'}>
+ <div class="flex h-full min-h-0 flex-col gap-3 px-4">
+ <CollapsibleSection.Root open={state.expandedGroups.channels}>
+ <CollapsibleSection.Header
+ focused={
+ list.focus.key() === rowKeyForSection('channels')
+ }
+ focusWithin={list.focus.item()?.group === 'channels'}
+ class="h-9 has-[[data-section-action]:hover]:bg-transparent has-[[data-section-action]:focus-within]:bg-transparent"
+ >
+ <button
+ id={domIdForRow(rowKeyForSection('channels'))}
+ type="button"
+ role="treeitem"
+ tabIndex={-1}
+ class="relative flex h-full min-w-0 flex-1 items-center gap-2 rounded-xl px-2 text-left outline-none focus-visible:ring-2 focus-visible:ring-accent"
+ aria-expanded={state.expandedGroups.channels}
+ onClick={() =>
+ activateRow(rowKeyForSection('channels'))
+ }
+ >
+ <CaretDownIcon
+ class={cn(
+ 'size-3 shrink-0 transition-transform',
+ !state.expandedGroups.channels && '-rotate-90'
+ )}
+ />
+ <span class="min-w-0 flex-1 truncate">Channels</span>
+ <Show when={unreadTeamChannelCount() > 0}>
+ <span class="text-xxs tabular-nums">
+ {unreadTeamChannelCount()}
+ </span>
+ </Show>
+ </button>
+ <div data-section-action="" class="pr-1">
+ <CreateRailAction
+ label="Create channel"
+ onClick={() => openNewChannelModal()}
+ />
+ </div>
+ </CollapsibleSection.Header>
+ <CollapsibleSection.Content
+ open={state.expandedGroups.channels}
+ contentRef={setSectionScrollRoot('channels')}
+ class="flex min-h-0 flex-col gap-0.5"
+ >
+ <Show
+ when={teamChannels().length > 0}
+ fallback={
+ <div class="px-2 py-2 text-xs text-ink-extra-muted">
+ No channels
+ </div>
+ }
+ >
+ <Key each={teamChannels()} by={(channel) => channel.id}>
+ {(channel) => (
+ <ChannelOption
+ id={domIdForRow(rowKeyForChannel(channel().id))}
+ channel={channel()}
+ unread={unreadChannelIds().has(channel().id)}
+ selected={
+ state.selectedChannelId === channel().id
+ }
+ focused={
+ list.focus.key() ===
+ rowKeyForChannel(channel().id)
+ }
+ onActivate={() =>
+ activateRow(rowKeyForChannel(channel().id))
+ }
+ />
+ )}
+ </Key>
+ </Show>
+ </CollapsibleSection.Content>
+ </CollapsibleSection.Root>
+
+ <CollapsibleSection.Root
+ open={state.expandedGroups.direct_messages}
+ >
+ <CollapsibleSection.Header
+ focused={
+ list.focus.key() === rowKeyForSection('direct_messages')
+ }
+ focusWithin={
+ list.focus.item()?.group === 'direct_messages'
+ }
+ class="h-9 has-[[data-section-action]:hover]:bg-transparent has-[[data-section-action]:focus-within]:bg-transparent"
+ >
+ <button
+ id={domIdForRow(rowKeyForSection('direct_messages'))}
+ type="button"
+ role="treeitem"
+ tabIndex={-1}
+ class="relative flex h-full min-w-0 flex-1 items-center gap-2 rounded-xl px-2 text-left outline-none focus-visible:ring-2 focus-visible:ring-accent"
+ aria-expanded={state.expandedGroups.direct_messages}
+ onClick={() =>
+ activateRow(rowKeyForSection('direct_messages'))
+ }
+ >
+ <CaretDownIcon
+ class={cn(
+ 'size-3 shrink-0 transition-transform',
+ !state.expandedGroups.direct_messages &&
+ '-rotate-90'
+ )}
+ />
+ <span class="min-w-0 flex-1 truncate">DMs</span>
+ <Show when={unreadDirectMessageCount() > 0}>
+ <span class="text-xxs tabular-nums">
+ {unreadDirectMessageCount()}
+ </span>
+ </Show>
+ </button>
+ <div data-section-action="" class="pr-1">
+ <CreateRailAction
+ label="Start direct message"
+ onClick={() => {
+ CommandState.clearQuery();
+ CommandState.setCategoryFilter('dms');
+ CommandState.open();
+ }}
+ />
+ </div>
+ </CollapsibleSection.Header>
+ <CollapsibleSection.Content
+ open={state.expandedGroups.direct_messages}
+ contentRef={setSectionScrollRoot('direct_messages')}
+ class="flex min-h-0 flex-col gap-0.5"
+ >
+ <Show
+ when={directMessages().length > 0}
+ fallback={
+ <div class="px-2 py-2 text-xs text-ink-extra-muted">
+ No direct messages
+ </div>
+ }
+ >
+ <Key
+ each={directMessages()}
+ by={(channel) => channel.id}
+ >
+ {(channel) => (
+ <ChannelOption
+ id={domIdForRow(rowKeyForChannel(channel().id))}
+ channel={channel()}
+ unread={unreadChannelIds().has(channel().id)}
+ selected={
+ state.selectedChannelId === channel().id
+ }
+ focused={
+ list.focus.key() ===
+ rowKeyForChannel(channel().id)
+ }
+ onActivate={() =>
+ activateRow(rowKeyForChannel(channel().id))
+ }
+ />
+ )}
+ </Key>
+ </Show>
+ </CollapsibleSection.Content>
+ </CollapsibleSection.Root>
+ </div>
+ </Match>
+ <Match when={state.tab === 'recents'}>
+ <Show
+ when={recentConversations().length > 0}
+ fallback={
+ <div class="px-3 py-8 text-center text-sm text-ink-extra-muted">
+ No recent messages
+ </div>
+ }
+ >
+ <div class="flex w-full flex-col divide-y divide-edge-muted">
+ <Key
+ each={recentConversations()}
+ by={(channel) => channel.id}
+ >
+ {(channel) => (
+ <ConversationCard
+ id={domIdForRow(rowKeyForChannel(channel().id))}
+ channel={channel()}
+ senderId={channel().latestRootMessage?.senderId}
+ mentionedCurrentUser={mentionsCurrentUser(channel())}
+ unread={unreadChannelIds().has(channel().id)}
+ selected={state.selectedChannelId === channel().id}
+ focused={
+ list.focus.key() === rowKeyForChannel(channel().id)
+ }
+ onActivate={() =>
+ activateRow(rowKeyForChannel(channel().id))
+ }
+ />
+ )}
+ </Key>
+ </div>
+ </Show>
+ </Match>
+ </Switch>
+ </div>
+ </Match>
+ <Match when={props.mode === 'slim'}>
+ <div class="flex shrink-0 justify-center px-2 pb-2">
+ <SplitPanel.ControlGroup>
+ <div class="grid w-12 grid-cols-2 justify-items-center">
+ <div class="col-span-2">
+ <SplitPanel.CloseButton size="icon-sm" />
+ </div>
+ <div>
+ <SplitPanel.BackButton size="icon-sm" />
+ </div>
+ <div>
+ <SplitPanel.ForwardButton size="icon-sm" />
+ </div>
+ </div>
+ </SplitPanel.ControlGroup>
+ </div>
+ <div class="shrink-0 px-3">
+ <Tabs
+ aria-label="Chat sidebar views"
+ class="h-[76px] flex-col"
+ itemClass="h-auto min-h-0 w-full"
+ labelClass="size-full p-0"
+ fullWidth
+ list={SLIM_CHANNEL_TABS}
+ value={state.tab}
+ onChange={(value) => {
+ if (value !== 'browse' && value !== 'recents') return;
+
+ setTab(value);
+ }}
+ />
+ </div>
+
+ <div
+ ref={(element) => {
+ listRoot = element;
+ }}
+ role="tree"
+ tabIndex={-1}
+ aria-activedescendant={activeDescendant()}
+ class={cn(
+ 'scrollbar-hidden min-h-0 flex-1 pt-3 outline-none',
+ state.tab === 'browse' ? 'overflow-hidden' : 'overflow-y-auto'
+ )}
+ >
+ <Switch>
+ <Match when={state.tab === 'browse'}>
+ <div class="flex h-full min-h-0 flex-col gap-3 px-2">
+ <CollapsibleSection.Root
+ open={state.expandedGroups.channels}
+ class="items-center"
+ >
+ <CollapsibleSection.Header
+ focused={
+ list.focus.key() === rowKeyForSection('channels')
+ }
+ focusWithin={list.focus.item()?.group === 'channels'}
+ class="h-10 justify-center"
+ >
+ <button
+ id={domIdForRow(rowKeyForSection('channels'))}
+ type="button"
+ role="treeitem"
+ tabIndex={-1}
+ class="relative flex size-10 min-w-10 flex-none items-center justify-center rounded-full outline-none focus-visible:ring-2 focus-visible:ring-accent"
+ aria-expanded={state.expandedGroups.channels}
+ aria-label="Channels"
+ onClick={() =>
+ activateRow(rowKeyForSection('channels'))
+ }
+ >
+ <span class="flex items-center justify-center [&_svg]:size-4">
+ <ChannelIcon />
+ </span>
+ <Show when={unreadTeamChannelCount() > 0}>
+ <span class="text-xxs absolute right-0.5 top-0 tabular-nums">
+ {unreadTeamChannelCount()}
+ </span>
+ </Show>
+ </button>
+ </CollapsibleSection.Header>
+ <div class="w-full px-2">
+ <div class="border-t border-edge-muted" />
+ </div>
+ <CollapsibleSection.Content
+ open={state.expandedGroups.channels}
+ contentRef={setSectionScrollRoot('channels')}
+ containerClass="w-full"
+ class="flex min-h-0 w-full flex-col items-center gap-0.5"
+ >
+ <div class="flex justify-center">
+ <CreateRailAction
+ label="Create channel"
+ slim
+ onClick={() => openNewChannelModal()}
+ />
+ </div>
+ <Show when={teamChannels().length > 0}>
+ <Key each={teamChannels()} by={(channel) => channel.id}>
+ {(channel) => (
+ <SlimChannelOption
+ id={domIdForRow(rowKeyForChannel(channel().id))}
+ channel={channel()}
+ unread={unreadChannelIds().has(channel().id)}
+ selected={
+ state.selectedChannelId === channel().id
+ }
+ focused={
+ list.focus.key() ===
+ rowKeyForChannel(channel().id)
+ }
+ onActivate={() =>
+ activateRow(rowKeyForChannel(channel().id))
+ }
+ />
+ )}
+ </Key>
+ </Show>
+ </CollapsibleSection.Content>
+ </CollapsibleSection.Root>
+
+ <CollapsibleSection.Root
+ open={state.expandedGroups.direct_messages}
+ class="items-center"
+ >
+ <CollapsibleSection.Header
+ focused={
+ list.focus.key() === rowKeyForSection('direct_messages')
+ }
+ focusWithin={
+ list.focus.item()?.group === 'direct_messages'
+ }
+ class="h-10 justify-center"
+ >
+ <button
+ id={domIdForRow(rowKeyForSection('direct_messages'))}
+ type="button"
+ role="treeitem"
+ tabIndex={-1}
+ class="relative flex size-10 min-w-10 flex-none items-center justify-center rounded-full outline-none focus-visible:ring-2 focus-visible:ring-accent"
+ aria-expanded={state.expandedGroups.direct_messages}
+ aria-label="DMs"
+ onClick={() =>
+ activateRow(rowKeyForSection('direct_messages'))
+ }
+ >
+ <span class="flex items-center justify-center [&_svg]:size-4">
+ <ChatTeardropIcon />
+ </span>
+ <Show when={unreadDirectMessageCount() > 0}>
+ <span class="text-xxs absolute right-0.5 top-0 tabular-nums">
+ {unreadDirectMessageCount()}
+ </span>
+ </Show>
+ </button>
+ </CollapsibleSection.Header>
+ <div class="w-full px-2">
+ <div class="border-t border-edge-muted" />
+ </div>
+ <CollapsibleSection.Content
+ open={state.expandedGroups.direct_messages}
+ contentRef={setSectionScrollRoot('direct_messages')}
+ containerClass="w-full"
+ class="flex min-h-0 w-full flex-col items-center gap-0.5"
+ >
+ <div class="flex justify-center">
+ <CreateRailAction
+ label="Start direct message"
+ slim
+ onClick={() => {
+ CommandState.clearQuery();
+ CommandState.setCategoryFilter('dms');
+ CommandState.open();
+ }}
+ />
+ </div>
+ <Show when={directMessages().length > 0}>
+ <Key
+ each={directMessages()}
+ by={(channel) => channel.id}
+ >
+ {(channel) => (
+ <SlimChannelOption
+ id={domIdForRow(rowKeyForChannel(channel().id))}
+ channel={channel()}
+ unread={unreadChannelIds().has(channel().id)}
+ selected={
+ state.selectedChannelId === channel().id
+ }
+ focused={
+ list.focus.key() ===
+ rowKeyForChannel(channel().id)
+ }
+ onActivate={() =>
+ activateRow(rowKeyForChannel(channel().id))
+ }
+ />
+ )}
+ </Key>
+ </Show>
+ </CollapsibleSection.Content>
+ </CollapsibleSection.Root>
+ </div>
+ </Match>
+ <Match when={state.tab === 'recents'}>
+ <Show when={recentConversations().length > 0}>
+ <div class="flex w-full flex-col gap-0.5">
+ <Key
+ each={recentConversations()}
+ by={(channel) => channel.id}
+ >
+ {(channel) => (
+ <SlimConversationCard
+ id={domIdForRow(rowKeyForChannel(channel().id))}
+ channel={channel()}
+ senderId={channel().latestRootMessage?.senderId}
+ mentionedCurrentUser={mentionsCurrentUser(channel())}
+ unread={unreadChannelIds().has(channel().id)}
+ selected={state.selectedChannelId === channel().id}
+ focused={
+ list.focus.key() === rowKeyForChannel(channel().id)
+ }
+ onActivate={() =>
+ activateRow(rowKeyForChannel(channel().id))
+ }
+ />
+ )}
+ </Key>
+ </div>
+ </Show>
+ </Match>
+ </Switch>
+ </div>
+ </Match>
+ </Switch>
+ </aside>
+ );
+}
diff --git a/apps/web/src/features/channels-view/components/ChannelsRailSection.tsx b/apps/web/src/features/channels-view/components/ChannelsRailSection.tsx
new file mode 100644
index 0000000000..f64a341836
--- /dev/null
+++ b/apps/web/src/features/channels-view/components/ChannelsRailSection.tsx
@@ -0,0 +1,121 @@
+import { ScrollIndicators } from '@core/component/VerticalScrollIndicators';
+import PlusIcon from '@phosphor/plus.svg';
+import { cn, Scroll } from '@ui';
+import { createSignal, type JSX, Show } from 'solid-js';
+
+function SectionScrollArea(props: {
+ contentRef: (element: HTMLDivElement) => void;
+ containerClass?: string;
+ class?: string;
+ children: JSX.Element;
+}) {
+ const [scrollRoot, setScrollRoot] = createSignal<HTMLDivElement>();
+
+ return (
+ <div class={cn('relative min-h-0 flex-1', props.containerClass)}>
+ <Scroll
+ scrollRef={(element) => {
+ setScrollRoot(element);
+ props.contentRef(element);
+ }}
+ >
+ <div role="group" class={props.class}>
+ {props.children}
+ </div>
+ </Scroll>
+ <ScrollIndicators
+ scrollRef={scrollRoot}
+ appearance="gradient"
+ gradientColor="inset"
+ />
+ </div>
+ );
+}
+
+function CollapsibleSectionRoot(props: {
+ open: boolean;
+ class?: string;
+ children: JSX.Element;
+}) {
+ return (
+ <section
+ class={cn(
+ 'flex min-h-0 flex-col gap-1',
+ props.open && 'shrink',
+ !props.open && 'shrink-0',
+ props.open && 'max-h-[calc(50%_-_0.375rem)]',
+ props.class
+ )}
+ >
+ {props.children}
+ </section>
+ );
+}
+
+function CollapsibleSectionHeader(props: {
+ focused: boolean;
+ focusWithin: boolean;
+ class?: string;
+ children: JSX.Element;
+}) {
+ return (
+ <div
+ class={cn(
+ 'flex w-full items-center rounded-xl text-xs font-semibold uppercase tracking-wide text-ink-extra-muted transition-colors hover:bg-hover hover:text-ink-muted',
+ props.focused && 'bg-hover text-ink-muted',
+ !props.focused && props.focusWithin && 'text-ink-muted',
+ props.class
+ )}
+ >
+ {props.children}
+ </div>
+ );
+}
+
+function CollapsibleSectionContent(props: {
+ open: boolean;
+ contentRef: (element: HTMLDivElement) => void;
+ containerClass?: string;
+ class?: string;
+ children: JSX.Element;
+}) {
+ return (
+ <Show when={props.open}>
+ <SectionScrollArea
+ contentRef={props.contentRef}
+ containerClass={props.containerClass}
+ class={props.class}
+ >
+ {props.children}
+ </SectionScrollArea>
+ </Show>
+ );
+}
+
+export const CollapsibleSection = {
+ Root: CollapsibleSectionRoot,
+ Header: CollapsibleSectionHeader,
+ Content: CollapsibleSectionContent,
+};
+
+export function CreateRailAction(props: {
+ label: string;
+ slim?: boolean;
+ onClick: () => void;
+}) {
+ return (
+ <button
+ type="button"
+ class={cn(
+ 'flex shrink-0 items-center justify-center text-ink-muted transition-colors hover:bg-hover hover:text-ink focus-visible:ring-2 focus-visible:ring-accent',
+ props.slim &&
+ 'size-10 rounded-full border border-edge-muted bg-transparent',
+ !props.slim && 'size-7 rounded-lg'
+ )}
+ aria-label={props.label}
+ onClick={props.onClick}
+ >
+ <PlusIcon class="size-3.5" />
+ </button>
+ );
+}
diff --git a/apps/web/src/features/channels-view/persistence.ts b/apps/web/src/features/channels-view/persistence.ts
new file mode 100644
index 0000000000..7559b9da23
--- /dev/null
+++ b/apps/web/src/features/channels-view/persistence.ts
@@ -0,0 +1,154 @@
+import type {
+ MakePersistedStateOptions,
+ PersistenceStorage,
+} from '@app/lib/persistence';
+import {
+ createEntryPersistenceStorage,
+ type EntryPersistenceHandle,
+} from '@components/app/split-layout/entry-persistence';
+import { createUserScopedStorage } from '@core/util/userScopedStorage';
+import type { Accessor } from 'solid-js';
+import { z } from 'zod';
+import type { ChannelsViewState } from './types';
+
+const CHANNELS_ENTRY_STATE_KEY = 'channels.view';
+const channelsLocalStateStorage = createUserScopedStorage(
+ 'macro:channels:view-state:v1'
+);
+
+const channelsExpandedGroupsSchema = z.preprocess(
+ (value) => {
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
+ return value;
+ }
+
+ const groups = value as Record<string, unknown>;
+ return {
+ ...groups,
+ direct_messages: groups.direct_messages ?? groups['direct-messages'],
+ };
+ },
+ z.object({
+ channels: z.boolean().default(true),
+ direct_messages: z.boolean().default(true),
+ })
+);
+
+const channelsEntryStateSchemaWithDefaults = z.object({
+ version: z.literal(1).default(1),
+ tab: z.enum(['browse', 'recents']).default('browse'),
+ selectedChannelId: z.string().optional(),
+ expandedGroups: channelsExpandedGroupsSchema.default({
+ channels: true,
+ direct_messages: true,
+ }),
+});
+
+type ChannelsEntryState = z.infer<typeof channelsEntryStateSchemaWithDefaults>;
+
+const DEFAULT_CHANNELS_ENTRY_STATE: ChannelsEntryState =
+ channelsEntryStateSchemaWithDefaults.parse({});
+const channelsEntryStateSchema = channelsEntryStateSchemaWithDefaults.catch(
+ DEFAULT_CHANNELS_ENTRY_STATE
+);
+
+function selectEntryState(state: ChannelsViewState): ChannelsEntryState {
+ return {
+ version: 1,
+ tab: state.tab,
+ ...(state.selectedChannelId === undefined
+ ? {}
+ : { selectedChannelId: state.selectedChannelId }),
+ expandedGroups: state.expandedGroups,
+ };
+}
+
+function restoreChannelsEntryState(
+ current: ChannelsViewState,
+ stored: unknown
+): ChannelsViewState {
+ const restored = channelsEntryStateSchema.parse(stored);
+
+ return {
+ ...current,
+ tab: restored.tab,
+ selectedChannelId: restored.selectedChannelId,
+ expandedGroups: restored.expandedGroups,
+ };
+}
+
+function createChannelsEntryStorage(options: {
+ handle: EntryPersistenceHandle;
+ restore: boolean;
+}): PersistenceStorage<ChannelsViewState> {
+ return createEntryPersistenceStorage({
+ handle: options.handle,
+ key: CHANNELS_ENTRY_STATE_KEY,
+ restore: (current, stored) => {
+ if (!options.restore) return undefined;
+
+ return restoreChannelsEntryState(current, stored);
+ },
+ select: selectEntryState,
+ });
+}
+
+function createChannelsLocalStateStorage(options: {
+ userId: Accessor<string | undefined>;
+ restore: boolean;
+}): PersistenceStorage<ChannelsViewState> {
+ let previous: string | undefined;
+ const serialize = (state: ChannelsViewState) =>
+ JSON.stringify(selectEntryState(state));
+
+ return {
+ restore: (current) => {
+ if (!options.restore) return undefined;
+
+ const userId = options.userId();
+ if (!userId) return undefined;
+
+ const raw = channelsLocalStateStorage.read(userId);
+ if (raw === null) return undefined;
+
+ try {
+ return restoreChannelsEntryState(current, JSON.parse(raw));
+ } catch {
+ return undefined;
+ }
+ },
+ initialize: (current) => {
+ previous = serialize(current);
+ },
+ write: (current) => {
+ const userId = options.userId();
+ if (!userId) return;
+
+ const serialized = serialize(current);
+ if (serialized === previous) return;
+
+ previous = serialized;
+ channelsLocalStateStorage.write(userId, serialized);
+ },
+ };
+}
+
+export function createChannelsViewPersistence(options: {
+ handle: EntryPersistenceHandle;
+ userId: Accessor<string | undefined>;
+ restoreEntryState?: boolean;
+ restoreLocalState?: boolean;
+}): MakePersistedStateOptions<ChannelsViewState> {
+ return {
+ storages: [
+ createChannelsLocalStateStorage({
+ userId: options.userId,
+ restore: options.restoreLocalState ?? true,
+ }),
+ createChannelsEntryStorage({
+ handle: options.handle,
+ restore: options.restoreEntryState ?? true,
+ }),
+ ],
+ };
+}
diff --git a/apps/web/src/features/channels-view/types.ts b/apps/web/src/features/channels-view/types.ts
new file mode 100644
index 0000000000..456833cb0b
--- /dev/null
+++ b/apps/web/src/features/channels-view/types.ts
@@ -0,0 +1,15 @@
+export type ChannelsTab = 'browse' | 'recents';
+
+export type ChannelsGroup = 'channels' | 'direct_messages';
+
+export type ChannelsViewState = {
+ tab: ChannelsTab;
+ selectedChannelId?: string;
+ expandedGroups: Record<ChannelsGroup, boolean>;
+};
+
+export type ChannelsViewStateOptions = Partial<
+ Omit<ChannelsViewState, 'expandedGroups'>
+> & {
+ expandedGroups?: Partial<ChannelsViewState['expandedGroups']>;
+};
diff --git a/apps/web/src/features/channels-view/utils.ts b/apps/web/src/features/channels-view/utils.ts
new file mode 100644
index 0000000000..de745f1525
--- /dev/null
+++ b/apps/web/src/features/channels-view/utils.ts
@@ -0,0 +1,23 @@
+import type { DateValue } from '@core/util/date';
+
+export function channelInitials(name: string) {
+ const words = name.replace(/^#+/, '').trim().split(/\s+/).filter(Boolean);
+
+ if (words.length === 0) return '?';
+
+ return words
+ .slice(0, 2)
+ .map((word) => word[0])
+ .join('')
+ .toLocaleUpperCase();
+}
+
+export function formatDetailedTimestamp(timestamp: DateValue) {
+ const date = timestamp instanceof Date ? timestamp : new Date(timestamp);
+ if (Number.isNaN(date.getTime())) return String(timestamp);
+
+ return date.toLocaleString(undefined, {
+ dateStyle: 'medium',
+ timeStyle: 'short',
+ });
+}
diff --git a/apps/web/src/features/inbox-view/components/InboxList.tsx b/apps/web/src/features/inbox-view/components/InboxList.tsx
index 34d60fd2f1..c8b73b355b 100644
--- a/apps/web/src/features/inbox-view/components/InboxList.tsx
+++ b/apps/web/src/features/inbox-view/components/InboxList.tsx
@@ -232,11 +232,6 @@ export function InboxList() {
{ storages: createInboxListEntryStorage(panel.handle) }
);
- createEffect(() => {
- const focusKey = list.focus.requestedKey();
- setPersistedListState((current) => ({ ...current, focusKey }));
- });
-
const rows = source.items;
const swipeRowsById = createMemo(() => {
@@ -405,10 +400,6 @@ export function InboxList() {
const handle = virtualizer();
if (!handle) return;
- setPersistedListState((current) => ({
- ...current,
- scrollOffset: handle.scrollOffset,
- }));
if (!source.hasMore()) return;
const distance =
diff --git a/apps/web/src/lib/core/component/TabsInset.tsx b/apps/web/src/lib/core/component/TabsInset.tsx
index 9ceaddaec3..88ff29b1bd 100644
--- a/apps/web/src/lib/core/component/TabsInset.tsx
+++ b/apps/web/src/lib/core/component/TabsInset.tsx
@@ -17,6 +17,8 @@ type TabsInsetProps = {
defaultValue?: string;
class?: string;
trackClass?: string;
+ itemClass?: string;
+ labelClass?: string;
depth?: 0 | 1 | 2 | 3 | 4;
fullWidth?: boolean;
} & Omit<SegmentedControlRootProps, 'defaultValue'>;
@@ -29,6 +31,8 @@ export const TabsInset = (props: TabsInsetProps) => {
'disabled',
'class',
'trackClass',
+ 'itemClass',
+ 'labelClass',
'depth',
'fullWidth',
]);
@@ -65,13 +69,14 @@ export const TabsInset = (props: TabsInsetProps) => {
<KSegmentedControl.Item
value={item.value}
disabled={local.disabled}
- class={cn(local.fullWidth && 'flex-1')}
+ class={cn(local.fullWidth && 'flex-1', local.itemClass)}
>
<KSegmentedControl.ItemInput class="absolute inset-0 pointer-events-none" />
<KSegmentedControl.ItemLabel
class={cn(
'flex items-center px-2.5 py-1 text-xs font-medium data-checked:ring data-checked:ring-edge-muted ring-inset rounded-md text-ink-extra-muted hover:text-ink data-checked:bg-surface data-checked:text-ink data-checked:shadow-[0_1px_2px_rgba(0,0,0,0.06)]',
- local.fullWidth && 'w-full justify-center'
+ local.fullWidth && 'w-full justify-center',
+ local.labelClass
)}
onPointerDown={(e) => {
if (isTouchDevice()) e.preventDefault();
diff --git a/apps/web/src/lib/core/constant/featureFlags.ts b/apps/web/src/lib/core/constant/featureFlags.ts
index 748e18d313..c1527b04d2 100644
--- a/apps/web/src/lib/core/constant/featureFlags.ts
+++ b/apps/web/src/lib/core/constant/featureFlags.ts
@@ -47,8 +47,8 @@ export function resolveFeatureFlag(
export const DEV_MODE_ENV = import.meta.env.MODE === 'development';
/**
- * Switches Inbox and Tasks from the current SoupView implementations to the
- * new composable view implementations. Override locally with
+ * Switches Inbox, Tasks, and Channels from the current SoupView implementations
+ * to the new composable view implementations. Override locally with
* VITE_ENABLE_NEW_APP_VIEWS.
*/
export const ENABLE_NEW_APP_VIEWS_FLAG = 'enable-new-app-views';
diff --git a/apps/web/src/lib/persistence/make-persisted-state.test.ts b/apps/web/src/lib/persistence/make-persisted-state.test.ts
index 21e92dffd1..34840e9b75 100644
--- a/apps/web/src/lib/persistence/make-persisted-state.test.ts
+++ b/apps/web/src/lib/persistence/make-persisted-state.test.ts
@@ -112,16 +112,24 @@ describe('makePersistedState', () => {
createRoot((dispose) => {
const initialize = vi.fn();
const storageDispose = vi.fn();
+ let readCurrent!: () => string;
const storage: PersistenceStorage<string> = {
restore: () => undefined,
write: vi.fn(),
- initialize,
+ initialize: (value, read) => {
+ initialize(value);
+ readCurrent = read;
+ },
dispose: storageDispose,
};
- makePersistedState(createSignal('default'), { storages: storage });
+ const signal = createSignal('default');
+ makePersistedState(signal, { storages: storage });
expect(initialize).toHaveBeenCalledWith('default');
+ signal[1]('latest');
+ expect(readCurrent()).toBe('latest');
+
dispose();
expect(storageDispose).toHaveBeenCalledOnce();
});
diff --git a/apps/web/src/lib/persistence/make-persisted-state.ts b/apps/web/src/lib/persistence/make-persisted-state.ts
index 6597525f64..98c542a24a 100644
--- a/apps/web/src/lib/persistence/make-persisted-state.ts
+++ b/apps/web/src/lib/persistence/make-persisted-state.ts
@@ -32,7 +32,11 @@ export type PersistedState<TState extends PersistableState> = [
export type PersistenceStorage<T> = {
restore: (current: T) => T | undefined;
write: (value: T) => unknown;
- initialize?: (value: T) => void;
+ /**
+ * Initializes storage-owned capture state and provides an untracked reader
+ * for storage mechanisms that pull the current value on demand.
+ */
+ initialize?: (value: T, readCurrent: () => T) => void;
dispose?: () => void;
};
@@ -96,10 +100,11 @@ export function makePersistedState<TState extends PersistableState>(
}
}
- const current = untrack(get);
+ const readCurrent = () => untrack(get);
+ const current = readCurrent();
for (const storage of storages) {
try {
- storage.initialize?.(current);
+ storage.initialize?.(current, readCurrent);
} catch {
// Initialization is best effort, matching restores and writes.
}
@@ -107,7 +112,7 @@ export function makePersistedState<TState extends PersistableState>(
}
const persistCurrent = () => {
- const value = untrack(get);
+ const value = readCurrent();
for (const storage of storages) {
try {
storage.write(value);