@devries-cameron20 / t3code-1 / commits / 9ff8cdca85
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

refactor(web): the command palette's theme items live in their own file (#22679)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 21, 2026 at 01:13 UTC 9ff8cdca8565d8ae0cbfc22130ea65c040d97545
2 files changed +170 -146
apps/web/src/components/CommandPalette.tsx
+7 -146
@@ -67,13 +67,10 @@ import {
67 MessageSquareDashedIcon,
68 LinkIcon,
69 MessageSquareIcon,
70 - MonitorIcon,
71 - MoonIcon,
70 PaletteIcon,
71 RotateCcwIcon,
72 SettingsIcon,
73 SquarePenIcon,
76 - SunIcon,
74 TextSearchIcon,
75 } from "lucide-react";
76 import { requestThreadFindOpen } from "./chat/threadFindActionBus";
@@ -104,15 +101,6 @@ import {
101 import { useClientSettings } from "../hooks/useSettings";
102 import { useStableCallback } from "../hooks/useStableCallback";
103 import { useTheme } from "../hooks/useTheme";
107 -import { useCustomThemes } from "../hooks/useCustomThemes";
108 -import { useEnvironmentThemeDefinitions } from "../hooks/useEnvironmentTheme";
109 -import { BUILT_IN_THEMES } from "@t3tools/shared/themePalettes";
110 -import { getThemeDefinition } from "../themePalette";
111 -import {
112 - STANDARD_THEME_CARDS,
113 - getThemeCardDefinition,
114 - ThemePreviewCircle,
115 -} from "./settings/ThemePreviewCircles";
104 import { readLocalApi } from "../localApi";
105 import { desktopLocalBackendId } from "../connection/desktopLocal";
106 import { filesystemEnvironment, useFilesystemReadAccess } from "../state/filesystem";
@@ -203,6 +191,11 @@ import {
191 import { orderItemsByPreferredIds, sortLogicalProjectsForSidebar } from "./Sidebar.logic";
192 import { resolveEnvironmentOptionLabel } from "./BranchToolbar.logic";
193 import { CommandPaletteContent } from "./CommandPaletteContent";
194 +import {
195 + APPEARANCE_OPTIONS,
196 + notifyThemeSaveFailure,
197 + useCommandPaletteThemeItems,
198 +} from "./CommandPaletteThemeItems";
199 import {
200 CommandPaletteTitleIcon,
201 CommandPaletteVirtualizedResults,
@@ -357,41 +350,9 @@ function overlayModeForCommand(command: string | null): SearchOverlayMode | null
350 : null;
351 }
352
360 -const APPEARANCE_OPTIONS = [
361 - { mode: "system", label: "System", icon: MonitorIcon },
362 - { mode: "light", label: "Light", icon: SunIcon },
363 - { mode: "dark", label: "Dark", icon: MoonIcon },
364 -] as const;
365 -
366 -function notifyThemeSaveFailure(): void {
367 - toastManager.add(
368 - stackedThreadToast({
369 - type: "error",
370 - title: "Couldn't save theme selection",
371 - description: "Try again.",
372 - }),
373 - );
374 -}
375 -
353 // Each helper reads its own source hook so the compiler caches the derived value on that
354 // source. Taking the source as an argument instead leaves the helper hook-free, and the
355 // compiler then treats it as a plain function and caches nothing.
379 -function useThemeCards() {
380 - const customThemes = useCustomThemes();
381 - const environmentThemes = useEnvironmentThemeDefinitions();
382 - const seen = new Set<string>();
383 - return [
384 - ...STANDARD_THEME_CARDS.map((card) => ({ ...card, id: null })),
385 - ...[...BUILT_IN_THEMES, ...customThemes, ...environmentThemes]
386 - .filter((definition) => {
387 - if (seen.has(definition.id)) return false;
388 - seen.add(definition.id);
389 - return true;
390 - })
391 - .map(getThemeCardDefinition),
392 - ];
393 -}
394 -
356 function useThreadSearchWithContentMatches(
357 environmentIds: ReadonlyArray<EnvironmentId>,
358 query: string,
@@ -817,16 +778,7 @@ function OpenCommandPaletteDialog(props: {
778 };
779 const threads = useThreadShells();
780 const keybindings = useAtomValue(primaryServerKeybindingsAtom);
820 - const {
821 - theme,
822 - themeHalves,
823 - resolvedTheme,
824 - appearanceMode,
825 - setAppearanceMode,
826 - setTheme,
827 - setThemeHalf,
828 - } = useTheme();
829 - const themeCards = useThemeCards();
781 + const { changeThemeItem, changeAppearanceItem, themeEditorItem } = useCommandPaletteThemeItems();
782 const providers = useAtomValue(primaryServerProvidersAtom);
783 const providersByEnvironment = useEnvironmentProviders();
784 const providerEntryByEnvironmentAndInstanceId = new Map<string, ProviderInstanceEntry>(
@@ -1863,84 +1815,7 @@ function OpenCommandPaletteDialog(props: {
1815 });
1816 }
1817
1866 - const changeThemeItem: CommandPaletteSubmenuItem = {
1867 - kind: "submenu",
1868 - value: "action:change-theme",
1869 - searchTerms: ["change theme", "appearance", "colors", "palette"],
1870 - title: "Change theme",
1871 - icon: <PaletteIcon className={ITEM_ICON_CLASS} />,
1872 - addonIcon: <PaletteIcon className={ADDON_ICON_CLASS} />,
1873 - shortcutCommand: "theme.select",
1874 - groups: [
1875 - {
1876 - value: "themes",
1877 - label: "Change theme",
1878 - items: themeCards.map(({ id, label, previews }) => ({
1879 - kind: "action",
1880 - value: id === null ? "theme:standard" : `theme:palette:${id}`,
1881 - title: label,
1882 - description: previews.length === 1 ? `For ${previews[0]!.mode} mode` : undefined,
1883 - searchTerms: [label, "theme", "appearance"],
1884 - icon: <PaletteIcon className={ITEM_ICON_CLASS} />,
1885 - titleTrailingContent: (
1886 - <span className="flex shrink-0 items-center gap-2">
1887 - {(themeHalves?.[resolvedTheme] ?? getThemeDefinition(theme)?.id ?? null) === id ? (
1888 - <span className="text-xs text-muted-foreground/70">Current</span>
1889 - ) : null}
1890 - <span className="flex items-center gap-1" aria-hidden>
1891 - {previews.map((preview) => (
1892 - <ThemePreviewCircle
1893 - key={preview.mode}
1894 - colors={preview.colors}
1895 - mode={preview.mode}
1896 - className="size-3 border-0"
1897 - />
1898 - ))}
1899 - </span>
1900 - </span>
1901 - ),
1902 - run: async () => {
1903 - const saved =
1904 - previews.length === 1 && id !== null
1905 - ? setThemeHalf(previews[0]!.mode, id)
1906 - : setTheme(id ?? appearanceMode);
1907 - if (!saved) notifyThemeSaveFailure();
1908 - },
1909 - })),
1910 - },
1911 - ],
1912 - };
1818 actionItems.push(changeThemeItem);
1914 -
1915 - const changeAppearanceItem: CommandPaletteSubmenuItem = {
1916 - kind: "submenu",
1917 - value: "action:change-appearance",
1918 - searchTerms: ["change appearance", "light", "dark", "system", "mode", "toggle"],
1919 - title: "Change appearance",
1920 - icon: <MonitorIcon className={ITEM_ICON_CLASS} />,
1921 - addonIcon: <MonitorIcon className={ADDON_ICON_CLASS} />,
1922 - shortcutCommand: "appearance.cycle",
1923 - groups: [
1924 - {
1925 - value: "appearance",
1926 - label: "Change appearance",
1927 - items: APPEARANCE_OPTIONS.map(({ mode, label, icon: Icon }) => ({
1928 - kind: "action",
1929 - value: `appearance:${mode}`,
1930 - title: label,
1931 - searchTerms: [label, "appearance", "mode"],
1932 - icon: <Icon className={ITEM_ICON_CLASS} />,
1933 - titleTrailingContent:
1934 - appearanceMode === mode ? (
1935 - <span className="text-xs text-muted-foreground/70">Current</span>
1936 - ) : undefined,
1937 - run: async () => {
1938 - if (!setAppearanceMode(mode)) notifyThemeSaveFailure();
1939 - },
1940 - })),
1941 - },
1942 - ],
1943 - };
1819 actionItems.push(changeAppearanceItem);
1820
1821 // The parent pushes an intent into this mounted dialog; applying it clears the
@@ -1984,21 +1859,7 @@ function OpenCommandPaletteDialog(props: {
1859 applyOpenIntent(openIntent);
1860 }, [openIntent, projectThreadItemCount]);
1861
1987 - actionItems.push({
1988 - kind: "action",
1989 - value: "action:theme-editor",
1990 - searchTerms: ["theme", "appearance", "colors", "palette", "customize"],
1991 - title: "Toggle theme editor",
1992 - icon: <PaletteIcon className={ITEM_ICON_CLASS} />,
1993 - shortcutCommand: "themeEditor.toggle",
1994 - run: async () => {
1995 - toggleThemeEditorForTheme({
1996 - theme,
1997 - themeHalves,
1998 - initialAppearance: resolvedTheme,
1999 - });
2000 - },
2001 - });
1862 + actionItems.push(themeEditorItem);
1863
1864 if (
1865 environments.some(
apps/web/src/components/CommandPaletteThemeItems.tsx new
+163
@@ -0,0 +1,163 @@
1 +import { BUILT_IN_THEMES } from "@t3tools/shared/themePalettes";
2 +import { MonitorIcon, MoonIcon, PaletteIcon, SunIcon } from "lucide-react";
3 +
4 +import { useCustomThemes } from "../hooks/useCustomThemes";
5 +import { useEnvironmentThemeDefinitions } from "../hooks/useEnvironmentTheme";
6 +import { useTheme } from "../hooks/useTheme";
7 +import { getThemeDefinition } from "../themePalette";
8 +import {
9 + ADDON_ICON_CLASS,
10 + ITEM_ICON_CLASS,
11 + type CommandPaletteActionItem,
12 + type CommandPaletteSubmenuItem,
13 +} from "./CommandPalette.logic";
14 +import { toggleThemeEditorForTheme } from "./settings/themeEditorStore";
15 +import {
16 + STANDARD_THEME_CARDS,
17 + getThemeCardDefinition,
18 + ThemePreviewCircle,
19 +} from "./settings/ThemePreviewCircles";
20 +import { stackedThreadToast, toastManager } from "./ui/toast";
21 +
22 +export const APPEARANCE_OPTIONS = [
23 + { mode: "system", label: "System", icon: MonitorIcon },
24 + { mode: "light", label: "Light", icon: SunIcon },
25 + { mode: "dark", label: "Dark", icon: MoonIcon },
26 +] as const;
27 +
28 +export function notifyThemeSaveFailure(): void {
29 + toastManager.add(
30 + stackedThreadToast({
31 + type: "error",
32 + title: "Couldn't save theme selection",
33 + description: "Try again.",
34 + }),
35 + );
36 +}
37 +
38 +// Reads its own source hooks so the compiler caches the cards on them. Taking the
39 +// sources as arguments would leave it hook-free, and the compiler would cache nothing.
40 +function useThemeCards() {
41 + const customThemes = useCustomThemes();
42 + const environmentThemes = useEnvironmentThemeDefinitions();
43 + const seen = new Set<string>();
44 + return [
45 + ...STANDARD_THEME_CARDS.map((card) => ({ ...card, id: null })),
46 + ...[...BUILT_IN_THEMES, ...customThemes, ...environmentThemes]
47 + .filter((definition) => {
48 + if (seen.has(definition.id)) return false;
49 + seen.add(definition.id);
50 + return true;
51 + })
52 + .map(getThemeCardDefinition),
53 + ];
54 +}
55 +
56 +export function useCommandPaletteThemeItems() {
57 + const {
58 + theme,
59 + themeHalves,
60 + resolvedTheme,
61 + appearanceMode,
62 + setAppearanceMode,
63 + setTheme,
64 + setThemeHalf,
65 + } = useTheme();
66 + const themeCards = useThemeCards();
67 +
68 + const changeThemeItem: CommandPaletteSubmenuItem = {
69 + kind: "submenu",
70 + value: "action:change-theme",
71 + searchTerms: ["change theme", "appearance", "colors", "palette"],
72 + title: "Change theme",
73 + icon: <PaletteIcon className={ITEM_ICON_CLASS} />,
74 + addonIcon: <PaletteIcon className={ADDON_ICON_CLASS} />,
75 + shortcutCommand: "theme.select",
76 + groups: [
77 + {
78 + value: "themes",
79 + label: "Change theme",
80 + items: themeCards.map(({ id, label, previews }) => ({
81 + kind: "action",
82 + value: id === null ? "theme:standard" : `theme:palette:${id}`,
83 + title: label,
84 + description: previews.length === 1 ? `For ${previews[0]!.mode} mode` : undefined,
85 + searchTerms: [label, "theme", "appearance"],
86 + icon: <PaletteIcon className={ITEM_ICON_CLASS} />,
87 + titleTrailingContent: (
88 + <span className="flex shrink-0 items-center gap-2">
89 + {(themeHalves?.[resolvedTheme] ?? getThemeDefinition(theme)?.id ?? null) === id ? (
90 + <span className="text-xs text-muted-foreground/70">Current</span>
91 + ) : null}
92 + <span className="flex items-center gap-1" aria-hidden>
93 + {previews.map((preview) => (
94 + <ThemePreviewCircle
95 + key={preview.mode}
96 + colors={preview.colors}
97 + mode={preview.mode}
98 + className="size-3 border-0"
99 + />
100 + ))}
101 + </span>
102 + </span>
103 + ),
104 + run: async () => {
105 + const saved =
106 + previews.length === 1 && id !== null
107 + ? setThemeHalf(previews[0]!.mode, id)
108 + : setTheme(id ?? appearanceMode);
109 + if (!saved) notifyThemeSaveFailure();
110 + },
111 + })),
112 + },
113 + ],
114 + };
115 +
116 + const changeAppearanceItem: CommandPaletteSubmenuItem = {
117 + kind: "submenu",
118 + value: "action:change-appearance",
119 + searchTerms: ["change appearance", "light", "dark", "system", "mode", "toggle"],
120 + title: "Change appearance",
121 + icon: <MonitorIcon className={ITEM_ICON_CLASS} />,
122 + addonIcon: <MonitorIcon className={ADDON_ICON_CLASS} />,
123 + shortcutCommand: "appearance.cycle",
124 + groups: [
125 + {
126 + value: "appearance",
127 + label: "Change appearance",
128 + items: APPEARANCE_OPTIONS.map(({ mode, label, icon: Icon }) => ({
129 + kind: "action",
130 + value: `appearance:${mode}`,
131 + title: label,
132 + searchTerms: [label, "appearance", "mode"],
133 + icon: <Icon className={ITEM_ICON_CLASS} />,
134 + titleTrailingContent:
135 + appearanceMode === mode ? (
136 + <span className="text-xs text-muted-foreground/70">Current</span>
137 + ) : undefined,
138 + run: async () => {
139 + if (!setAppearanceMode(mode)) notifyThemeSaveFailure();
140 + },
141 + })),
142 + },
143 + ],
144 + };
145 +
146 + const themeEditorItem: CommandPaletteActionItem = {
147 + kind: "action",
148 + value: "action:theme-editor",
149 + searchTerms: ["theme", "appearance", "colors", "palette", "customize"],
150 + title: "Toggle theme editor",
151 + icon: <PaletteIcon className={ITEM_ICON_CLASS} />,
152 + shortcutCommand: "themeEditor.toggle",
153 + run: async () => {
154 + toggleThemeEditorForTheme({
155 + theme,
156 + themeHalves,
157 + initialAppearance: resolvedTheme,
158 + });
159 + },
160 + };
161 +
162 + return { changeThemeItem, changeAppearanceItem, themeEditorItem };
163 +}