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
fix(web): connect mobile dock search to channel results (#7119)
Sean Aye4a98c07375bd
diff --git a/apps/web/src/features/channels-view/channels-view.test.tsx b/apps/web/src/features/channels-view/channels-view.test.tsxindex d49d60f8d7..328b833051 100644--- a/apps/web/src/features/channels-view/channels-view.test.tsx+++ b/apps/web/src/features/channels-view/channels-view.test.tsx@@ -7,20 +7,38 @@ import {screen,waitFor,} from '@solidjs/testing-library';-import { batch, createSignal, type JSX, Show } from 'solid-js';+import { batch, createSignal, For, type JSX, Show } from 'solid-js';import { createStore } from 'solid-js/store';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';+import type { ChannelsDataSource } from './queries';+import type { ChannelsQueryScope } from './types';+type FullChannel = ChannelEntity & { notifications: Notification[] };const mocks = vi.hoisted(() => ({pass: (props: { children?: JSX.Element }) => props.children,selectedId: (): string | undefined => undefined,rows: (): ChannelEntity[] => [],+ mobileLayout: (): boolean => false,+ active: (): boolean => true,+ searchOpen: (): boolean => false,+ searchText: (): string => '',+ mobileTab: (): ChannelsQueryScope => 'channels',selectedQuery: vi.fn(),markRead: vi.fn(),refresh: vi.fn(async () => {}),}));+vi.mock('@app/features/command/mobile/mobileSearchState', () => ({+ SearchState: {+ isOpen: () => mocks.searchOpen(),+ query: () => mocks.searchText(),+ },+}));+vi.mock('@queries/soup/search', () => ({+ useSearchSoupQuery: () => ({ isSuccess: false, isLoading: false }),+ validateSearchServiceText: (text: string) => text.length >= 3,+}));vi.mock('@app/lib/split-router', () => ({SplitRouter: {Outlet: (props: { fallback: () => JSX.Element }) => (@@ -64,7 +82,9 @@ vi.mock('@components/app/PreviewPanel', () => ({),}));vi.mock('@components/app/split-layout/layoutUtils', () => ({- useSplitPanelOrThrow: () => ({ handle: { setDisplayName: vi.fn() } }),+ useSplitPanelOrThrow: () => ({+ handle: { setDisplayName: vi.fn(), isActive: () => mocks.active() },+ }),}));vi.mock('@components/app/split-panel', () => ({SplitPanel: { Root: mocks.pass, Body: mocks.pass },@@ -83,7 +103,16 @@ vi.mock('./components/ChannelDetailView', () => ({),}));vi.mock('./components/ChannelsMobileView', () => ({- ChannelsMobileView: () => null,+ ChannelsMobileView: (props: {+ source: ChannelsDataSource;+ searchText: string;+ }) => (+ <div data-testid="mobile-channels" data-query={props.searchText}>+ <For each={props.source.items()}>+ {(channel) => <div>{channel.name}</div>}+ </For>+ </div>+ ),}));vi.mock('./components/rail/ChannelsRail', () => ({ ChannelsRail: () => null }));vi.mock('./channels-view-context', () => ({@@ -92,10 +121,12 @@ vi.mock('./channels-view-context', () => ({state: {asideWidth: 256,tab: 'browse',- mobileTab: 'channels',+ get mobileTab() {+ return mocks.mobileTab();+ },sortBy: { channels: 'updated_at', direct_messages: 'updated_at' },},- mobileLayout: () => false,+ mobileLayout: () => mocks.mobileLayout(),selectedChannel: () =>mocks.selectedId()? { type: 'channel', id: mocks.selectedId() }@@ -118,7 +149,7 @@ vi.mock('./queries', () => ({useChannelByIdQuery: mocks.selectedQuery,useChannelsSources: () => ({channels: { items: () => mocks.rows() },- direct_messages: { items: () => [] },+ direct_messages: { items: () => mocks.rows() },recents: { items: () => [] },search: { items: () => [] },}),@@ -168,6 +199,11 @@ let setRows: ReturnType<typeof createSignal<ChannelEntity[]>>[1];beforeEach(() => {vi.clearAllMocks();+ mocks.mobileLayout = () => false;+ mocks.active = () => true;+ mocks.searchOpen = () => false;+ mocks.searchText = () => '';+ mocks.mobileTab = () => 'channels';[mocks.selectedId, setSelectedId] = createSignal<string | undefined>('one');[mocks.rows, setRows] = createSignal([row('one', 'new'), row('two')]);const [query, update] = createStore<QueryState>({@@ -198,6 +234,39 @@ beforeEach(() => {});afterEach(cleanup);+describe('mobile dock search wiring', () => {+ it('filters DMs from the active dock session and restores rows on close or navigation', () => {+ mocks.mobileLayout = () => true;+ mocks.mobileTab = () => 'direct_messages';+ const [open, setOpen] = createSignal(true);+ const [text, setText] = createSignal('');+ const [active, setActive] = createSignal(true);+ mocks.searchOpen = open;+ mocks.searchText = text;+ mocks.active = active;+ setRows([+ {+ ...row('julia'),+ name: 'Julia Westphal',+ channelType: 'direct_message',+ },+ { ...row('hutch'), name: 'hutch', channelType: 'direct_message' },+ ]);+ render(() => <ChannelsView />);+ expect(screen.getByText('hutch')).toBeTruthy();+ setText('Julia');+ expect(screen.getByText('Julia Westphal')).toBeTruthy();+ expect(screen.queryByText('hutch')).toBeNull();+ setActive(false);+ expect(screen.getByText('hutch')).toBeTruthy();+ setActive(true);+ expect(screen.queryByText('hutch')).toBeNull();+ setOpen(false);+ expect(screen.getByText('hutch')).toBeTruthy();+ expect(screen.getByTestId('mobile-channels').dataset.query).toBe('');+ });+});+describe('channel selection loading and recovery', () => {it('offers recovery for a successful empty selection and retries normally', async () => {render(() => <ChannelsView />);diff --git a/apps/web/src/features/channels-view/channels-view.tsx b/apps/web/src/features/channels-view/channels-view.tsxindex 45d1a3dd96..4432567335 100644--- a/apps/web/src/features/channels-view/channels-view.tsx+++ b/apps/web/src/features/channels-view/channels-view.tsx@@ -1,4 +1,5 @@import { ViewShell } from '@app/components/view-shell';+import { SearchState } from '@app/features/command/mobile/mobileSearchState';import { markChannelNotificationsSeenOnOpen } from '@app/features/next-soup/utils';import { MaybeSoupEntityActionDrawerManager } from '@app/features/soup';import { withEntityNotifications } from '@app/features/soup/entity-notifications';@@ -25,22 +26,52 @@ import { ChannelDetailView } from './components/ChannelDetailView';import { ChannelsMobileView } from './components/ChannelsMobileView';import { ChannelsRail } from './components/rail/ChannelsRail';import {+ type ChannelsSources,deduplicateChannels,resolveSelectedChannel,useChannelByIdQuery,useChannelsSources,} from './queries';+import { useMobileChannelSearch } from './queries/mobile-channel-search';const ChannelSourcesContext =createContext<ReturnType<typeof useChannelsSources>>();-import type { ChannelsViewStateOptions } from './types';+import type { ChannelsQueryScope, ChannelsViewStateOptions } from './types';export type ChannelsViewProps = {/** Explicit navigation state. When present, it wins over entry restoration. */initialState?: ChannelsViewStateOptions;};+function MobileChannels(props: {+ sources: ChannelsSources;+ tab: ChannelsQueryScope;+ onTabChange: (tab: ChannelsQueryScope) => void;+}) {+ const panel = useSplitPanelOrThrow();+ // The dock lives outside the split. Derive its query only for the active+ // mobile list so closing search or navigating away restores ordinary rows.+ const searchText = () =>+ SearchState.isOpen() && panel.handle.isActive()+ ? SearchState.query().trim()+ : '';+ const source = useMobileChannelSearch({+ text: searchText,+ scope: () => props.tab,+ source: () => props.sources[props.tab],+ });++ return (+ <ChannelsMobileView+ source={source}+ tab={props.tab}+ onTabChange={props.onTabChange}+ searchText={searchText()}+ />+ );+}+function ChannelsViewRoot() {const panel = useSplitPanelOrThrow();const { state, mobileLayout, selectedChannel, setAsideWidth, setMobileTab } =@@ -133,8 +164,8 @@ function ChannelsViewRoot() {</div>}>- <ChannelsMobileView- source={sources[state.mobileTab]}+ <MobileChannels+ sources={sources}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 26a6c15391..2464dec47d 100644--- a/apps/web/src/features/channels-view/components/ChannelsMobileView.tsx+++ b/apps/web/src/features/channels-view/components/ChannelsMobileView.tsx@@ -10,17 +10,20 @@ import { SplitHeaderLeft } from '@components/app/split-layout/components/SplitHeimport { useSplitPanelOrThrow } from '@components/app/split-layout/layoutUtils';import { toast } from '@core/component/Toast/Toast';import { useUserId } from '@core/context/user';+import EmptyStateNoSearchMatchGraphic from '@design/empty-state-no-search-match.svg';import type { ChannelEntity } from '@entity';import { isMutedItem } from '@entity/utils/notification';import SpinnerIcon from '@phosphor/spinner.svg';import { hydrateChannelNotificationSelection } from '@queries/channel/notification-selection';import { createElementSize } from '@solid-primitives/resize-observer';-import { Button } from '@ui';+import { Button, EmptyStatePanel } from '@ui';import {+ createEffect,createMemo,createSignal,createUniqueId,Match,+ on,onCleanup,Show,Switch,@@ -53,6 +56,7 @@ export function ChannelsMobileView(props: {source: ChannelsDataSource;tab: ChannelsQueryScope;onTabChange: (tab: ChannelsQueryScope) => void;+ searchText?: string;}) {const panel = useSplitPanelOrThrow();const notificationSource = useGlobalNotificationSource();@@ -83,6 +87,13 @@ export function ChannelsMobileView(props: {viewport()?.scrollTo({ top: 0 });};+ createEffect(+ on(+ () => props.searchText,+ () => viewport()?.scrollTo({ top: 0 })+ )+ );+const topInset = () => topSpacerSize.height ?? 0;function loadNextPage() {@@ -195,7 +206,24 @@ export function ChannelsMobileView(props: {</div></Match><Match when={forceEmptyState() || visibleChannels().length === 0}>- <ChannelsEmptyState scope={props.tab} />+ <Show+ when={props.searchText}+ fallback={<ChannelsEmptyState scope={props.tab} />}+ >+ <EmptyStatePanel+ centered+ graphic={EmptyStateNoSearchMatchGraphic}+ title="No results"+ description={+ <span>+ No conversations match{' '}+ <span class="[overflow-wrap:anywhere]">+ “{props.searchText}”+ </span>+ </span>+ }+ />+ </Show></Match><Match when={true}><Virtualizerdiff --git a/apps/web/src/features/channels-view/queries/mobile-channel-search.test.ts b/apps/web/src/features/channels-view/queries/mobile-channel-search.test.tsnew file mode 100644index 0000000000..4c43c3b331--- /dev/null+++ b/apps/web/src/features/channels-view/queries/mobile-channel-search.test.ts@@ -0,0 +1,379 @@+import type { ChannelEntity } from '@entity/types/entity';+import type { SearchSoupQueryArgs } from '@queries/soup/search';+import { createRoot, createSignal } from 'solid-js';+import { createStore } from 'solid-js/store';+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';+import type { ChannelsQueryScope } from '../types';++const mocks = vi.hoisted(() => ({ search: vi.fn() }));+vi.mock('@queries/soup/search', () => ({+ useSearchSoupQuery: mocks.search,+ validateSearchServiceText: (text: string) => text.length >= 3,+}));+vi.mock('@queries/soup/items', () => ({ useSoupAstItemsQuery: vi.fn() }));+vi.mock('@entity', () => ({+ isChannelEntity: (entity: { type: string }) => entity.type === 'channel',+}));++import { useMobileChannelSearch } from './mobile-channel-search';++const channel = (+ id: string,+ name: string,+ channelType: ChannelEntity['channelType'] = 'direct_message'+): ChannelEntity => ({+ id,+ name,+ channelType,+ type: 'channel',+ ownerId: 'viewer',+});++const julia = channel('julia', 'Julia Westphal');+const hutch = channel('hutch', 'hutch');+let dispose: () => void;++beforeEach(() => {+ vi.useFakeTimers();+ vi.clearAllMocks();+});+afterEach(() => {+ dispose?.();+ vi.useRealTimers();+});++function setup(initialText = '') {+ return createRoot((rootDispose) => {+ dispose = rootDispose;+ const [text, setText] = createSignal(initialText);+ const [scope, setScope] =+ createSignal<ChannelsQueryScope>('direct_messages');+ const [rows, setRows] = createSignal<ChannelEntity[]>([julia, hutch]);+ const [sourceFetching, setSourceFetching] = createSignal(false);+ const [sourceError, setSourceError] = createSignal<Error>();+ const [state, setState] = createStore({+ isSuccess: false,+ isLoading: false,+ isFetching: false,+ isFetchingNextPage: false,+ isPlaceholderData: false,+ hasNextPage: false,+ error: null as Error | null,+ data: [] as ChannelEntity[],+ });+ const fetchNextPage = vi.fn(async () => {});+ const refetch = vi.fn(async () => {});+ let args: () => SearchSoupQueryArgs;+ let enabled: () => { enabled: boolean };+ mocks.search.mockImplementation((getArgs, getOptions) => {+ args = getArgs;+ enabled = getOptions;+ return {+ get isSuccess() {+ return state.isSuccess;+ },+ get isLoading() {+ return state.isLoading;+ },+ get isFetching() {+ return state.isFetching;+ },+ get isFetchingNextPage() {+ return state.isFetchingNextPage;+ },+ get isPlaceholderData() {+ return state.isPlaceholderData;+ },+ get hasNextPage() {+ return state.hasNextPage;+ },+ get error() {+ return state.error;+ },+ get isEnabled() {+ return enabled().enabled;+ },+ get data() {+ if (!state.isSuccess)+ throw new Error('Pending data read would suspend');+ return state.data;+ },+ fetchNextPage,+ refetch,+ };+ });+ const source = {+ items: rows,+ isLoading: () => false,+ isFetching: sourceFetching,+ isLoadingMore: () => false,+ hasMore: () => true,+ error: sourceError,+ loadMore: vi.fn(async () => {}),+ refresh: vi.fn(async () => {}),+ };+ const result = useMobileChannelSearch({+ text,+ scope,+ source: () => source,+ });+ return {+ result,+ source,+ setText,+ setScope,+ setRows,+ setSourceFetching,+ setSourceError,+ setState,+ fetchNextPage,+ refetch,+ args: () => args(),+ enabled: () => enabled().enabled,+ };+ });+}++describe('mobile channel search', () => {+ it('filters loaded DMs immediately and never reads disabled/pending data', () => {+ const test = setup();+ expect(test.result.items()).toEqual([julia, hutch]);+ test.setText(' JU ');+ expect(test.result.items()).toEqual([julia]);+ expect(test.enabled()).toBe(false);+ expect(test.result.isLoading()).toBe(false);+ test.setText('Julia');+ expect(test.result.items()).toEqual([julia]);+ expect(test.enabled()).toBe(false);+ });++ it('searches beyond the loaded page with a debounced participant-only name query', async () => {+ const test = setup();+ test.setRows([hutch]);+ test.setText(' Julia ');+ expect(test.result.items()).toEqual([]);+ expect(test.result.isLoading()).toBe(true);+ await vi.advanceTimersByTimeAsync(300);+ expect(test.enabled()).toBe(true);+ expect(test.args().body).toMatchObject({+ query: 'Julia',+ search_on: 'name',+ match_type: 'partial',+ filters: {+ channel_filters: {+ is_participant: true,+ channel_types: ['direct_message'],+ },+ document_filters: {+ document_ids: ['00000000-0000-0000-0000-000000000000'],+ },+ },+ });+ test.setState({ isSuccess: true, data: [julia] });+ expect(test.result.items()).toEqual([julia]);+ expect(test.result.isLoading()).toBe(false);+ });++ it('deduplicates remote hits while retaining the loaded row metadata', () => {+ const test = setup('Julia');+ test.setRows([{ ...julia, participantIds: ['viewer', 'julia-user'] }]);+ test.setState({+ isSuccess: true,+ data: [julia, channel('julian', 'Julian')],+ });+ expect(test.result.items().map((row) => row.id)).toEqual([+ 'julia',+ 'julian',+ ]);+ expect(test.result.items()[0].participantIds).toEqual([+ 'viewer',+ 'julia-user',+ ]);+ });++ it('changes tab filters and excludes placeholder results from the previous tab', () => {+ const test = setup('Julia');+ test.setState({ isSuccess: true, data: [julia] });+ test.setRows([]);+ test.setScope('channels');+ test.setState('isPlaceholderData', true);+ expect(test.result.items()).toEqual([]);+ expect(test.args().body.filters?.channel_filters?.channel_types).toEqual([+ 'public',+ 'private',+ 'team',+ ]);+ const team = channel('team', 'Julia project', 'team');+ test.setState({ isPlaceholderData: false, data: [team, julia] });+ expect(test.result.items()).toEqual([team]);+ test.setScope('recents');+ expect(+ test.args().body.filters?.channel_filters?.channel_types+ ).toBeUndefined();+ expect(test.result.items()).toEqual([team, julia]);+ });++ it('shows loading instead of an empty state while replacing placeholder results', () => {+ const test = setup('Julia');+ test.setRows([]);+ test.setState({+ isSuccess: true,+ isFetching: true,+ isPlaceholderData: true,+ data: [hutch],+ });+ expect(test.result.items()).toEqual([]);+ expect(test.result.isLoading()).toBe(true);+ test.setState({+ isFetching: false,+ isPlaceholderData: false,+ data: [],+ });+ expect(test.result.isLoading()).toBe(false);+ });++ it('hides stale hits during debounce and placeholder data after changing the text', async () => {+ const test = setup('Julia');+ test.setState({ isSuccess: true, data: [julia], hasNextPage: true });+ test.setText('hutch');+ expect(test.result.items()).toEqual([hutch]);+ expect(test.result.hasMore()).toBe(false);+ test.setState('isPlaceholderData', true);+ await vi.advanceTimersByTimeAsync(300);+ expect(test.result.items()).toEqual([hutch]);+ expect(test.result.hasMore()).toBe(false);+ test.setText('zzzzzz');+ test.setState({ isSuccess: false, isPlaceholderData: false });+ await vi.advanceTimersByTimeAsync(300);+ expect(test.result.items()).toEqual([]);+ });++ it('paginates search results without discarding hits and restores browse pagination on clear', async () => {+ const test = setup('Julia');+ test.setState({ isSuccess: true, data: [julia], hasNextPage: true });+ await test.result.loadMore();+ expect(test.fetchNextPage).toHaveBeenCalledOnce();+ expect(test.source.loadMore).not.toHaveBeenCalled();+ test.setState({ isFetching: true, isFetchingNextPage: true });+ expect(test.result.items()).toEqual([julia]);+ expect(test.result.isLoadingMore()).toBe(true);+ await test.result.loadMore();+ expect(test.fetchNextPage).toHaveBeenCalledOnce();+ test.setText('');+ expect(test.result.items()).toEqual([julia, hutch]);+ await test.result.loadMore();+ expect(test.source.loadMore).toHaveBeenCalledOnce();+ });++ it('keeps search pagination available during a browse refetch and restores browse fetching on clear', async () => {+ const test = setup('Julia');+ test.setState({ isSuccess: true, data: [julia], hasNextPage: true });+ test.setSourceFetching(true);+ expect(test.source.isFetching()).toBe(true);+ expect(test.result.isFetching()).toBe(false);+ expect(test.result.hasMore()).toBe(true);+ await test.result.loadMore();+ expect(test.fetchNextPage).toHaveBeenCalledOnce();+ expect(test.source.loadMore).not.toHaveBeenCalled();++ test.setState({ isFetching: true, isFetchingNextPage: true });+ expect(test.result.isFetching()).toBe(true);+ expect(test.result.isLoadingMore()).toBe(true);+ await test.result.loadMore();+ expect(test.fetchNextPage).toHaveBeenCalledOnce();+ test.setState({ isFetching: false, isFetchingNextPage: false });+ expect(test.result.isFetching()).toBe(false);++ test.setText('');+ expect(test.result.isFetching()).toBe(true);+ test.setSourceFetching(false);+ expect(test.result.isFetching()).toBe(false);+ });++ it('reports search debounce and refetch activity but not browse activity for short queries', async () => {+ const test = setup();+ test.setText('Julia');+ expect(test.result.isFetching()).toBe(true);+ await vi.advanceTimersByTimeAsync(300);+ test.setState({ isSuccess: true, data: [julia], isFetching: true });+ expect(test.result.isFetching()).toBe(true);+ test.setState('isFetching', false);+ expect(test.result.isFetching()).toBe(false);++ test.setSourceFetching(true);+ test.setText('Ju');+ expect(test.result.isFetching()).toBe(false);+ expect(test.result.hasMore()).toBe(false);+ test.setText(' ');+ expect(test.result.isFetching()).toBe(true);+ });++ it.each([+ { name: 'no hits', hits: [] },+ { name: 'remote hits', hits: [julia] },+ ])(+ 'does not report a browse failure after a successful search with $name',+ ({ hits }) => {+ const test = setup('Julia');+ test.setRows([]);+ test.setSourceError(new Error('browse failed'));+ test.setState({ isSuccess: true, data: hits });++ expect(test.result.items()).toEqual(hits);+ expect(test.result.error()).toBeNull();+ }+ );++ it('hides browse errors during debounce and pending search, restoring them on clear', async () => {+ const test = setup();+ const browseError = new Error('browse failed');+ test.setSourceError(browseError);+ expect(test.result.error()).toBe(browseError);++ test.setText('Julia');+ expect(test.enabled()).toBe(false);+ expect(test.result.error()).toBeUndefined();+ await vi.advanceTimersByTimeAsync(300);+ test.setState('isFetching', true);+ expect(test.enabled()).toBe(true);+ expect(test.result.error()).toBeNull();++ test.setText('');+ expect(test.result.error()).toBe(browseError);+ });++ it('reports only the active source error and suppresses errors for local-only queries', () => {+ const test = setup('Julia');+ const browseError = new Error('browse failed');+ const searchError = new Error('search failed');+ test.setSourceError(browseError);+ test.setState('error', searchError);+ expect(test.result.error()).toBe(searchError);++ test.setText('Ju');+ expect(test.result.items()).toEqual([julia]);+ expect(test.result.error()).toBeUndefined();+ test.setText('Other query');+ expect(test.enabled()).toBe(false);+ expect(test.result.error()).toBeUndefined();+ test.setText(' ');+ expect(test.result.error()).toBe(browseError);+ test.setSourceError(undefined);+ expect(test.result.error()).toBeUndefined();+ });++ it('reports search failures without losing local hits and retries only valid searches', async () => {+ const test = setup('Julia');+ const error = new Error('offline');+ test.setState('error', error);+ expect(test.result.items()).toEqual([julia]);+ expect(test.result.error()).toBe(error);+ await test.result.refresh();+ expect(test.refetch).toHaveBeenCalledWith({ throwOnError: true });+ test.setText('Ju');+ expect(test.result.error()).toBeUndefined();+ await test.result.refresh();+ expect(test.refetch).toHaveBeenCalledOnce();+ expect(test.source.refresh).toHaveBeenCalledTimes(2);+ });+});diff --git a/apps/web/src/features/channels-view/queries/mobile-channel-search.ts b/apps/web/src/features/channels-view/queries/mobile-channel-search.tsnew file mode 100644index 0000000000..d44dafc2e6--- /dev/null+++ b/apps/web/src/features/channels-view/queries/mobile-channel-search.ts@@ -0,0 +1,126 @@+import { QUERY_FILTERS_BASE } from '@app/features/next-soup/filters/query-filters';+import { debouncedDependent } from '@core/util/debounce';+import { type ChannelEntity, isChannelEntity } from '@entity/types/entity';+import type { WithSearch } from '@entity/types/search';+import {+ useSearchSoupQuery,+ validateSearchServiceText,+} from '@queries/soup/search';+import { type Accessor, createMemo } from 'solid-js';+import { match } from 'ts-pattern';+import { type ChannelsDataSource, deduplicateChannels } from '../queries';+import type { ChannelsQueryScope } from '../types';++/** Name search supplements the active tab's loaded rows, not just its first page. */+export function useMobileChannelSearch(options: {+ text: Accessor<string>;+ scope: Accessor<ChannelsQueryScope>;+ source: Accessor<ChannelsDataSource>;+}): ChannelsDataSource {+ const text = createMemo(() => options.text().trim());+ const serviceText = debouncedDependent(text, 300);+ const channelTypes = createMemo(() =>+ match(options.scope())+ .with('direct_messages', () => ['direct_message'])+ .with('channels', () => ['public', 'private', 'team'])+ .with('recents', () => undefined)+ .exhaustive()+ );+ const serviceEnabled = () =>+ validateSearchServiceText(text()) && text() === serviceText();+ const query = useSearchSoupQuery(+ () => ({+ params: { page_size: 100 },+ body: {+ query: serviceText(),+ match_type: 'partial',+ search_on: 'name',+ filters: {+ ...QUERY_FILTERS_BASE,+ channel_filters: {+ is_participant: true,+ channel_types: channelTypes(),+ },+ },+ },+ }),+ () => ({ enabled: serviceEnabled() })+ );++ const items = createMemo(() => {+ const source = options.source();+ if (!text()) return source.items();++ const local = source+ .items()+ .filter((channel) =>+ channel.name.toLocaleLowerCase().includes(text().toLocaleLowerCase())+ );+ // Disabled/pending reads must not suspend the mobile list. Placeholder data+ // belongs to the previous query or tab and must never appear as a new hit.+ const remote =+ serviceEnabled() && query.isSuccess && !query.isPlaceholderData+ ? query.data+ .filter((entity): entity is WithSearch<ChannelEntity> =>+ isChannelEntity(entity)+ )+ .filter((channel) => {+ const types = channelTypes();+ return !types || types.includes(channel.channelType);+ })+ : [];+ return deduplicateChannels([local, remote]);+ });+ const searching = () => text().length > 0;+ const serviceLoading = () =>+ validateSearchServiceText(text()) &&+ (text() !== serviceText() ||+ (query.isFetching && !query.isFetchingNextPage));++ return {+ items,+ isLoading: () =>+ searching()+ ? items().length === 0 &&+ (options.source().isLoading() || serviceLoading())+ : options.source().isLoading(),+ // Match the pagination source so browse refetches cannot block search pages.+ isFetching: () =>+ searching()+ ? serviceLoading() || (serviceEnabled() && query.isFetching)+ : options.source().isFetching(),+ error: () =>+ searching()+ ? serviceEnabled()+ ? query.error+ : undefined+ : options.source().error(),+ hasMore: () =>+ searching()+ ? serviceEnabled() && !query.isPlaceholderData && query.hasNextPage+ : options.source().hasMore(),+ isLoadingMore: () =>+ searching()+ ? serviceEnabled() && query.isFetchingNextPage+ : options.source().isLoadingMore(),+ loadMore: async () => {+ if (!searching()) return options.source().loadMore();+ if (+ !serviceEnabled() ||+ query.isPlaceholderData ||+ query.isFetching ||+ !query.hasNextPage+ )+ return;+ await query.fetchNextPage();+ },+ refresh: async () => {+ await Promise.all([+ options.source().refresh(),+ ...(serviceEnabled() && query.isEnabled+ ? [query.refetch({ throwOnError: true })]+ : []),+ ]);+ },+ };+}diff --git a/docs/AGENT_GUIDE/channels.md b/docs/AGENT_GUIDE/channels.mdindex 7d4900035a..0575536d4b 100644--- a/docs/AGENT_GUIDE/channels.md+++ b/docs/AGENT_GUIDE/channels.md@@ -514,6 +514,21 @@ Channels, and DMs section headers.On touch layouts, the `Recent`, `Channels`, and `DMs` pill tabs each retaintheir own loaded pages and load more as their active list approaches the end.+The mobile dock search filters the selected tab by conversation name as you type:+`DMs` searches people, `Channels` searches non-DM channels, and `Recent` searches+both. Loaded matches appear immediately; queries of at least three characters+also search the server, including conversations beyond the loaded page. Changing+tabs keeps the query and changes its scope. Closing search restores the ordinary+list. Verify `Channels` → `DMs` → type a person's name with GraphQL enabled:+unrelated rows disappear, no matches shows **No results**, and switching to+Channels never keeps DM search hits. Changing the query resets list scroll+without blurring the dock input. While a background browse-list refresh is still+pending, scroll near the end of search results: the next search page should load+without waiting for that refresh or requiring another scroll. Clearing search+restores the browse list's own pagination and fetching state. A failed browse+request must not show a load-error message over valid search hits or replace+**No results**, including during debounce and short local-only queries. Search+failures still show their own error; clearing search restores the browse error.With `enable-graphql-soup` enabled, open an unread conversation from each taband return to the list: all its message notifications should be read, includingmentions, replies, and ones older than the global notification feed's loaded page.