Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(channel-view): pagination of section lists (#6281)
dev-rb3efa57d60ffa
diff --git a/apps/web/src/components/list/README.md b/apps/web/src/components/list/README.mdindex 2ad8dab386..d7451c0671 100644--- a/apps/web/src/components/list/README.md+++ b/apps/web/src/components/list/README.md@@ -60,6 +60,15 @@ instead of eagerly memoizing them in its panel-owned root. This lets mountedrendering choose its reactive owner while off-screen navigation reads currentquery and group pages on demand.+### Boundary pagination++`useListInteractions` accepts `navigation.onBeforeMove` for paginated+collections. Returning `false` consumes the key without moving focus. A list+can use this at its final loaded row to start `loadMore`, keep repeated key+presses on that row while loading, and allow the next move once rows append.+When the source has no continuation, the guard should return `true` so normal+navigation can cross into the next group or section.+## Applying the patternInbox's model owns Signal/Noise/All admission, notification enrichment, readdiff --git a/apps/web/src/components/list/index.ts b/apps/web/src/components/list/index.tsindex 81fab3cd83..a7437e0068 100644--- a/apps/web/src/components/list/index.ts+++ b/apps/web/src/components/list/index.ts@@ -37,6 +37,7 @@ export type {export {type ListInteractionActivation,type ListInteractionActivationIntent,+ type ListInteractionBeforeMoveEvent,type ListInteractionDisclosure,type ListInteractionNavigation,type ListInteractionNavigationEvent,diff --git a/apps/web/src/components/list/use-list-interactions.ts b/apps/web/src/components/list/use-list-interactions.tsindex 09ebae18ad..328ab6180c 100644--- a/apps/web/src/components/list/use-list-interactions.ts+++ b/apps/web/src/components/list/use-list-interactions.ts@@ -28,6 +28,11 @@ type ListInteractionConditions = Partial<>;export type ListInteractionNavigation<TItem> = {+ /**+ * Return false to consume a move without changing focus.+ * Useful when a list must load more rows before crossing a boundary.+ */+ onBeforeMove?: (event: ListInteractionBeforeMoveEvent<TItem>) => boolean;move?: ListNavigationOptions<TItem>;first?: ListNavigationOptions<TItem>;last?: ListNavigationOptions<TItem>;@@ -35,6 +40,11 @@ export type ListInteractionNavigation<TItem> = {onNavigate?: (event: ListInteractionNavigationEvent<TItem>) => void;};+export type ListInteractionBeforeMoveEvent<TItem> = {+ direction: 1 | -1;+ current: ListItemResult<TItem> | undefined;+};+export type ListInteractionNavigationEvent<TItem> =| {kind: 'move';@@ -98,6 +108,15 @@ export function useListInteractions<TItem, TMetadata = unknown>(};const move = (offset: 1 | -1) => {+ if (+ options.navigation?.onBeforeMove?.({+ direction: offset,+ current: list.focus.result(),+ }) === false+ ) {+ return true;+ }+const result = list.navigate.by(offset, options.navigation?.move);options.navigation?.onNavigate?.({kind: 'move',diff --git a/apps/web/src/features/channels-view/channels-view.tsx b/apps/web/src/features/channels-view/channels-view.tsxindex bd5304b07f..b4222a6f92 100644--- a/apps/web/src/features/channels-view/channels-view.tsx+++ b/apps/web/src/features/channels-view/channels-view.tsx@@ -6,7 +6,7 @@ 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 { isTouchDevice } from '@core/mobile/isTouchDevice';-import { isChannelEntity, ListEntityMetadataQueryProvider } from '@entity';+import { ListEntityMetadataQueryProvider } from '@entity';import SpinnerIcon from '@phosphor/spinner.svg';import { createElementSize } from '@solid-primitives/resize-observer';import { createMemo, createSignal, onMount, Show, Suspense } from 'solid-js';@@ -18,7 +18,12 @@ import {CHANNELS_MIN_RAIL_WIDTH,CHANNELS_NARROW_RAIL_WIDTH,} from './constants';-import { useChannelsQuery } from './queries';+import {+ deduplicateChannels,+ resolveSelectedChannel,+ useChannelByIdQuery,+ useChannelsSources,+} from './queries';import type { ChannelsViewStateOptions } from './types';export type ChannelsViewProps = {@@ -55,15 +60,43 @@ function ChannelsViewRoot() {max: CHANNELS_MAX_RAIL_WIDTH,};- const channelsQuery = useChannelsQuery(() =>- isTouchDevice() ? state.mobileTab : 'recents'+ const sources = useChannelsSources((scope) =>+ isTouchDevice()+ ? state.mobileTab === scope+ : scope === 'recents'+ ? state.tab === 'recents'+ : state.tab === 'browse'+ );+ const loadedChannels = createMemo(() =>+ deduplicateChannels([+ sources.channels.items(),+ sources.direct_messages.items(),+ sources.recents.items(),+ ]));- const channels = createMemo(() =>- (channelsQuery.data?.entities ?? []).filter(isChannelEntity)+ const loadedSelectedChannel = createMemo(() =>+ resolveSelectedChannel(state.selectedChannelId, loadedChannels()));- const selectedChannel = createMemo(() =>- channels().find((channel) => channel.id === state.selectedChannelId)+ const selectedChannelQuery = useChannelByIdQuery(+ () => state.selectedChannelId,+ () =>+ !isTouchDevice() &&+ state.selectedChannelId !== undefined &&+ loadedSelectedChannel() === undefined);+ const selectedChannel = createMemo(() => {+ const loaded = loadedSelectedChannel();+ if (loaded) return loaded;+ if (!selectedChannelQuery.isEnabled || selectedChannelQuery.isLoading) {+ return;+ }++ return resolveSelectedChannel(+ state.selectedChannelId,+ loadedChannels(),+ selectedChannelQuery.data?.entities+ );+ });onMount(() => panel.handle.setDisplayName('Channels'));@@ -89,7 +122,7 @@ function ChannelsViewRoot() {}}><ChannelsRail- channels={channels()}+ sources={sources}mode={railMode()}onModeChange={setRailMode}/>@@ -145,8 +178,7 @@ function ChannelsViewRoot() {}><ChannelsMobileView- channels={channels()}- source={channelsQuery}+ source={sources[state.mobileTab]}tab={state.mobileTab}onTabChange={setMobileTab}/>diff --git a/apps/web/src/features/channels-view/components/ChannelsMobileView.tsx b/apps/web/src/features/channels-view/components/ChannelsMobileView.tsxindex 7fc9ee7b3a..c0744d0b77 100644--- a/apps/web/src/features/channels-view/components/ChannelsMobileView.tsx+++ b/apps/web/src/features/channels-view/components/ChannelsMobileView.tsx@@ -8,7 +8,6 @@ import { useUserId } from '@core/context/user';import type { ChannelEntity } from '@entity';import { isMutedItem } from '@entity/utils/notification';import SpinnerIcon from '@phosphor/spinner.svg';-import type { SoupAstItemsQuery } from '@queries/soup/items';import { createElementSize } from '@solid-primitives/resize-observer';import { Button } from '@ui';import {@@ -21,7 +20,7 @@ import {} from 'solid-js';import { Virtualizer, type VirtualizerHandle } from 'virtua/solid';import { useChannelsView } from '../channels-view-context';-import { filterChannelsForScope } from '../queries';+import type { ChannelsDataSource } from '../queries';import type { ChannelsQueryScope } from '../types';import { channelMentionsUser } from '../utils';import { ChannelsEmptyState } from './ChannelsEmptyState';@@ -42,8 +41,7 @@ const MOBILE_CHANNEL_BUFFER_SIZE = MOBILE_CHANNEL_ITEM_SIZE * 6;const LOAD_MORE_THRESHOLD = 300;export function ChannelsMobileView(props: {- channels: ChannelEntity[];- source: SoupAstItemsQuery;+ source: ChannelsDataSource;tab: ChannelsQueryScope;onTabChange: (tab: ChannelsQueryScope) => void;}) {@@ -60,14 +58,8 @@ export function ChannelsMobileView(props: {);const listId = createUniqueId();const channelCalls = useChannelCalls();- const channelActivity = useChannelRailActivity(- () => props.channels,- channelCalls- );-- const visibleChannels = createMemo(() =>- filterChannelsForScope(props.tab, props.channels)- );+ const visibleChannels = createMemo(() => props.source.items());+ const channelActivity = useChannelRailActivity(visibleChannels, channelCalls);const selectTab = (tab: ChannelsQueryScope) => {props.onTabChange(tab);@@ -78,14 +70,14 @@ export function ChannelsMobileView(props: {function loadNextPage() {if (- props.source.isFetching ||- props.source.isFetchingNextPage ||- !props.source.hasNextPage+ props.source.isFetching() ||+ props.source.isLoadingMore() ||+ !props.source.hasMore()) {return;}- void props.source.fetchNextPage();+ void props.source.loadMore();}function checkNearEnd(offset?: number) {@@ -126,7 +118,7 @@ export function ChannelsMobileView(props: {<divrole="tree"aria-label={`${MOBILE_CHANNEL_TABS.find((tab) => tab.value === props.tab)?.label ?? 'Channels'} conversations`}- aria-busy={props.source.isFetchingNextPage}+ aria-busy={props.source.isLoadingMore()}class="size-full min-h-0 overflow-hidden"><div@@ -139,7 +131,7 @@ export function ChannelsMobileView(props: {class="h-[calc(var(--mobile-content-inset-top,0px)+0.75rem)]"/><Switch>- <Match when={!forceEmptyState() && props.source.isLoading}>+ <Match when={!forceEmptyState() && props.source.isLoading()}><div class="grid min-h-32 place-items-center text-ink-muted"><SpinnerIconaria-label="Loading conversations"@@ -147,7 +139,13 @@ export function ChannelsMobileView(props: {/></div></Match>- <Match when={!forceEmptyState() && props.source.error}>+ <Match+ when={+ !forceEmptyState() &&+ props.source.error() &&+ visibleChannels().length === 0+ }+ ><div class="flex min-h-32 flex-col items-center justify-center gap-3 px-(--mobile-chrome-gutter) text-sm text-ink-muted"><span>Conversations couldn’t be loaded.</span><Button@@ -198,7 +196,7 @@ export function ChannelsMobileView(props: {/>)}</Virtualizer>- <Show when={props.source.isFetchingNextPage}>+ <Show when={props.source.isLoadingMore()}><div class="flex h-12 items-center justify-center text-ink-muted"><SpinnerIconaria-label="Loading more conversations"@@ -206,6 +204,24 @@ export function ChannelsMobileView(props: {/></div></Show>+ <Show+ when={+ props.source.error() &&+ !props.source.isLoadingMore() &&+ visibleChannels().length > 0+ }+ >+ <div class="flex items-center justify-center gap-2 py-3 text-xs text-ink-muted">+ <span>Couldn’t load more conversations.</span>+ <Button+ variant="outline"+ size="xs"+ onClick={() => void props.source.refresh()}+ >+ Try again+ </Button>+ </div>+ </Show></Match></Switch><divdiff --git a/apps/web/src/features/channels-view/components/rail/ChannelsRail.tsx b/apps/web/src/features/channels-view/components/rail/ChannelsRail.tsxindex da0d2b11e3..ed36b54c27 100644--- a/apps/web/src/features/channels-view/components/rail/ChannelsRail.tsx+++ b/apps/web/src/features/channels-view/components/rail/ChannelsRail.tsx@@ -10,7 +10,6 @@ import {withSplitPanelOwner,} from '@components/app/split-layout/layoutUtils';import { createHotkeyGroup, registerHotkey } from '@core/hotkey/hotkeys';-import { compareDateDesc } from '@core/util/date';import type { ChannelEntity } from '@entity';import {createEffect,@@ -20,9 +19,14 @@ import {on,onCleanup,} from 'solid-js';+import type { VirtualizerHandle } from 'virtua/solid';import { useChannelsView } from '../../channels-view-context';-import type { ChannelsGroup, ChannelsTab } from '../../types';-import { channelHasMessages, isDirectMessage } from '../../utils';+import { type ChannelsSources, deduplicateChannels } from '../../queries';+import type {+ ChannelsGroup,+ ChannelsQueryScope,+ ChannelsTab,+} from '../../types';import {type ChannelRailRow,type ChannelsRailContext,@@ -38,13 +42,79 @@ import { SlimChannelsRail } from './SlimChannelsRail';const CHANNEL_GROUPS: ChannelsGroup[] = ['channels', 'direct_messages'];const CHANNEL_TAB_IDS: ChannelsTab[] = ['browse', 'recents'];+const DM_LOADING_PREVIEW_OFFSET = 80;export type ChannelsRailProps = {- channels: ChannelEntity[];+ sources: ChannelsSources;mode: 'full' | 'slim';onModeChange: (mode: 'full' | 'slim') => void;};+type ChannelRailItemsByScope = Record<+ ChannelsQueryScope,+ readonly ChannelEntity[]+>;++export function buildChannelRailRows(+ tab: ChannelsTab,+ expandedGroups: Record<ChannelsGroup, boolean>,+ items: ChannelRailItemsByScope+): ChannelRailRow[] {+ if (tab === 'recents') {+ return items.recents.map((channel, localIndex) => ({+ kind: 'conversation',+ id: `channel:${channel.id}`,+ scope: 'recents',+ localIndex,+ channel,+ }));+ }++ const rows: ChannelRailRow[] = [+ {+ kind: 'section',+ id: 'section:channels',+ group: 'channels',+ },+ ];+ if (expandedGroups.channels) {+ rows.push(+ ...items.channels.map(+ (channel, localIndex): ChannelRailRow => ({+ kind: 'conversation',+ id: `channel:${channel.id}`,+ group: 'channels',+ scope: 'channels',+ localIndex,+ channel,+ })+ )+ );+ }++ rows.push({+ kind: 'section',+ id: 'section:direct_messages',+ group: 'direct_messages',+ });+ if (expandedGroups.direct_messages) {+ rows.push(+ ...items.direct_messages.map(+ (channel, localIndex): ChannelRailRow => ({+ kind: 'conversation',+ id: `channel:${channel.id}`,+ group: 'direct_messages',+ scope: 'direct_messages',+ localIndex,+ channel,+ })+ )+ );+ }++ return rows;+}+export function ChannelsRail(props: ChannelsRailProps) {const { state, setGroupOpen, setSelectedChannelId, setTab } =useChannelsView();@@ -54,80 +124,28 @@ export function ChannelsRail(props: ChannelsRailProps) {Partial<Record<ChannelsGroup, HTMLDivElement>>>({});const [listRoot, setListRoot] = createSignal<HTMLDivElement>();+ const [virtualizers, setVirtualizers] = createSignal<+ Partial<Record<ChannelsQueryScope, VirtualizerHandle>>+ >({});const channelCalls = useChannelCalls();- const channelActivity = useChannelRailActivity(- () => props.channels,- channelCalls+ const channels = createMemo(() =>+ deduplicateChannels([+ props.sources.channels.items(),+ props.sources.direct_messages.items(),+ props.sources.recents.items(),+ ]));+ const channelActivity = useChannelRailActivity(channels, channelCalls);- const teamChannels = createMemo(() =>- props.channels.filter((channel) => !isDirectMessage(channel))- );- const directMessages = createMemo(() =>- props.channels.filter(isDirectMessage)- );- const recentConversations = createMemo(() =>- props.channels- .filter(channelHasMessages)- .sort((a, b) =>- compareDateDesc(- a.latestRootMessage?.createdAt,- b.latestRootMessage?.createdAt- )- )+ const visibleRows = createMemo(() =>+ buildChannelRailRows(state.tab, state.expandedGroups, {+ channels: props.sources.channels.items(),+ direct_messages: props.sources.direct_messages.items(),+ recents: props.sources.recents.items(),+ }));- const visibleRows = createMemo<ChannelRailRow[]>(() => {- if (state.tab === 'recents') {- return recentConversations().map((channel) => ({- kind: 'conversation',- id: `channel:${channel.id}`,- channel,- }));- }-- const rows: ChannelRailRow[] = [- {- kind: 'section',- id: 'section:channels',- group: 'channels',- },- ];- if (state.expandedGroups.channels) {- rows.push(- ...teamChannels().map(- (channel): ChannelRailRow => ({- kind: 'conversation',- id: `channel:${channel.id}`,- group: 'channels',- channel,- })- )- );- }-- rows.push({- kind: 'section',- id: 'section:direct_messages',- group: 'direct_messages',- });- if (state.expandedGroups.direct_messages) {- rows.push(- ...directMessages().map(- (channel): ChannelRailRow => ({- kind: 'conversation',- id: `channel:${channel.id}`,- group: 'direct_messages',- channel,- })- )- );- }-- return rows;- });-const list = withSplitPanelOwner(listOwnedSlotName('controller'), () =>createListController<ChannelRailRow>({items: visibleRows,@@ -149,10 +167,18 @@ export function ChannelsRail(props: ChannelsRailProps) {);const scrollHandle: ListScrollHandle = {- scrollToIndex: (index) => {+ scrollToIndex: (index, options) => {const row = list.items.at(index);if (!row) return;+ if (row.kind === 'conversation') {+ const virtualizer = virtualizers()[row.scope];+ if (virtualizer) {+ virtualizer.scrollToIndex(row.localIndex, options);+ return;+ }+ }+const element = document.getElementById(domIdForRow(listDomId, row.id));const scrollRoot =row.kind === 'conversation' && row.group@@ -187,6 +213,44 @@ export function ChannelsRail(props: ChannelsRailProps) {scrollHandle: () => scrollHandle,enabled: panel.isPanelActive,navigation: {+ onBeforeMove: ({ direction, current }) => {+ const row = current?.item;+ if (direction !== 1 || row?.kind !== 'conversation') return true;++ const source = props.sources[row.scope];+ if (row.localIndex < source.items().length - 1) return true;++ if (!source.isLoadingMore()) {+ if (!source.hasMore()) return true;+ void source.loadMore();+ }++ if (row.scope === 'direct_messages') {+ requestAnimationFrame(() => {+ const scrollRoot = sectionScrollRoots().direct_messages;+ const element = document.getElementById(+ domIdForRow(listDomId, row.id)+ );+ if (!scrollRoot || !element) return;++ const scrollBounds = scrollRoot.getBoundingClientRect();+ const elementBounds = element.getBoundingClientRect();+ const previewOffset = Math.max(+ 0,+ Math.min(+ DM_LOADING_PREVIEW_OFFSET,+ scrollBounds.height - elementBounds.height+ )+ );+ scrollRoot.scrollTop += Math.max(+ 0,+ elementBounds.bottom + previewOffset - scrollBounds.bottom+ );+ });+ }++ return false;+ },onNavigate: (event) => {listRoot()?.focus({ preventScroll: true });@@ -267,15 +331,30 @@ export function ChannelsRail(props: ChannelsRailProps) {list.activate.key(rowId, { reason: 'pointer' });};+ const registerVirtualizer = (+ scope: ChannelsQueryScope,+ handle: VirtualizerHandle+ ) => {+ setVirtualizers((current) => ({ ...current, [scope]: handle }));++ return () => {+ setVirtualizers((current) => {+ if (current[scope] !== handle) return current;++ const next = { ...current };+ delete next[scope];+ return next;+ });+ };+ };+const rail: ChannelsRailContext = {railId: listDomId,list,tab: () => state.tab,selectTab: setTab,setMode: (mode) => props.onModeChange(mode),- teamChannels,- directMessages,- recentConversations,+ sources: props.sources,selectedChannelId: () => state.selectedChannelId,isGroupOpen: (group) => state.expandedGroups[group],registerRootRef: setListRoot,@@ -286,6 +365,7 @@ export function ChannelsRail(props: ChannelsRailProps) {[group]: element,}));},+ registerVirtualizer,channelActivity,};diff --git a/apps/web/src/features/channels-view/components/rail/ChannelsRailContext.ts b/apps/web/src/features/channels-view/components/rail/ChannelsRailContext.tsindex 3971961768..b44070fb63 100644--- a/apps/web/src/features/channels-view/components/rail/ChannelsRailContext.ts+++ b/apps/web/src/features/channels-view/components/rail/ChannelsRailContext.ts@@ -3,7 +3,13 @@ import { createAssertedContextProvider } from '@core/context/createContext';import type { ChannelEntity } from '@entity';import type { ContextProviderProps } from '@solid-primitives/context';import type { Accessor } from 'solid-js';-import type { ChannelsGroup, ChannelsTab } from '../../types';+import type { VirtualizerHandle } from 'virtua/solid';+import type { ChannelsSources } from '../../queries';+import type {+ ChannelsGroup,+ ChannelsQueryScope,+ ChannelsTab,+} from '../../types';import type { useChannelRailActivity } from './hooks/useChannelRailActivity';type ChannelRailActivity = ReturnType<typeof useChannelRailActivity>;@@ -18,6 +24,8 @@ export type ChannelRailRow =kind: 'conversation';id: `channel:${string}`;group?: ChannelsGroup;+ scope: ChannelsQueryScope;+ localIndex: number;channel: ChannelEntity;};@@ -36,14 +44,16 @@ export type ChannelsRailContext = {tab: Accessor<ChannelsTab>;selectTab: (tab: ChannelsTab) => void;setMode: (mode: 'full' | 'slim') => void;- teamChannels: Accessor<readonly ChannelEntity[]>;- directMessages: Accessor<readonly ChannelEntity[]>;- recentConversations: Accessor<readonly ChannelEntity[]>;+ sources: ChannelsSources;selectedChannelId: Accessor<string | undefined>;isGroupOpen: (group: ChannelsGroup) => boolean;registerRootRef: (element: HTMLDivElement) => void;activateRow: (rowId: ChannelRailRow['id']) => void;registerScrollRef: (group: ChannelsGroup, element: HTMLDivElement) => void;+ registerVirtualizer: (+ scope: ChannelsQueryScope,+ handle: VirtualizerHandle+ ) => () => void;channelActivity: ChannelRailActivity;};diff --git a/apps/web/src/features/channels-view/components/rail/ChannelsRailSection.tsx b/apps/web/src/features/channels-view/components/rail/ChannelsRailSection.tsxindex cbc2712498..cdadb37cb0 100644--- a/apps/web/src/features/channels-view/components/rail/ChannelsRailSection.tsx+++ b/apps/web/src/features/channels-view/components/rail/ChannelsRailSection.tsx@@ -3,10 +3,13 @@ import { AnimatedSquareSidebarIcon } from '@icon/square-sidebar';import CaretDownIcon from '@phosphor/caret-down.svg';import CaretUpIcon from '@phosphor/caret-up.svg';import PlusIcon from '@phosphor/plus.svg';+import SpinnerIcon from '@phosphor/spinner.svg';import { Button, cn, Scroll, Tooltip } from '@ui';-import { createSignal, type JSX, Match, Show, Switch } from 'solid-js';+import { createSignal, For, type JSX, Match, Show, Switch } from 'solid-js';import { useOffscreenActivity } from './hooks/useOffscreenActivity';+const LOADING_SKELETON_ROWS = [0, 1, 2];+function SectionScrollArea(props: {contentRef: (element: HTMLDivElement) => void;containerClass?: string;@@ -155,6 +158,79 @@ export const CollapsibleSection = {Content: CollapsibleSectionContent,};+export function RailListLoading() {+ return (+ <div class="grid min-h-20 place-items-center text-ink-muted">+ <SpinnerIcon+ aria-label="Loading conversations"+ class="size-4 animate-spin"+ />+ </div>+ );+}++export function RailListLoadingMore(props: {+ variant: 'channel' | 'recent' | 'slim';+}) {+ return (+ <div role="status" aria-label="Loading more conversations">+ <For each={LOADING_SKELETON_ROWS}>+ {(row) => (+ <div+ aria-hidden="true"+ class={cn(+ 'flex items-center',+ props.variant === 'slim' && 'h-10 justify-center',+ props.variant === 'channel' && 'h-10 gap-2 px-2',+ props.variant === 'recent' && 'h-18 items-start gap-3 px-2 py-2'+ )}+ >+ <div+ class={cn(+ 'skeleton-shimmer shrink-0 rounded-full bg-skeleton',+ props.variant === 'channel' && 'size-6',+ props.variant !== 'channel' && 'size-8'+ )}+ />+ <Show when={props.variant !== 'slim'}>+ <div class="flex min-w-0 flex-1 flex-col gap-2">+ <div+ class={cn(+ 'skeleton-shimmer h-2.5 rounded-full bg-skeleton',+ row % 2 === 0 ? 'w-1/2' : 'w-2/3'+ )}+ />+ <Show when={props.variant === 'recent'}>+ <div class="skeleton-shimmer h-2 w-4/5 rounded-full bg-skeleton" />+ </Show>+ </div>+ </Show>+ </div>+ )}+ </For>+ </div>+ );+}++export function RailListError(props: {+ retry: () => Promise<void>;+ compact?: boolean;+}) {+ return (+ <div+ class={cn(+ 'flex items-center justify-center gap-2 px-2 text-xs text-ink-muted',+ props.compact ? 'py-2' : 'min-h-20 flex-col'+ )}+ >+ <span>Couldn’t load conversations.</span>+ <Button variant="outline" size="xs" onClick={() => void props.retry()}>+ Try again+ </Button>+ </div>+ );+}+export function CreateRailAction(props: {label: string;onClick: () => void;diff --git a/apps/web/src/features/channels-view/components/rail/ExpandedChannelsRail.tsx b/apps/web/src/features/channels-view/components/rail/ExpandedChannelsRail.tsxindex 3f4d8c0bda..e0101f1f43 100644--- a/apps/web/src/features/channels-view/components/rail/ExpandedChannelsRail.tsx+++ b/apps/web/src/features/channels-view/components/rail/ExpandedChannelsRail.tsx@@ -6,9 +6,9 @@ import { useUserId } from '@core/context/user';import { isTouchDevice } from '@core/mobile/isTouchDevice';import type { ChannelEntity } from '@entity';import CaretDownIcon from '@phosphor/caret-down.svg';-import { Key } from '@solid-primitives/keyed';import { cn, Hotkey, Tabs } from '@ui';-import { For, Match, Show, Switch } from 'solid-js';+import { createSignal, For, Match, Show, Switch } from 'solid-js';+import { Virtualizer } from 'virtua/solid';import type { ChannelsGroup } from '../../types';import { channelMentionsUser, isDirectMessage } from '../../utils';import { ChannelsEmptyState } from '../ChannelsEmptyState';@@ -29,11 +29,16 @@ import {import {CollapsibleSection,CreateRailAction,+ RailListError,+ RailListLoading,+ RailListLoadingMore,RailModeButton,} from './ChannelsRailSection';import {useChannelRailItemState,+ useChannelRailScopeState,useChannelRailSectionState,+ useChannelRailVirtualizer,} from './hooks/useChannelRailState';const CHANNEL_TABS = [@@ -152,11 +157,15 @@ function ExpandedHeader() {function ExpandedGroupSection(props: { config: GroupConfig }) {const rail = useChannelsRail();+ const [scrollRoot, setScrollRoot] = createSignal<HTMLDivElement>();const { state: section, clearVisibleActivity } = useChannelRailSectionState(() => props.config.group);- const registerScrollRef = (element: HTMLDivElement) =>+ const pagination = useChannelRailVirtualizer(() => props.config.group);+ const registerScrollRef = (element: HTMLDivElement) => {+ setScrollRoot(element);rail.registerScrollRef(props.config.group, element);+ };return (<CollapsibleSection.Root@@ -206,10 +215,42 @@ function ExpandedGroupSection(props: { config: GroupConfig }) {onActivityVisible={clearVisibleActivity}><Switch>+ <Match+ when={section().source.isLoading() && section().items.length === 0}+ >+ <RailListLoading />+ </Match>+ <Match+ when={section().source.error() && section().items.length === 0}+ >+ <RailListError retry={section().source.refresh} />+ </Match><Match when={section().items.length > 0}>- <Key each={section().items} by={(channel) => channel.id}>- {(channel) => <ChannelOption channel={channel()} />}- </Key>+ <Virtualizer+ ref={pagination.registerVirtualizer}+ data={section().items}+ scrollRef={scrollRoot()}+ itemSize={props.config.group === 'channels' ? 34 : 42}+ bufferSize={240}+ keepMounted={section().keepMounted}+ onScroll={pagination.loadMoreNearEnd}+ >+ {(channel) => (+ <div class="pb-0.5">+ <ChannelOption channel={channel} />+ </div>+ )}+ </Virtualizer>+ <Show when={section().source.isLoadingMore()}>+ <RailListLoadingMore variant="channel" />+ </Show>+ <Show+ when={+ section().source.error() && !section().source.isLoadingMore()+ }+ >+ <RailListError retry={section().source.refresh} compact />+ </Show></Match><Match when={true}><div class="px-2 py-2 text-xs text-ink-extra-muted">@@ -228,11 +269,17 @@ function ExpandedBrowse() {DEBUG_SETTING_KEYS.FORCE_EMPTY_STATES);const hasItems = () =>- rail.teamChannels().length > 0 || rail.directMessages().length > 0;+ rail.sources.channels.items().length > 0 ||+ rail.sources.direct_messages.items().length > 0;+ const sourcesSettled = () =>+ !rail.sources.channels.isLoading() &&+ !rail.sources.direct_messages.isLoading() &&+ !rail.sources.channels.error() &&+ !rail.sources.direct_messages.error();return (<Switch>- <Match when={forceEmptyState() || !hasItems()}>+ <Match when={forceEmptyState() || (sourcesSettled() && !hasItems())}><ChannelsEmptyState scope="channels" topAligned /></Match><Match when={true}>@@ -255,6 +302,7 @@ function RecentConversationCard(props: { channel: ChannelEntity }) {<ChannelRailItemContextMenu channel={props.channel} class="block w-full"><ConversationCardid={item().domId}+ class="border-b border-edge-muted"channel={props.channel}senderId={props.channel.latestRootMessage?.senderId}mentionedCurrentUser={channelMentionsUser(@@ -274,23 +322,61 @@ function RecentConversationCard(props: { channel: ChannelEntity }) {}function ExpandedRecents() {- const rail = useChannelsRail();+ const [scrollRoot, setScrollRoot] = createSignal<HTMLDivElement>();+ const scope = useChannelRailScopeState(() => 'recents');+ const pagination = useChannelRailVirtualizer(() => 'recents');const forceEmptyState = useDebugSetting(DEBUG_SETTING_KEYS.FORCE_EMPTY_STATES);- const hasItems = () =>- !forceEmptyState() && rail.recentConversations().length > 0;return (<Switch>- <Match when={!hasItems()}>+ <Match+ when={+ !forceEmptyState() &&+ scope().source.isLoading() &&+ scope().items.length === 0+ }+ >+ <RailListLoading />+ </Match>+ <Match+ when={+ !forceEmptyState() &&+ scope().source.error() &&+ scope().items.length === 0+ }+ >+ <RailListError retry={scope().source.refresh} />+ </Match>+ <Match when={forceEmptyState() || scope().items.length === 0}><ChannelsEmptyState scope="recents" topAligned /></Match><Match when={true}>- <div class="flex w-full flex-col divide-y divide-edge-muted">- <Key each={rail.recentConversations()} by={(channel) => channel.id}>- {(channel) => <RecentConversationCard channel={channel()} />}- </Key>+ <div+ ref={setScrollRoot}+ class="scrollbar-hidden size-full min-h-0 overflow-y-auto"+ aria-busy={scope().source.isLoadingMore()}+ >+ <Virtualizer+ ref={pagination.registerVirtualizer}+ data={scope().items}+ scrollRef={scrollRoot()}+ itemSize={72}+ bufferSize={360}+ keepMounted={scope().keepMounted}+ onScroll={pagination.loadMoreNearEnd}+ >+ {(channel) => <RecentConversationCard channel={channel} />}+ </Virtualizer>+ <Show when={scope().source.isLoadingMore()}>+ <RailListLoadingMore variant="recent" />+ </Show>+ <Show+ when={scope().source.error() && !scope().source.isLoadingMore()}+ >+ <RailListError retry={scope().source.refresh} compact />+ </Show></div></Match></Switch>@@ -313,10 +399,7 @@ export function ExpandedChannelsRail() {role="tree"tabIndex={-1}aria-activedescendant={activeDescendant()}- class={cn(- 'scrollbar-hidden min-h-0 flex-1 outline-none',- rail.tab() === 'browse' ? 'overflow-hidden' : 'overflow-y-auto'- )}+ class="min-h-0 flex-1 overflow-hidden outline-none"><Switch><Match when={rail.tab() === 'browse'}>diff --git a/apps/web/src/features/channels-view/components/rail/SlimChannelsRail.tsx b/apps/web/src/features/channels-view/components/rail/SlimChannelsRail.tsxindex 0b6d48eee2..8bfa5a024b 100644--- a/apps/web/src/features/channels-view/components/rail/SlimChannelsRail.tsx+++ b/apps/web/src/features/channels-view/components/rail/SlimChannelsRail.tsx@@ -5,14 +5,22 @@ import { SplitPanel } from '@components/app/split-panel';import { isTouchDevice } from '@core/mobile/isTouchDevice';import { type ChannelEntity, Entity } from '@entity';import ChannelIcon from '@icon/wide-channel.svg';+import ArrowClockwiseIcon from '@phosphor/arrow-clockwise.svg';import ChatTeardropIcon from '@phosphor/chat-teardrop.svg';import ChatTextIcon from '@phosphor/chat-text.svg';import ChatsIcon from '@phosphor/chats-circle.svg';import PlusIcon from '@phosphor/plus.svg';-import { Key } from '@solid-primitives/keyed';-import { cn, Dropdown, Tabs, Tooltip } from '@ui';-import { type Component, For, Match, Show, Switch } from 'solid-js';+import { Button, cn, Dropdown, Tabs, Tooltip } from '@ui';+import {+ type Component,+ createSignal,+ For,+ Match,+ Show,+ Switch,+} from 'solid-js';import { Dynamic } from 'solid-js/web';+import { Virtualizer } from 'virtua/solid';import type { ChannelsGroup } from '../../types';import { channelInitials, isDirectMessage } from '../../utils';import {@@ -26,10 +34,17 @@ import {rowKeyForSection,useChannelsRail,} from './ChannelsRailContext';-import { CollapsibleSection, RailModeButton } from './ChannelsRailSection';+import {+ CollapsibleSection,+ RailListLoading,+ RailListLoadingMore,+ RailModeButton,+} from './ChannelsRailSection';import {useChannelRailItemState,+ useChannelRailScopeState,useChannelRailSectionState,+ useChannelRailVirtualizer,} from './hooks/useChannelRailState';function BrowseTabLabel() {@@ -74,6 +89,22 @@ const GROUPS: GroupConfig[] = [},];+function SlimListError(props: { retry: () => Promise<void> }) {+ return (+ <div class="flex min-h-10 items-center justify-center">+ <Button+ variant="outline"+ size="icon-sm"+ label="Retry loading conversations"+ tooltipPlacement="right"+ onClick={() => void props.retry()}+ >+ <ArrowClockwiseIcon class="size-4" />+ </Button>+ </div>+ );+}+function SlimChannelAvatar(props: { channel: ChannelEntity }) {return (<Switch>@@ -228,14 +259,18 @@ function SlimHeader() {function SlimGroupSection(props: { config: GroupConfig }) {const rail = useChannelsRail();+ const [scrollRoot, setScrollRoot] = createSignal<HTMLDivElement>();const forceEmptyState = useDebugSetting(DEBUG_SETTING_KEYS.FORCE_EMPTY_STATES);const { state: section, clearVisibleActivity } = useChannelRailSectionState(() => props.config.group);- const registerScrollRef = (element: HTMLDivElement) =>+ const pagination = useChannelRailVirtualizer(() => props.config.group);+ const registerScrollRef = (element: HTMLDivElement) => {+ setScrollRoot(element);rail.registerScrollRef(props.config.group, element);+ };return (<CollapsibleSection.Root@@ -277,11 +312,46 @@ function SlimGroupSection(props: { config: GroupConfig }) {activityTooltiponActivityVisible={clearVisibleActivity}>- <Show when={!forceEmptyState()}>- <Key each={section().items} by={(channel) => channel.id}>- {(channel) => <SlimChannelItem channel={channel()} />}- </Key>- </Show>+ <Switch>+ <Match when={forceEmptyState()}>{null}</Match>+ <Match+ when={section().source.isLoading() && section().items.length === 0}+ >+ <RailListLoading />+ </Match>+ <Match+ when={section().source.error() && section().items.length === 0}+ >+ <SlimListError retry={section().source.refresh} />+ </Match>+ <Match when={section().items.length > 0}>+ <Virtualizer+ ref={pagination.registerVirtualizer}+ data={section().items}+ scrollRef={scrollRoot()}+ itemSize={42}+ bufferSize={240}+ keepMounted={section().keepMounted}+ onScroll={pagination.loadMoreNearEnd}+ >+ {(channel) => (+ <div class="flex justify-center pb-0.5">+ <SlimChannelItem channel={channel} />+ </div>+ )}+ </Virtualizer>+ <Show when={section().source.isLoadingMore()}>+ <RailListLoadingMore variant="slim" />+ </Show>+ <Show+ when={+ section().source.error() && !section().source.isLoadingMore()+ }+ >+ <SlimListError retry={section().source.refresh} />+ </Show>+ </Match>+ </Switch></CollapsibleSection.Content></CollapsibleSection.Root>);@@ -298,21 +368,54 @@ function SlimBrowse() {}function SlimRecents() {- const rail = useChannelsRail();+ const [scrollRoot, setScrollRoot] = createSignal<HTMLDivElement>();+ const scope = useChannelRailScopeState(() => 'recents');+ const pagination = useChannelRailVirtualizer(() => 'recents');const forceEmptyState = useDebugSetting(DEBUG_SETTING_KEYS.FORCE_EMPTY_STATES);- const hasItems = () =>- !forceEmptyState() && rail.recentConversations().length > 0;return (- <Show when={hasItems()}>- <div class="flex w-full flex-col gap-0.5">- <Key each={rail.recentConversations()} by={(channel) => channel.id}>- {(channel) => <SlimChannelItem channel={channel()} />}- </Key>- </div>- </Show>+ <Switch>+ <Match when={forceEmptyState()}>{null}</Match>+ <Match when={scope().source.isLoading() && scope().items.length === 0}>+ <RailListLoading />+ </Match>+ <Match when={scope().source.error() && scope().items.length === 0}>+ <SlimListError retry={scope().source.refresh} />+ </Match>+ <Match when={scope().items.length > 0}>+ <div+ ref={setScrollRoot}+ class="scrollbar-hidden size-full min-h-0 overflow-y-auto"+ aria-busy={scope().source.isLoadingMore()}+ >+ <Virtualizer+ ref={pagination.registerVirtualizer}+ data={scope().items}+ scrollRef={scrollRoot()}+ itemSize={42}+ bufferSize={240}+ keepMounted={scope().keepMounted}+ onScroll={pagination.loadMoreNearEnd}+ >+ {(channel) => (+ <div class="flex justify-center pb-0.5">+ <SlimChannelItem channel={channel} />+ </div>+ )}+ </Virtualizer>+ <Show when={scope().source.isLoadingMore()}>+ <RailListLoadingMore variant="slim" />+ </Show>+ <Show+ when={scope().source.error() && !scope().source.isLoadingMore()}+ >+ <SlimListError retry={scope().source.refresh} />+ </Show>+ </div>+ </Match>+ </Switch>);}@@ -332,10 +435,7 @@ export function SlimChannelsRail() {role="tree"tabIndex={-1}aria-activedescendant={activeDescendant()}- class={cn(- 'scrollbar-hidden min-h-0 flex-1 outline-none',- rail.tab() === 'browse' ? 'overflow-hidden' : 'overflow-y-auto'- )}+ class="min-h-0 flex-1 overflow-hidden outline-none"><Switch><Match when={rail.tab() === 'browse'}>diff --git a/apps/web/src/features/channels-view/components/rail/hooks/useChannelRailActivity.ts b/apps/web/src/features/channels-view/components/rail/hooks/useChannelRailActivity.tsindex 098d8e2f18..9d900aa3d4 100644--- a/apps/web/src/features/channels-view/components/rail/hooks/useChannelRailActivity.ts+++ b/apps/web/src/features/channels-view/components/rail/hooks/useChannelRailActivity.ts@@ -22,7 +22,7 @@ type ChannelActivityTarget = {};export function useChannelRailActivity(- channels: Accessor<ChannelEntity[]>,+ channels: Accessor<readonly ChannelEntity[]>,calls: ReturnType<typeof useChannelCalls>) {const notificationSource = useGlobalNotificationSource();diff --git a/apps/web/src/features/channels-view/components/rail/hooks/useChannelRailState.ts b/apps/web/src/features/channels-view/components/rail/hooks/useChannelRailState.tsindex 70fd19ffab..4f262b857d 100644--- a/apps/web/src/features/channels-view/components/rail/hooks/useChannelRailState.ts+++ b/apps/web/src/features/channels-view/components/rail/hooks/useChannelRailState.ts@@ -1,7 +1,8 @@import { useGlobalNotificationSource } from '@components/app/GlobalAppState';import { isMutedItem } from '@entity/utils/notification';-import { type Accessor, createMemo } from 'solid-js';-import type { ChannelsGroup } from '../../../types';+import { type Accessor, createMemo, createSignal, onCleanup } from 'solid-js';+import type { VirtualizerHandle } from 'virtua/solid';+import type { ChannelsGroup, ChannelsQueryScope } from '../../../types';import {domIdForRow,rowKeyForChannel,@@ -9,6 +10,8 @@ import {useChannelsRail,} from '../ChannelsRailContext';+const LOAD_MORE_THRESHOLD = 300;+export function useChannelRailItemState(channelId: Accessor<string>) {const rail = useChannelsRail();const notificationSource = useGlobalNotificationSource();@@ -32,16 +35,88 @@ export function useChannelRailItemState(channelId: Accessor<string>) {});}+export function useChannelRailScopeState(scope: Accessor<ChannelsQueryScope>) {+ const rail = useChannelsRail();++ return createMemo(() => {+ const currentScope = scope();+ const source = rail.sources[currentScope];+ const items = source.items();+ const focusedRow = rail.list.focus.item();+ const focusedIndex =+ focusedRow?.kind === 'conversation' && focusedRow.scope === currentScope+ ? focusedRow.localIndex+ : -1;+ const targetChannelId =+ currentScope === 'recents'+ ? undefined+ : rail.channelActivity.targetChannelId(currentScope);+ const activityIndex =+ targetChannelId === undefined+ ? -1+ : items.findIndex((channel) => channel.id === targetChannelId);+ const keepMounted = [...new Set([focusedIndex, activityIndex])].filter(+ (index) => index >= 0+ );++ return {+ items,+ source,+ focusedIndex,+ activityIndex,+ keepMounted: keepMounted.length > 0 ? keepMounted : undefined,+ };+ });+}++export function useChannelRailVirtualizer(scope: Accessor<ChannelsQueryScope>) {+ const rail = useChannelsRail();+ const [virtualizer, setVirtualizer] = createSignal<VirtualizerHandle>();+ let unregister: (() => void) | undefined;++ const registerVirtualizer = (handle?: VirtualizerHandle) => {+ unregister?.();+ unregister = undefined;+ setVirtualizer(handle);++ if (handle) {+ unregister = rail.registerVirtualizer(scope(), handle);+ }+ };++ onCleanup(() => unregister?.());++ const loadMoreNearEnd = (offset?: number) => {+ const handle = virtualizer();+ if (!handle) return;++ const source = rail.sources[scope()];+ const distance =+ handle.scrollSize - handle.viewportSize - (offset ?? handle.scrollOffset);+ if (+ distance >= LOAD_MORE_THRESHOLD ||+ source.isLoadingMore() ||+ !source.hasMore()+ ) {+ return;+ }++ void source.loadMore();+ };++ return { registerVirtualizer, loadMoreNearEnd };+}+export function useChannelRailSectionState(group: Accessor<ChannelsGroup>) {const rail = useChannelsRail();+ const scope = useChannelRailScopeState(group);const state = createMemo(() => {const section = group();const rowId = rowKeyForSection(section);const targetChannelId = rail.channelActivity.targetChannelId(section);return {- items:- section === 'channels' ? rail.teamChannels() : rail.directMessages(),+ ...scope(),open: rail.isGroupOpen(section),fillAvailable:section === 'direct_messages' && !rail.isGroupOpen('channels'),diff --git a/apps/web/src/features/channels-view/queries.ts b/apps/web/src/features/channels-view/queries.tsindex e4d16d11af..26fb06ae91 100644--- a/apps/web/src/features/channels-view/queries.ts+++ b/apps/web/src/features/channels-view/queries.ts@@ -1,21 +1,21 @@+import type { ListDataSource } from '@app/components/list';import {compileToAst,defineQueryFilters,queryStateFrom,} from '@app/features/next-soup/filters/filter-store';-import type { ChannelEntity } from '@entity';+import { type ChannelEntity, type EntityData, isChannelEntity } from '@entity';import {type SoupAstItemsQueryArgs,type SoupAstParams,useSoupAstItemsQuery,} from '@queries/soup/items';-import type { Accessor } from 'solid-js';+import { type Accessor, createMemo } from 'solid-js';import type { ChannelsQueryScope } from './types';import { channelHasMessages, isDirectMessage } from './utils';const CHANNELS_QUERY_PARAMS = {limit: 100,- sort_method: 'updated_at',} satisfies SoupAstParams;type ChannelsQueryDefinition = {@@ -24,9 +24,13 @@ type ChannelsQueryDefinition = {matches: (channel: ChannelEntity) => boolean;};+export type ChannelsDataSource = ListDataSource<ChannelEntity>;++export type ChannelsSources = Record<ChannelsQueryScope, ChannelsDataSource>;+export const CHANNELS_QUERY_DEFINITIONS = {recents: {- params: CHANNELS_QUERY_PARAMS,+ params: { ...CHANNELS_QUERY_PARAMS, sort_method: 'updated_at' },filters: defineQueryFilters({include: {channelImportance: true,@@ -36,7 +40,7 @@ export const CHANNELS_QUERY_DEFINITIONS = {matches: channelHasMessages,},channels: {- params: CHANNELS_QUERY_PARAMS,+ params: { ...CHANNELS_QUERY_PARAMS, sort_method: 'created_at' },filters: defineQueryFilters({include: { channelIsParticipant: [true] },exclude: { channelType: ['direct_message'] },@@ -44,7 +48,7 @@ export const CHANNELS_QUERY_DEFINITIONS = {matches: (channel) => !isDirectMessage(channel),},direct_messages: {- params: CHANNELS_QUERY_PARAMS,+ params: { ...CHANNELS_QUERY_PARAMS, sort_method: 'created_at' },filters: defineQueryFilters({include: {channelType: ['direct_message'],@@ -68,14 +72,114 @@ export function channelsQueryArgs(export function filterChannelsForScope(scope: ChannelsQueryScope,- channels: ChannelEntity[]+ channels: readonly ChannelEntity[]): ChannelEntity[] {return channels.filter(CHANNELS_QUERY_DEFINITIONS[scope].matches);}-export function useChannelsQuery(scope: Accessor<ChannelsQueryScope>) {+export function channelByIdQueryArgs(channelId: string): SoupAstItemsQueryArgs {+ return {+ params: {+ ...CHANNELS_QUERY_PARAMS,+ limit: 1,+ sort_method: 'created_at',+ },+ body: compileToAst(+ queryStateFrom(+ defineQueryFilters({+ include: { channelId: [channelId] },+ })+ )+ ),+ };+}++export function deduplicateChannels(+ collections: readonly (readonly ChannelEntity[])[]+): ChannelEntity[] {+ const channelsById = new Map<string, ChannelEntity>();++ for (const channels of collections) {+ for (const channel of channels) {+ if (!channelsById.has(channel.id)) {+ channelsById.set(channel.id, channel);+ }+ }+ }++ return [...channelsById.values()];+}++export function resolveSelectedChannel(+ selectedChannelId: string | undefined,+ loadedChannels: readonly ChannelEntity[],+ fallbackEntities: readonly EntityData[] = []+): ChannelEntity | undefined {+ if (selectedChannelId === undefined) return;++ return (+ loadedChannels.find((channel) => channel.id === selectedChannelId) ??+ fallbackEntities.find(+ (entity): entity is ChannelEntity =>+ isChannelEntity(entity) && entity.id === selectedChannelId+ )+ );+}++function useChannelsDataSource(+ scope: ChannelsQueryScope,+ enabled: Accessor<boolean>+): ChannelsDataSource {+ const query = useSoupAstItemsQuery(+ () => channelsQueryArgs(scope),+ () => ({ enabled: enabled(), staleTime: 30_000 })+ );+ const items = createMemo<ChannelEntity[]>((previous) => {+ if (!query.isEnabled || query.isLoading) return previous;++ const channels = (query.data?.entities ?? []).filter(isChannelEntity);+ return filterChannelsForScope(scope, channels);+ }, []);++ return {+ items,+ isLoading: () => query.isEnabled && query.isLoading && items().length === 0,+ isFetching: () => query.isEnabled && query.isFetching,+ error: () => (query.isEnabled ? (query.error ?? undefined) : undefined),+ hasMore: () => query.isEnabled && query.hasNextPage,+ isLoadingMore: () => query.isEnabled && query.isFetchingNextPage,+ loadMore: async () => {+ if (!query.isEnabled || query.isFetchingNextPage || !query.hasNextPage) {+ return;+ }++ await query.fetchNextPage();+ },+ refresh: async () => {+ if (!query.isEnabled) return;+ await query.refresh();+ },+ };+}++export function useChannelsSources(+ enabled: (scope: ChannelsQueryScope) => boolean+): ChannelsSources {+ return {+ channels: useChannelsDataSource('channels', () => enabled('channels')),+ direct_messages: useChannelsDataSource('direct_messages', () =>+ enabled('direct_messages')+ ),+ recents: useChannelsDataSource('recents', () => enabled('recents')),+ };+}++export function useChannelByIdQuery(+ channelId: Accessor<string | undefined>,+ enabled: Accessor<boolean>+) {return useSoupAstItemsQuery(- () => channelsQueryArgs(scope()),- () => ({ staleTime: 30_000 })+ () => channelByIdQueryArgs(channelId() ?? ''),+ () => ({ enabled: enabled(), staleTime: 30_000 }));}diff --git a/docs/AGENT_GUIDE/channels.md b/docs/AGENT_GUIDE/channels.mdindex bcdfb15690..96692eda58 100644--- a/docs/AGENT_GUIDE/channels.md+++ b/docs/AGENT_GUIDE/channels.md@@ -86,6 +86,22 @@ A touch tap leaves pending navigation intact; a vertical finger drag cancels it.The `[data-channel-scroll]` element is the scroll surface. Its virtualized rows arekeyed by message ID; offscreen rows are normally absent from the DOM.+## Chat navigation rail++On desktop, the Chat rail has `Browse` and `Recents` tabs. Browse contains+independently paginated `Channels` and `DMs` sections; collapsing a section+does not discard its loaded pages. Recents has its own pagination cursor.+Each list is virtualized, so offscreen conversations may not exist in the DOM.++Arrow Down / `j` at the last loaded conversation holds focus while that+section loads its next page. Once loading finishes, the next press advances+into the appended rows. If the section has no next page, navigation proceeds+to the next section. `[` and `]` jump between the Channels and DMs section+headers.++On touch layouts, the `Recents`, `Channels`, and `DMs` pill tabs each retain+their own loaded pages and load more as their active list approaches the end.+## Channel tabsRadio group at the top of the channel pane: `Messages` / `Attachments` / `Participants`,