Skip to content
TypeScript

feat(mobile): search Settings, and keep its sidebar header clean (#24766)

Julius Marmingeb3d382e1009d
diff --git a/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx b/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx
index d9c233a90f3..5a42b61d259 100644
--- a/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx
+++ b/apps/mobile/src/features/layout/createWorkspaceStackNavigator.ios.tsx
@@ -39,7 +39,6 @@ import { workspaceUsesColumns } from "../workspace/workspace-tabs-state";
import { isSettingsRoute, settingsOpenIn } from "../settings/settings-navigation";
import { workspaceRoutesOf } from "./workspace-overlay-routes";
import { setNativelyPoppingWorkspaceRoute } from "../workspace/workspace-detail-selection";
-import { useWorkspaceSidebarHeaderItem } from "./useWorkspaceSidebarHeaderItem";
import { useDeviceType, useNativeLayoutMetrics } from "../../native/native-layout-metrics";
import { useAdaptiveWorkspaceLayout } from "./AdaptiveWorkspaceLayout";
@@ -94,26 +93,15 @@ function ColumnScreen(props: {
readonly onDismiss: (routeKey: string, native: boolean) => void;
readonly onAppearance: (type: "willAppear" | "didAppear" | "willDisappear", key: string) => void;
readonly onCompose?: () => void;
- /** Settings pages don't draw their own sidebar toggle, unlike threads and pull requests. */
- readonly sidebarToggle?: boolean;
readonly navigation: ViewProps["navigation"];
}) {
const { descriptor } = props;
// Options a screen set inside this workspace tab slot, over its route's.
- const slotOptions = slotScreenOptions(
+ const options = slotScreenOptions(
use(WorkspaceSlotOptionsContext),
descriptor.route.key,
descriptor.options,
);
- const sidebarItem = useWorkspaceSidebarHeaderItem();
- // Swapping header components would unmount the native header config, which hides the bar.
- const options =
- props.sidebarToggle && !slotOptions.unstable_headerLeftItems
- ? ({
- ...slotOptions,
- unstable_headerLeftItems: () => [sidebarItem],
- } as AppNativeStackNavigationOptions as typeof slotOptions)
- : slotOptions;
const [presented, setPresented] = useState(false);
const primaryColumn = useMemo(
() =>
@@ -420,7 +408,6 @@ function WorkspaceColumns(
key={screenKey}
screenKey={screenKey}
descriptor={descriptor}
- sidebarToggle={inSettingsSlot}
attached={props.detail.some((current) => current.key === route.key)}
onDismiss={handleNativeDismiss}
onAppearance={followCollapsedSplit}
diff --git a/apps/mobile/src/features/settings/SettingsRouteScreen.tsx b/apps/mobile/src/features/settings/SettingsRouteScreen.tsx
index 826d352fb4a..2f7406d5b78 100644
--- a/apps/mobile/src/features/settings/SettingsRouteScreen.tsx
+++ b/apps/mobile/src/features/settings/SettingsRouteScreen.tsx
@@ -11,13 +11,15 @@ import {
import { currentWorkspaceSelections } from "../workspace/workspace-selection-store";
import { rememberedSettingsPage } from "../workspace/workspace-tab-navigation";
import { useSelectWorkspaceTab } from "../workspace/useSelectWorkspaceTab";
+import { useWorkspaceTabs } from "../workspace/WorkspaceTabsContext";
import {
ScreenScrollView as ScrollView,
ScreenScrollViewBottomInset,
} from "../../components/ui/ScreenScrollView";
+import { EmptyState } from "../../components/ui/EmptyState";
import { useAuth, useUser } from "@clerk/expo";
import { useNavigation, useNavigationState } from "@react-navigation/native";
-import { use, useMemo } from "react";
+import { use, useMemo, type ComponentProps } from "react";
import { Platform, View } from "react-native";
import { useWorkspaceSurface } from "../workspace/useWorkspaceSurface";
import { useDeviceType } from "../../native/native-layout-metrics";
@@ -31,17 +33,20 @@ import { useSavedRemoteConnections } from "../../state/use-remote-environment-re
import { SettingsRow } from "./components/SettingsRow";
import { SettingsSection, SettingsSidebarContext } from "./components/SettingsSection";
import { SettingsScreen } from "./components/SettingsScreen";
+import type { SettingsPageTarget } from "./components/settings-page-targets";
import {
AndroidSettingsEnvironmentFilter,
SettingsEnvironmentFilterHeader,
} from "./components/SettingsEnvironmentFilterHeader";
import { useSettingsEnvironmentFilter } from "./settings-environment-filter";
+import { filterSettingsSections } from "./settings-search";
import { NativePrimaryColumnContext } from "../../native/v5-workspace-context";
export function SettingsRouteScreen() {
const surface = useWorkspaceSurface();
const deviceType = useDeviceType();
const compactTabs = useCompactWorkspaceTabs();
+ const workspace = useWorkspaceTabs();
const { layout } = useAdaptiveWorkspaceLayout();
const inSidebar = use(NativePrimaryColumnContext) !== null && layout.usesSplitView;
// The page open beside the list: the route right above the Settings tab's route. While
@@ -66,7 +71,20 @@ export function SettingsRouteScreen() {
<SettingsEnvironmentFilterHeader />
<ScreenScrollViewBottomInset value={deviceType === "pad" || compactTabs ? 80 : 0}>
{Platform.OS === "android" ? (
- <SettingsScreen title="Settings" trailing={<AndroidSettingsEnvironmentFilter />}>
+ <SettingsScreen
+ title="Settings"
+ trailing={<AndroidSettingsEnvironmentFilter />}
+ search={
+ workspace
+ ? {
+ value: workspace.state.tabs.settings.query,
+ onChangeText: (query) =>
+ workspace.dispatch({ type: "query", tab: "settings", query }),
+ placeholder: "Search settings",
+ }
+ : undefined
+ }
+ >
{content}
</SettingsScreen>
) : (
@@ -78,12 +96,14 @@ export function SettingsRouteScreen() {
);
}
+type SettingsListRow = ComponentProps<typeof SettingsRow> & { readonly id: string };
+
+interface SettingsListSection {
+ readonly title?: string;
+ readonly rows: readonly SettingsListRow[];
+}
+
function ConfiguredSettingsRouteScreen() {
- // UIKit's scroll-edge material takes the scroll view's own color; like the chat list, match
- // the sidebar's surface so the bar doesn't darken over content at rest.
- // Grouped cards only lift off the screen surface; the drawer is as dark as they are.
- const listSurface = use(SettingsSidebarContext) ? "bg-drawer" : "bg-screen";
- const insets = useSafeAreaInsets();
const navigation = useNavigation();
const { isLoaded, isSignedIn } = useAuth({ treatPendingAsSignedOut: false });
const { user } = useUser();
@@ -95,77 +115,96 @@ function ConfiguredSettingsRouteScreen() {
: (user?.primaryEmailAddress?.emailAddress ?? "Signed in");
return (
- <View collapsable={false} className="flex-1">
- <ScrollView
- contentInsetAdjustmentBehavior="automatic"
- showsVerticalScrollIndicator={false}
- className={`flex-1 ${listSurface}`}
- contentContainerClassName="gap-4 px-5 pt-4"
- contentContainerStyle={{ paddingBottom: Math.max(insets.bottom, 18) + 18 }}
- >
- <OverflowSection />
- <SettingsSection title="Connections">
- <SettingsRow
- icon="person.crop.circle"
- label="T3 Account"
- value={accountLabel}
- disabled={!isLoaded}
- onPress={() => navigation.navigate("SettingsAuth")}
- />
- <SettingsRow
- icon="desktopcomputer"
- label="Environments"
- value={`${Object.keys(savedConnectionsById).length}`}
- valuePosition="trailing"
- target="SettingsEnvironments"
- />
- <SettingsRow icon="bell.badge" label="Notifications" target="SettingsNotifications" />
- </SettingsSection>
-
- <SettingsIndexSections />
- </ScrollView>
- </View>
+ <SettingsList
+ connections={[
+ {
+ id: "account",
+ icon: "person.crop.circle",
+ label: "T3 Account",
+ value: accountLabel,
+ disabled: !isLoaded,
+ onPress: () => navigation.navigate("SettingsAuth"),
+ },
+ environmentsRow(Object.keys(savedConnectionsById).length),
+ {
+ id: "SettingsNotifications",
+ icon: "bell.badge",
+ label: "Notifications",
+ target: "SettingsNotifications",
+ },
+ ]}
+ />
);
}
function LocalSettingsRouteScreen() {
+ const { savedConnectionsById } = useSavedRemoteConnections();
+ return <SettingsList connections={[environmentsRow(Object.keys(savedConnectionsById).length)]} />;
+}
+
+function environmentsRow(count: number): SettingsListRow {
+ return {
+ id: "SettingsEnvironments",
+ icon: "desktopcomputer",
+ label: "Environments",
+ value: `${count}`,
+ valuePosition: "trailing",
+ target: "SettingsEnvironments",
+ };
+}
+
+function SettingsList(props: { readonly connections: readonly SettingsListRow[] }) {
// UIKit's scroll-edge material takes the scroll view's own color; like the chat list, match
// the sidebar's surface so the bar doesn't darken over content at rest.
// Grouped cards only lift off the screen surface; the drawer is as dark as they are.
const listSurface = use(SettingsSidebarContext) ? "bg-drawer" : "bg-screen";
const insets = useSafeAreaInsets();
- const { savedConnectionsById } = useSavedRemoteConnections();
- const environmentCount = Object.keys(savedConnectionsById).length;
+ const workspace = useWorkspaceTabs();
+ const query = workspace?.state.tabs.settings.query ?? "";
+ const overflowRows = useOverflowRows();
+ const indexSections = useSettingsIndexSections();
+ const sections = filterSettingsSections(
+ [{ rows: overflowRows }, { title: "Connections", rows: props.connections }, ...indexSections],
+ query,
+ );
return (
<View collapsable={false} className="flex-1">
<ScrollView
contentInsetAdjustmentBehavior="automatic"
+ keyboardShouldPersistTaps="handled"
showsVerticalScrollIndicator={false}
className={`flex-1 ${listSurface}`}
contentContainerClassName="gap-4 px-5 pt-4"
contentContainerStyle={{
- paddingBottom: Math.max(insets.bottom, 18) + 18,
+ // The workspace's clearance keeps the last row above its search field and keyboard.
+ paddingBottom: Math.max(
+ Math.max(insets.bottom, 18) + 18,
+ workspace?.bottomClearance ?? 0,
+ ),
}}
>
- <OverflowSection />
- <SettingsSection title="Connections">
- <SettingsRow
- icon="desktopcomputer"
- label="Environments"
- value={`${environmentCount}`}
- valuePosition="trailing"
- target="SettingsEnvironments"
+ {sections.length ? (
+ sections.map((section) => (
+ <SettingsSection key={section.title ?? "tabs"} title={section.title}>
+ {section.rows.map(({ id, ...row }) => (
+ <SettingsRow key={id} {...row} />
+ ))}
+ </SettingsSection>
+ ))
+ ) : (
+ <EmptyState
+ variant="plain"
+ title="No results"
+ detail={`No settings match “${query.trim()}”.`}
/>
- </SettingsSection>
-
- <SettingsIndexSections />
+ )}
</ScrollView>
</View>
);
}
-function SettingsIndexSections() {
+function useSettingsIndexSections(): SettingsListSection[] {
const { selectedTargets, projectGroups, selectedProjectKey } = useSettingsEnvironmentFilter();
const noServerTargets = selectedTargets.length === 0;
const selectedProject = projectGroups.find((group) => group.key === selectedProjectKey);
@@ -182,101 +221,74 @@ function SettingsIndexSections() {
members: scopedProjectMembers,
})
: (selectedProject?.label ?? "Unavailable project");
- return (
- <>
- <SettingsSection title="Interface">
- <SettingsRow icon="paintbrush" label="Appearance" target="SettingsAppearance" />
- {navigationCustomizationAvailable() ? (
- <SettingsRow
- icon="line.3.horizontal"
- label="Navigation tabs"
- target="SettingsNavigation"
- />
- ) : null}
- {Platform.OS === "ios" ? (
- <>
- <SettingsRow icon="keyboard" label="Keyboard" target="SettingsKeyboard" />
- <SettingsRow icon="mic" label="Microphone" target="SettingsMicrophone" />
- </>
- ) : null}
- </SettingsSection>
-
- <SettingsSection title="Automations">
- <SettingsRow icon="clock" label="Scheduled tasks" target="SettingsScheduledTasks" />
- </SettingsSection>
-
- <SettingsSection title="Projects & threads">
- {selectedProjectKey !== null ? (
- <SettingsRow
- icon="folder"
- label="Overview"
- value={projectLabel}
- target="SettingsProjectOverview"
- />
- ) : null}
- <SettingsRow icon="folder" label="Organization" target="SettingsOrganization" />
- <SettingsRow icon="text.bubble" label="Thread behavior" target="SettingsThreads" />
- <SettingsRow icon="arrow.turn.left.up" label="Follow-ups" target="SettingsFollowUp" />
- <SettingsRow icon="archivebox" label="Archived Threads" target="SettingsArchive" />
- </SettingsSection>
-
- <SettingsSection title="Server settings">
- <SettingsRow
- icon="person.crop.circle"
- label="Provider accounts"
- target="SettingsProviderAccounts"
- disabled={noServerTargets}
- />
- <SettingsRow
- icon="text.bubble"
- label="New threads"
- target="SettingsEnvironmentNewThreads"
- disabled={noServerTargets}
- />
- <SettingsRow
- icon="arrow.triangle.branch"
- label="Source control"
- target="SettingsEnvironmentSourceControl"
- disabled={noServerTargets}
- />
- <SettingsRow
- icon="text.alignleft"
- label="Agent behavior"
- target="SettingsEnvironmentAgentBehavior"
- disabled={noServerTargets}
- />
- <SettingsRow
- icon="arrow.clockwise"
- label="Maintenance"
- target="SettingsEnvironmentMaintenance"
- disabled={noServerTargets}
- />
- </SettingsSection>
-
- <SettingsSection title="App">
- <SettingsRow icon="info.circle" label="About T3 Code" target="SettingsAbout" />
- </SettingsSection>
- </>
- );
+ const page = (
+ target: SettingsPageTarget,
+ icon: SettingsListRow["icon"],
+ label: string,
+ extra?: Pick<SettingsListRow, "disabled" | "value">,
+ ): SettingsListRow => ({ id: target, icon, label, target, ...extra });
+ const serverPage = (target: SettingsPageTarget, icon: SettingsListRow["icon"], label: string) =>
+ page(target, icon, label, { disabled: noServerTargets });
+ return [
+ {
+ title: "Interface",
+ rows: [
+ page("SettingsAppearance", "paintbrush", "Appearance"),
+ ...(navigationCustomizationAvailable()
+ ? [page("SettingsNavigation", "line.3.horizontal", "Navigation tabs")]
+ : []),
+ ...(Platform.OS === "ios"
+ ? [
+ page("SettingsKeyboard", "keyboard", "Keyboard"),
+ page("SettingsMicrophone", "mic", "Microphone"),
+ ]
+ : []),
+ ],
+ },
+ {
+ title: "Automations",
+ rows: [page("SettingsScheduledTasks", "clock", "Scheduled tasks")],
+ },
+ {
+ title: "Projects & threads",
+ rows: [
+ ...(selectedProjectKey !== null
+ ? [page("SettingsProjectOverview", "folder", "Overview", { value: projectLabel })]
+ : []),
+ page("SettingsOrganization", "folder", "Organization"),
+ page("SettingsThreads", "text.bubble", "Thread behavior"),
+ page("SettingsFollowUp", "arrow.turn.left.up", "Follow-ups"),
+ page("SettingsArchive", "archivebox", "Archived Threads"),
+ ],
+ },
+ {
+ title: "Server settings",
+ rows: [
+ serverPage("SettingsProviderAccounts", "person.crop.circle", "Provider accounts"),
+ serverPage("SettingsEnvironmentNewThreads", "text.bubble", "New threads"),
+ serverPage("SettingsEnvironmentSourceControl", "arrow.triangle.branch", "Source control"),
+ serverPage("SettingsEnvironmentAgentBehavior", "text.alignleft", "Agent behavior"),
+ serverPage("SettingsEnvironmentMaintenance", "arrow.clockwise", "Maintenance"),
+ ],
+ },
+ {
+ title: "App",
+ rows: [page("SettingsAbout", "info.circle", "About T3 Code")],
+ },
+ ];
}
-function OverflowSection() {
+function useOverflowRows(): SettingsListRow[] {
const order = useNavigationTabOrder();
const hidden = useHiddenNavigationTabs();
const { layout } = useAdaptiveWorkspaceLayout();
const tabs =
Platform.OS === "android" && layout.usesSplitView ? [] : overflowNavigationTabs(order, hidden);
const selectTab = useSelectWorkspaceTab();
- return tabs.length ? (
- <SettingsSection>
- {tabs.map((tab) => (
- <SettingsRow
- key={tab}
- icon={NAVIGATION_TAB_ICONS[tab]}
- label={WORKSPACE_TAB_LABELS[tab]}
- onPress={() => selectTab(tab)}
- />
- ))}
- </SettingsSection>
- ) : null;
+ return tabs.map((tab) => ({
+ id: tab,
+ icon: NAVIGATION_TAB_ICONS[tab],
+ label: WORKSPACE_TAB_LABELS[tab],
+ onPress: () => selectTab(tab),
+ }));
}
diff --git a/apps/mobile/src/features/settings/components/SettingsScreen.tsx b/apps/mobile/src/features/settings/components/SettingsScreen.tsx
index 85a8258187a..74a749ed24d 100644
--- a/apps/mobile/src/features/settings/components/SettingsScreen.tsx
+++ b/apps/mobile/src/features/settings/components/SettingsScreen.tsx
@@ -17,7 +17,7 @@ import {
export { SettingsScreenContent };
export function SettingsScreen(
- props: Pick<AppBarProps, "title" | "actions" | "trailing"> & {
+ props: Pick<AppBarProps, "title" | "actions" | "trailing" | "search"> & {
readonly children: ReactNode;
readonly formSheet?: boolean;
readonly workspaceRoot?: boolean;
@@ -44,6 +44,7 @@ export function SettingsScreen(
<AppBar
title={props.title}
actions={props.actions}
+ search={props.search}
trailing={Platform.OS === "android" ? props.trailing : undefined}
sidebar={false}
onBack={workspaceRoot ? undefined : () => navigation.goBack()}
diff --git a/apps/mobile/src/features/settings/settings-search.test.ts b/apps/mobile/src/features/settings/settings-search.test.ts
new file mode 100644
index 00000000000..6c11a3dae7f
--- /dev/null
+++ b/apps/mobile/src/features/settings/settings-search.test.ts
@@ -0,0 +1,68 @@
+import { describe, expect, it } from "vite-plus/test";
+
+import { filterSettingsSections } from "./settings-search";
+
+const SECTIONS = [
+ { rows: [{ id: "usage", label: "Usage" }] },
+ {
+ title: "Connections",
+ rows: [
+ { id: "account", label: "T3 Account" },
+ { id: "SettingsEnvironments", label: "Environments" },
+ ],
+ },
+ {
+ title: "Interface",
+ rows: [
+ { id: "SettingsAppearance", label: "Appearance" },
+ { id: "SettingsKeyboard", label: "Keyboard" },
+ ],
+ },
+ {
+ title: "Server settings",
+ rows: [
+ { id: "SettingsProviderAccounts", label: "Provider accounts" },
+ { id: "SettingsEnvironmentSourceControl", label: "Source control" },
+ ],
+ },
+];
+
+function visible(query: string) {
+ return filterSettingsSections(SECTIONS, query).map((section) => [
+ section.title ?? null,
+ section.rows.map((row) => row.label),
+ ]);
+}
+
+describe("filterSettingsSections", () => {
+ it.each([
+ {
+ query: "",
+ expected: SECTIONS.map((section) => [
+ section.title ?? null,
+ section.rows.map((row) => row.label),
+ ]),
+ },
+ { query: " ", expected: visible("") },
+ { query: "appear", expected: [["Interface", ["Appearance"]]] },
+ { query: "KEYBOARD", expected: [["Interface", ["Keyboard"]]] },
+ { query: "dark mode", expected: [["Interface", ["Appearance"]]] },
+ { query: "branch naming", expected: [["Server settings", ["Source control"]]] },
+ {
+ query: "server settings",
+ expected: [["Server settings", ["Provider accounts", "Source control"]]],
+ },
+ {
+ query: "accounts",
+ expected: [["Server settings", ["Provider accounts"]]],
+ },
+ { query: "usage", expected: [[null, ["Usage"]]] },
+ { query: "zzzz", expected: [] },
+ ])("$query", ({ query, expected }) => {
+ expect(visible(query)).toEqual(expected);
+ });
+
+ it("drops sections that start empty", () => {
+ expect(filterSettingsSections([{ rows: [] }, ...SECTIONS], "").length).toBe(SECTIONS.length);
+ });
+});
diff --git a/apps/mobile/src/features/settings/settings-search.ts b/apps/mobile/src/features/settings/settings-search.ts
new file mode 100644
index 00000000000..f82f90dfe83
--- /dev/null
+++ b/apps/mobile/src/features/settings/settings-search.ts
@@ -0,0 +1,120 @@
+import { foldSearchQuery, rankSearchItems, scoreSearchTerms } from "@t3tools/shared/paletteSearch";
+
+import type { SettingsPageTarget } from "./components/settings-page-targets";
+
+/** What each page holds besides its row's label, so search finds a setting by its own name. */
+const SETTINGS_SEARCH_TERMS = {
+ account: ["sign in", "sign out", "login", "clerk", "connect"],
+ SettingsEnvironments: [
+ "servers",
+ "connections",
+ "pair",
+ "add environment",
+ "remote",
+ "tailscale",
+ ],
+ SettingsNotifications: ["push", "alerts", "live activity", "agent activity"],
+ SettingsAppearance: [
+ "theme",
+ "dark mode",
+ "light mode",
+ "colors",
+ "font size",
+ "text size",
+ "code",
+ "diffs",
+ "terminal",
+ "word break",
+ "math",
+ ],
+ SettingsNavigation: ["tabs", "tab order", "reorder", "hide tabs"],
+ SettingsKeyboard: ["return key", "send message", "new line", "hardware keyboard"],
+ SettingsMicrophone: ["voice", "dictation", "audio input", "bluetooth"],
+ SettingsScheduledTasks: ["automations", "schedule", "cron", "recurring", "webhook"],
+ SettingsProjectOverview: ["project", "checkouts", "worktrees", "delete project"],
+ SettingsOrganization: ["project grouping", "group projects", "sidebar"],
+ SettingsThreads: [
+ "auto-settle",
+ "settle",
+ "snooze",
+ "usage limits",
+ "auto-resume",
+ "plan mode",
+ "working section",
+ ],
+ SettingsFollowUp: ["queue", "steer", "while the agent is running"],
+ SettingsArchive: ["archive", "archived", "restore", "unarchive"],
+ SettingsProviderAccounts: ["codex", "claude", "cursor", "opencode", "sign in", "login", "auth"],
+ SettingsEnvironmentNewThreads: [
+ "default workspace",
+ "worktree",
+ "submodules",
+ "default permissions",
+ "access",
+ ],
+ SettingsEnvironmentSourceControl: [
+ "git",
+ "branch naming",
+ "pull requests",
+ "co-authors",
+ "agent credits",
+ "default branch",
+ "automatically pull",
+ "worktrees",
+ "start from remote",
+ ],
+ SettingsEnvironmentAgentBehavior: ["response streaming", "preview browser", "browser access"],
+ SettingsEnvironmentMaintenance: ["updates", "provider updates", "restart", "manage environments"],
+ SettingsAbout: [
+ "version",
+ "diagnostics",
+ "client storage",
+ "cache",
+ "legal",
+ "privacy",
+ "terms",
+ "open source licenses",
+ ],
+} satisfies Partial<Record<SettingsPageTarget | "account", readonly string[]>>;
+const termsById: ReadonlyMap<string, readonly string[]> = new Map(
+ Object.entries(SETTINGS_SEARCH_TERMS),
+);
+
+export interface SettingsSearchRow {
+ readonly id: string;
+ readonly label: string;
+}
+
+export interface SettingsSearchSection<Row extends SettingsSearchRow> {
+ readonly title?: string;
+ readonly rows: readonly Row[];
+}
+
+/**
+ * Keeps the rows whose label, section, or page contents match `query`, in list order, and drops
+ * sections left empty. Matching is the command palette's, so both searches agree.
+ */
+export function filterSettingsSections<
+ Row extends SettingsSearchRow,
+ Section extends SettingsSearchSection<Row>,
+>(sections: readonly Section[], query: string): Section[] {
+ const normalizedQuery = foldSearchQuery(query);
+ const rows = sections.flatMap((section) =>
+ section.rows.map((row) => ({ row, section: section.title })),
+ );
+ const matched = normalizedQuery
+ ? new Set(
+ rankSearchItems(rows, ({ row, section }, options) =>
+ scoreSearchTerms(
+ normalizedQuery,
+ [row.label, ...(section ? [section] : []), ...(termsById.get(row.id) ?? [])],
+ options,
+ ),
+ ).map(({ item }) => item.row),
+ )
+ : null;
+ return sections.flatMap((section) => {
+ const kept = matched ? section.rows.filter((row) => matched.has(row)) : section.rows;
+ return kept.length ? [{ ...section, rows: kept }] : [];
+ });
+}
diff --git a/apps/mobile/src/features/workspace/WorkspaceRootScreen.tsx b/apps/mobile/src/features/workspace/WorkspaceRootScreen.tsx
index 69efd96411f..8778ba2b364 100644
--- a/apps/mobile/src/features/workspace/WorkspaceRootScreen.tsx
+++ b/apps/mobile/src/features/workspace/WorkspaceRootScreen.tsx
@@ -54,16 +54,17 @@ function WorkspaceRootTitle(props: {
readonly maxWidth: number;
readonly onOpenEnvironments: () => void;
}) {
- const { state } = useWorkspaceTabs()!;
+ const { state, settingsOpen } = useWorkspaceTabs()!;
const enabled = useEnabledNavigationTabs();
+ const tabTitle = settingsOpen
+ ? "Settings"
+ : enabled.length
+ ? TAB_TITLES[state.selectedTab]
+ : "Navigation";
return (
<View style={{ width: props.maxWidth, minHeight: 32, justifyContent: "center" }}>
<WorkspaceConnectionTitle
- brand={
- <CompactBrandTitle
- accessibilityLabel={`T3 Code, ${enabled.length ? TAB_TITLES[state.selectedTab] : "Navigation"}`}
- />
- }
+ brand={<CompactBrandTitle accessibilityLabel={`T3 Code, ${tabTitle}`} />}
maxWidth={props.maxWidth}
onPress={props.onOpenEnvironments}
/>
@@ -106,9 +107,9 @@ function WorkspaceRootContent() {
),
[width, navigation],
);
- const tab = state.tabs[state.selectedTab];
// Settings is a workspace tab too; its list takes the place of the selected tab's.
const settingsOpen = workspace.settingsOpen;
+ const tab = state.tabs[settingsOpen ? "settings" : state.selectedTab];
const bottomClearance =
layout.primarySidebarOverlaysContent && state.selectedTab === "usage"
? workspaceDockBottomClearance({ bottomInset: insets.bottom, keyboardHeight })
@@ -164,8 +165,12 @@ function WorkspaceRootContent() {
? { headerSearchBarOptions: undefined, unstable_headerRightItems: () => [] }
: {}),
unstable_headerLeftItems: () => [],
+ // Beside a detail column the tab bar names the tab and the detail header the page,
+ // so the sidebar keeps the brand.
headerTitle:
- settingsOpen || state.selectedTab === "usage" ? undefined : renderHeaderTitle,
+ sidebarNavigation || (!settingsOpen && state.selectedTab !== "usage")
+ ? renderHeaderTitle
+ : undefined,
}}
/>
) : (
@@ -199,10 +204,7 @@ function WorkspaceRootContent() {
}
>
{settingsOpen ? (
- <>
- <NativeStackScreenOptions options={{ headerSearchBarOptions: undefined }} />
- <SettingsRouteScreen />
- </>
+ <SettingsRouteScreen />
) : enabled.length === 0 ? (
<WorkspaceNoTabs />
) : state.selectedTab === "threads" ? (
@@ -216,14 +218,15 @@ function WorkspaceRootContent() {
{deviceType !== "pad" && deviceType !== "phone" && sidebarPicker ? (
<WorkspaceSidebarTabs />
) : null}
- {enabled.length === 0 && !settingsOpen ? null : !settingsOpen &&
- (state.selectedTab === "threads" || state.selectedTab === "pullRequests") ? (
+ {/* Android's Settings list carries its own search in its app bar. */}
+ {enabled.length === 0 && !settingsOpen ? null : (
+ settingsOpen
+ ? Platform.OS === "ios"
+ : state.selectedTab === "threads" || state.selectedTab === "pullRequests"
+ ) ? (
<WorkspaceToolbar sidebar={sidebarNavigation} onNewTask={startNewTask} />
) : (
- <WorkspaceSectionToolbar
- onNewTask={startNewTask}
- showCompose={!settingsOpen && state.selectedTab !== "usage"}
- />
+ <WorkspaceSectionToolbar onNewTask={startNewTask} showCompose={false} />
)}
</View>
</WorkspaceTabsContext>
diff --git a/apps/mobile/src/features/workspace/WorkspaceTabsContext.tsx b/apps/mobile/src/features/workspace/WorkspaceTabsContext.tsx
index f8e23235d3d..2c3a10e4b0c 100644
--- a/apps/mobile/src/features/workspace/WorkspaceTabsContext.tsx
+++ b/apps/mobile/src/features/workspace/WorkspaceTabsContext.tsx
@@ -14,6 +14,7 @@ import {
import {
initialWorkspaceTabsState,
workspaceTabsReducer,
+ type WorkspaceSearchTab,
type WorkspaceTab,
type WorkspaceTabsAction,
type WorkspaceTabsState,
@@ -25,8 +26,8 @@ export const WorkspaceTabsContext = createContext<{
readonly isTabActive: (tab: WorkspaceTab) => boolean;
readonly bottomClearance: number;
readonly settingsOpen: boolean;
- readonly getScrollOffset: (tab: WorkspaceTab) => number;
- readonly recordScrollOffset: (tab: WorkspaceTab, offset: number) => void;
+ readonly getScrollOffset: (tab: WorkspaceSearchTab) => number;
+ readonly recordScrollOffset: (tab: WorkspaceSearchTab, offset: number) => void;
} | null>(null);
export function useWorkspaceTabs() {
@@ -47,9 +48,9 @@ export function WorkspaceTabsProvider(props: {
activeTab.current = state.selectedTab;
}, [state.selectedTab]);
const isTabActive = useCallback((tab: WorkspaceTab) => activeTab.current === tab, []);
- const scrollOffsets = useRef({ threads: 0, pullRequests: 0, usage: 0 });
- const getScrollOffset = useCallback((tab: WorkspaceTab) => scrollOffsets.current[tab], []);
- const recordScrollOffset = useCallback((tab: WorkspaceTab, offset: number) => {
+ const scrollOffsets = useRef({ threads: 0, pullRequests: 0, usage: 0, settings: 0 });
+ const getScrollOffset = useCallback((tab: WorkspaceSearchTab) => scrollOffsets.current[tab], []);
+ const recordScrollOffset = useCallback((tab: WorkspaceSearchTab, offset: number) => {
scrollOffsets.current[tab] = offset;
}, []);
const context = useMemo(
diff --git a/apps/mobile/src/features/workspace/WorkspaceToolbar.ios.tsx b/apps/mobile/src/features/workspace/WorkspaceToolbar.ios.tsx
index 17fff053258..821c4c70c34 100644
--- a/apps/mobile/src/features/workspace/WorkspaceToolbar.ios.tsx
+++ b/apps/mobile/src/features/workspace/WorkspaceToolbar.ios.tsx
@@ -19,6 +19,12 @@ import { useWorkspaceTabs } from "./WorkspaceTabsContext";
import { useCompactWorkspaceTabs, useSidebarWorkspaceTabs } from "./useSystemWorkspaceTabBar";
import { WorkspaceTabToolbarButtons } from "./WorkspaceSectionToolbar";
+const SEARCH_LABELS = {
+ threads: "Search threads",
+ pullRequests: "Search pull requests",
+ settings: "Search settings",
+} as const;
+
export function WorkspaceToolbar(props: {
readonly onNewTask: () => void;
readonly sidebar?: boolean;
@@ -34,15 +40,23 @@ export function WorkspaceToolbar(props: {
const nativeToolbarCompose =
Platform.OS === "ios" &&
deviceType === "duo-folded" &&
+ !workspace.settingsOpen &&
workspace.state.selectedTab === "threads" &&
activeNewTask === null;
- const { isTabActive } = workspace;
const tabActive = use(NativeWorkspaceTabActivityContext)?.active ?? true;
const focused = useIsFocused();
const { panes, togglePrimarySidebar } = useAdaptiveWorkspaceLayout();
const searchRef = useRef<SearchBarCommands>(null);
- const tab = workspace.state.tabs[workspace.state.selectedTab];
- const selectedTab = workspace.state.selectedTab;
+ // The Settings list takes the selected tab's place, so search follows it.
+ const selectedTab = workspace.settingsOpen ? "settings" : workspace.state.selectedTab;
+ const tab = workspace.state.tabs[selectedTab];
+ const searchLabel = SEARCH_LABELS[selectedTab === "usage" ? "threads" : selectedTab];
+ const { isTabActive: isListTabActive } = workspace;
+ const isTabActive = useCallback(
+ // A retained tab slot stays mounted while another is shown.
+ (tab: typeof selectedTab) => (tab === "settings" ? tabActive : isListTabActive(tab)),
+ [tabActive, isListTabActive],
+ );
const foldedSearch = deviceType === "duo-folded";
const primaryColumn = use(NativePrimaryColumnContext);
// UIKit hosts integrated search outside the sidebar's sliding content.
@@ -60,11 +74,11 @@ export function WorkspaceToolbar(props: {
if (props.sidebar && !panes.primarySidebarVisible) togglePrimarySidebar();
}, [workspace, selectedTab, props.sidebar, panes.primarySidebarVisible, togglePrimarySidebar]);
const focusSearch = useCallback(() => {
- if (!workspace.isTabActive(selectedTab)) return false;
+ if (!isTabActive(selectedTab)) return false;
if (duoSearch || !NATIVE_LIQUID_GLASS_SUPPORTED) enterSearch();
searchRef.current?.focus();
return true;
- }, [workspace, selectedTab, enterSearch, duoSearch]);
+ }, [isTabActive, selectedTab, enterSearch, duoSearch]);
const cancelSearch = useCallback(() => {
workspace.recordScrollOffset(selectedTab, tab.searchEntryOffset);
workspace.dispatch({ type: "cancel", tab: selectedTab });
@@ -124,13 +138,7 @@ export function WorkspaceToolbar(props: {
const searchButton = foldedSearch ? (
<Toolbar.Button
identifier="workspace-search"
- accessibilityLabel={
- searchVisible
- ? "Close search"
- : selectedTab === "pullRequests"
- ? "Search pull requests"
- : "Search threads"
- }
+ accessibilityLabel={searchVisible ? "Close search" : searchLabel}
icon={searchVisible ? "xmark" : "magnifyingglass"}
onPress={searchVisible ? () => searchRef.current?.cancelSearch() : focusSearch}
separateBackground
@@ -142,8 +150,13 @@ export function WorkspaceToolbar(props: {
optionsVersion={[selectedTab, tab.searchMode]}
listeners={{ transitionEnd: restoreSearch }}
options={{
+ // Without Liquid Glass, Settings keeps its search field out instead of a search button,
+ // which would take the header's trailing items from the scope filter.
headerSearchBarOptions:
- (NATIVE_LIQUID_GLASS_SUPPORTED || tab.searchMode !== "resting") && searchVisible
+ (NATIVE_LIQUID_GLASS_SUPPORTED ||
+ tab.searchMode !== "resting" ||
+ workspace.settingsOpen) &&
+ searchVisible
? {
ref: searchRef,
autoFocus: tab.searchMode === "active",
@@ -160,8 +173,7 @@ export function WorkspaceToolbar(props: {
NATIVE_LIQUID_GLASS_SUPPORTED &&
deviceType !== "phone" &&
sidebarTabs !== "picker",
- placeholder:
- selectedTab === "pullRequests" ? "Search pull requests" : "Search threads",
+ placeholder: searchLabel,
cancelButtonHidden: foldedSearch,
onFocus: searchFocused,
onBlur: () => workspace.dispatch({ type: "expand", tab: selectedTab }),
@@ -177,32 +189,33 @@ export function WorkspaceToolbar(props: {
: undefined,
}}
/>
- {/* UIKit lays trailing items out from the edge inward. */}
- <Toolbar placement="right">
- {searchButton}
- {nativeToolbarCompose && foldedSearch ? <Toolbar.Spacer width={8} /> : null}
- {composeButton}
- {selectedTab !== "threads" ||
- isDuoDevice(deviceType) ||
- deviceType === "pad" ||
- sidebarTabs === "picker" ||
- compactTabs ? null : (
- <Toolbar.Button
- accessibilityLabel="New chat"
- icon="square.and.pencil"
- onPress={props.onNewTask}
- />
- )}
- {NATIVE_LIQUID_GLASS_SUPPORTED ? null : (
- <Toolbar.Button
- accessibilityLabel={
- selectedTab === "pullRequests" ? "Search pull requests" : "Search threads"
- }
- icon="magnifyingglass"
- onPress={focusSearch}
- />
- )}
- </Toolbar>
+ {/* UIKit lays trailing items out from the edge inward. A trailing toolbar replaces the
+ header's own items, so an empty one would hide the Settings scope filter. */}
+ {workspace.settingsOpen && !foldedSearch ? null : (
+ <Toolbar placement="right">
+ {searchButton}
+ {nativeToolbarCompose && foldedSearch ? <Toolbar.Spacer width={8} /> : null}
+ {composeButton}
+ {selectedTab !== "threads" ||
+ isDuoDevice(deviceType) ||
+ deviceType === "pad" ||
+ sidebarTabs === "picker" ||
+ compactTabs ? null : (
+ <Toolbar.Button
+ accessibilityLabel="New chat"
+ icon="square.and.pencil"
+ onPress={props.onNewTask}
+ />
+ )}
+ {NATIVE_LIQUID_GLASS_SUPPORTED ? null : (
+ <Toolbar.Button
+ accessibilityLabel={searchLabel}
+ icon="magnifyingglass"
+ onPress={focusSearch}
+ />
+ )}
+ </Toolbar>
+ )}
<Toolbar placement="bottom">
{sidebarTabs === "toolbar" ? <WorkspaceTabToolbarButtons /> : null}
{bottomSearch && searchVisible ? <Toolbar.SearchBarSlot /> : null}
diff --git a/apps/mobile/src/features/workspace/workspace-tabs-state.test.ts b/apps/mobile/src/features/workspace/workspace-tabs-state.test.ts
index f476d009857..d0f72faa077 100644
--- a/apps/mobile/src/features/workspace/workspace-tabs-state.test.ts
+++ b/apps/mobile/src/features/workspace/workspace-tabs-state.test.ts
@@ -110,6 +110,20 @@ describe("workspace root navigation", () => {
expect(workspaceTabsReducer(state, { type: "cancel" }).tabs.threads.scrollOffset).toBe(500);
});
+ it("keeps the Settings search apart from the tab Settings opened over", () => {
+ let state = workspaceTabsReducer(initialWorkspaceTabsState(), {
+ type: "query",
+ query: "diff",
+ tab: "threads",
+ });
+ state = workspaceTabsReducer(state, { type: "search", tab: "settings" });
+ state = workspaceTabsReducer(state, { type: "query", query: "theme", tab: "settings" });
+ expect(state.tabs.settings).toMatchObject({ query: "theme", searchMode: "active" });
+ state = workspaceTabsReducer(state, { type: "cancel", tab: "settings" });
+ expect(state.tabs.settings).toMatchObject({ query: "", searchMode: "resting" });
+ expect(state.tabs.threads.query).toBe("diff");
+ });
+
it("a late native blur cannot reopen a cancelled search", () => {
let state = workspaceTabsReducer(initialWorkspaceTabsState(), { type: "search" });
state = workspaceTabsReducer(state, { type: "cancel" });
diff --git a/apps/mobile/src/features/workspace/workspace-tabs-state.ts b/apps/mobile/src/features/workspace/workspace-tabs-state.ts
index 6355796c84e..f216fb9f13c 100644
--- a/apps/mobile/src/features/workspace/workspace-tabs-state.ts
+++ b/apps/mobile/src/features/workspace/workspace-tabs-state.ts
@@ -12,6 +12,8 @@ export function resolveWorkspaceTabOrder(saved: readonly unknown[] | undefined)
}
export type WorkspaceTab = NavigationTab;
+/** Lists with their own search: the searchable tabs and the Settings list. */
+export type WorkspaceSearchTab = WorkspaceTab | "settings";
export type WorkspaceSearchMode = "resting" | "active" | "expanded";
/** Settings, Chats and pull requests pair a list with a detail column; Usage is one page. */
@@ -29,7 +31,7 @@ export interface WorkspaceTabState {
export interface WorkspaceTabsState {
readonly selectedTab: WorkspaceTab;
readonly selectionRevision: number;
- readonly tabs: Readonly<Record<WorkspaceTab, WorkspaceTabState>>;
+ readonly tabs: Readonly<Record<WorkspaceSearchTab, WorkspaceTabState>>;
}
function emptyTab(): WorkspaceTabState {
@@ -44,17 +46,18 @@ export function initialWorkspaceTabsState(): WorkspaceTabsState {
threads: emptyTab(),
pullRequests: emptyTab(),
usage: emptyTab(),
+ settings: emptyTab(),
},
};
}
export type WorkspaceTabsAction =
| { readonly type: "select"; readonly tab: WorkspaceTab }
- | { readonly type: "search"; readonly tab?: WorkspaceTab }
- | { readonly type: "query"; readonly query: string; readonly tab?: WorkspaceTab }
- | { readonly type: "expand"; readonly tab?: WorkspaceTab }
- | { readonly type: "cancel"; readonly tab?: WorkspaceTab }
- | { readonly type: "scroll"; readonly tab: WorkspaceTab; readonly offset: number };
+ | { readonly type: "search"; readonly tab?: WorkspaceSearchTab }
+ | { readonly type: "query"; readonly query: string; readonly tab?: WorkspaceSearchTab }
+ | { readonly type: "expand"; readonly tab?: WorkspaceSearchTab }
+ | { readonly type: "cancel"; readonly tab?: WorkspaceSearchTab }
+ | { readonly type: "scroll"; readonly tab: WorkspaceSearchTab; readonly offset: number };
export function workspaceTabsReducer(
state: WorkspaceTabsState,
@@ -69,7 +72,7 @@ export function workspaceTabsReducer(
selectionRevision: state.selectionRevision + 1,
};
const tab = action.tab ?? state.selectedTab;
- if (tab !== "threads" && tab !== "pullRequests") return state;
+ if (tab !== "threads" && tab !== "pullRequests" && tab !== "settings") return state;
const current = state.tabs[tab];
let next: WorkspaceTabState;
switch (action.type) {