Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

feat(search): switch colour themes from the command bar (MUL-9047) (#10378)

Jiayuan Zhangd44d6866a9b7
diff --git a/packages/views/layout/account-menu.tsx b/packages/views/layout/account-menu.tsx
index 11c0a59679..ac2258595f 100644
--- a/packages/views/layout/account-menu.tsx
+++ b/packages/views/layout/account-menu.tsx
@@ -15,7 +15,7 @@ import {
Sun,
User,
} from "@multica/ui/icons";
-import { BUILT_IN_THEMES, useAppearanceStore, useInstalledThemesStore } from "@multica/core/appearance";
+import { useAppearanceStore } from "@multica/core/appearance";
import { useAuthStore } from "@multica/core/auth";
import { useWorkspacePaths } from "@multica/core/paths";
import type { SupportedLocale } from "@multica/core/i18n";
@@ -44,7 +44,7 @@ import { useLanguageSwitch } from "../common/use-language-switch";
import { useT } from "../i18n";
import { AppLink } from "../navigation";
import { isDesktopShell } from "../platform/local-directory";
-import { ThemeSwatch, useAppliedMode, useThemeLabel } from "../settings/components/theme-swatch";
+import { ThemeSwatch, useAppliedMode, useColorThemes, useThemeLabel } from "../settings/components/theme-swatch";
import { DISCORD_URL, DiscordIcon } from "./discord";
import { CHANGELOG_URL, DOCS_URL, DOWNLOAD_URL } from "./help-links";
import { RAIL_ICON_BUTTON_CLASS } from "./rail-styles";
@@ -86,15 +86,11 @@ export function AccountMenu() {
const logout = useLogout();
const { theme: mode, setTheme: setMode } = useTheme();
const appliedMode = useAppliedMode();
- const colorTheme = useAppearanceStore((s) => s.theme);
const setAppearance = useAppearanceStore((s) => s.set);
- const installedThemes = useInstalledThemesStore((s) => s.themes);
+ const { themes: colorThemes, selected: selectedTheme } = useColorThemes();
const themeLabel = useThemeLabel();
const language = useLanguageSwitch();
const modeValue = (mode ?? "system") as (typeof THEMES)[number]["value"];
- const colorThemes = [...BUILT_IN_THEMES, ...installedThemes];
- const selectedTheme =
- colorThemes.find((manifest) => manifest.id === colorTheme) ?? BUILT_IN_THEMES[0]!;
const name = user?.name ?? "";
const avatar = (size: "md" | "lg") => (
<ActorAvatar
diff --git a/packages/views/locales/en/search.json b/packages/views/locales/en/search.json
index ac78ef92d9..7f37331a67 100644
--- a/packages/views/locales/en/search.json
+++ b/packages/views/locales/en/search.json
@@ -34,6 +34,7 @@
},
"commands": {
"current_theme_aria": "Current theme",
+ "current_mode_aria": "Current mode",
"new_issue": "New issue",
"new_project": "New project",
"new_autopilot": "New autopilot",
@@ -106,7 +107,6 @@
"project": "Project",
"parent": "Parent issue",
"quick_actions": "Quick actions",
- "theme": "Theme",
"project_status": "Project status",
"no_project": "No project",
"current": "Current"
diff --git a/packages/views/locales/es/search.json b/packages/views/locales/es/search.json
index fe1cb4784f..99245ccc20 100644
--- a/packages/views/locales/es/search.json
+++ b/packages/views/locales/es/search.json
@@ -22,6 +22,7 @@
},
"commands": {
"current_theme_aria": "Tema actual",
+ "current_mode_aria": "Modo actual",
"new_issue": "Nueva tarea",
"new_project": "Nuevo proyecto",
"copy_issue_link": "Copiar enlace de la tarea",
@@ -128,7 +129,6 @@
"project": "Proyecto",
"parent": "Tarea principal",
"quick_actions": "Acciones rápidas",
- "theme": "Tema",
"project_status": "Estado del proyecto",
"no_project": "Sin proyecto",
"current": "Actual"
diff --git a/packages/views/locales/fr/search.json b/packages/views/locales/fr/search.json
index c8d2347894..43cd5ce54b 100644
--- a/packages/views/locales/fr/search.json
+++ b/packages/views/locales/fr/search.json
@@ -34,6 +34,7 @@
},
"commands": {
"current_theme_aria": "Thème actuel",
+ "current_mode_aria": "Mode actuel",
"new_issue": "Nouvelle tâche",
"new_project": "Nouveau projet",
"new_autopilot": "Nouvelle automatisation",
@@ -106,7 +107,6 @@
"project": "Projet",
"parent": "Tâche parente",
"quick_actions": "Actions rapides",
- "theme": "Thème",
"project_status": "Statut du projet",
"no_project": "Aucun projet",
"current": "Actuel"
diff --git a/packages/views/locales/ja/search.json b/packages/views/locales/ja/search.json
index a82273a951..7ceb3b3490 100644
--- a/packages/views/locales/ja/search.json
+++ b/packages/views/locales/ja/search.json
@@ -33,6 +33,7 @@
},
"commands": {
"current_theme_aria": "現在のテーマ",
+ "current_mode_aria": "現在のモード",
"new_issue": "新規タスク",
"new_project": "新規プロジェクト",
"new_autopilot": "新規オートパイロット",
@@ -103,7 +104,6 @@
"project": "プロジェクト",
"parent": "親タスク",
"quick_actions": "クイックアクション",
- "theme": "テーマ",
"project_status": "プロジェクトのステータス",
"no_project": "プロジェクトなし",
"current": "現在"
diff --git a/packages/views/locales/ko/search.json b/packages/views/locales/ko/search.json
index ec3fbddbdd..cdce8db951 100644
--- a/packages/views/locales/ko/search.json
+++ b/packages/views/locales/ko/search.json
@@ -33,6 +33,7 @@
},
"commands": {
"current_theme_aria": "현재 테마",
+ "current_mode_aria": "현재 모드",
"new_issue": "새 태스크",
"new_project": "새 프로젝트",
"new_autopilot": "새 오토파일럿",
@@ -103,7 +104,6 @@
"project": "프로젝트",
"parent": "상위 태스크",
"quick_actions": "빠른 작업",
- "theme": "테마",
"project_status": "프로젝트 상태",
"no_project": "프로젝트 없음",
"current": "현재"
diff --git a/packages/views/locales/ru/search.json b/packages/views/locales/ru/search.json
index 5137f20b44..117614d91d 100644
--- a/packages/views/locales/ru/search.json
+++ b/packages/views/locales/ru/search.json
@@ -36,6 +36,7 @@
},
"commands": {
"current_theme_aria": "Текущая тема",
+ "current_mode_aria": "Текущий режим",
"new_issue": "Новая задача",
"new_project": "Новый проект",
"new_autopilot": "Новый автопилот",
@@ -112,7 +113,6 @@
"project": "Проект",
"parent": "Родительская задача",
"quick_actions": "Быстрые действия",
- "theme": "Тема",
"project_status": "Статус проекта",
"no_project": "Без проекта",
"current": "Текущий"
diff --git a/packages/views/locales/zh-Hans/search.json b/packages/views/locales/zh-Hans/search.json
index 47fdf20bd1..d8312dc59f 100644
--- a/packages/views/locales/zh-Hans/search.json
+++ b/packages/views/locales/zh-Hans/search.json
@@ -33,6 +33,7 @@
},
"commands": {
"current_theme_aria": "当前主题",
+ "current_mode_aria": "当前模式",
"new_issue": "新建任务",
"new_project": "新建项目",
"new_autopilot": "新建自动化",
@@ -103,7 +104,6 @@
"project": "项目",
"parent": "父任务",
"quick_actions": "快捷操作",
- "theme": "主题",
"project_status": "项目状态",
"no_project": "无项目",
"current": "当前"
diff --git a/packages/views/locales/zh-Hant/search.json b/packages/views/locales/zh-Hant/search.json
index 013cc1cdad..503b8ddb03 100644
--- a/packages/views/locales/zh-Hant/search.json
+++ b/packages/views/locales/zh-Hant/search.json
@@ -33,6 +33,7 @@
},
"commands": {
"current_theme_aria": "當前主題",
+ "current_mode_aria": "當前模式",
"new_issue": "新建任務",
"new_project": "新建專案",
"new_autopilot": "新建自動化",
@@ -103,7 +104,6 @@
"project": "專案",
"parent": "父任務",
"quick_actions": "快捷操作",
- "theme": "主題",
"project_status": "專案狀態",
"no_project": "無專案",
"current": "目前"
diff --git a/packages/views/search/commands/global-commands.tsx b/packages/views/search/commands/global-commands.tsx
index 474727d4ee..72dd55d9a2 100644
--- a/packages/views/search/commands/global-commands.tsx
+++ b/packages/views/search/commands/global-commands.tsx
@@ -132,7 +132,7 @@ export function useGlobalCommands(contexts: readonly CommandBarContext[]): Palet
id: "theme",
label: t(($) => $.commands.change_theme),
icon: Palette,
- keywords: ["theme", "appearance", "dark", "light", "system", "mode", "主题", "深色", "浅色"],
+ keywords: ["theme", "appearance", "dark", "light", "system", "mode", "color", "colour", "主题", "深色", "浅色", "配色"],
page: { type: "theme" },
},
{
diff --git a/packages/views/search/pages/other-pages.tsx b/packages/views/search/pages/other-pages.tsx
index c77db78281..95eb204a74 100644
--- a/packages/views/search/pages/other-pages.tsx
+++ b/packages/views/search/pages/other-pages.tsx
@@ -4,6 +4,7 @@ import { useQuery, useQueryClient } from "@tanstack/react-query";
import { toast } from "sonner";
import { FolderMinus, Monitor, Moon, SquarePen, Sun } from "@multica/ui/icons";
import { Command as CommandPrimitive } from "cmdk";
+import { useAppearanceStore } from "@multica/core/appearance";
import { useWorkspaceId } from "@multica/core/hooks";
import { useIssueStatuses } from "@multica/core/issue-statuses/hooks";
import { issueDetailOptions } from "@multica/core/issues/queries";
@@ -18,6 +19,7 @@ import { cn } from "@multica/ui/lib/utils";
import { runConfirmIntent } from "../../issues/actions/run-confirm-gate";
import { ProjectIcon } from "../../projects/components/project-icon";
import { useProjectStatusLabels } from "../../projects/components/labels";
+import { ThemeSwatch, useAppliedMode, useColorThemes, useThemeLabel } from "../../settings/components/theme-swatch";
import { useT } from "../../i18n";
import { HighlightText } from "../highlight-text";
import { scoreRow, scoreText } from "../matching";
@@ -30,35 +32,69 @@ type ThemeValue = "light" | "dark" | "system";
export function ThemePage({ query }: { query: string }) {
const { t } = useT("search");
+ const { t: tLayout } = useT("layout");
const palette = usePalette();
- const { theme, setTheme } = useTheme();
+ const { theme: mode, setTheme: setMode } = useTheme();
+ const appliedMode = useAppliedMode();
+ const setAppearance = useAppearanceStore((s) => s.set);
+ const { themes, selected } = useColorThemes();
+ const themeLabel = useThemeLabel();
+ const currentMode = mode ?? "system";
const q = query.trim().toLowerCase();
- const options: { value: ThemeValue; label: string; icon: typeof Sun; keywords: string[] }[] = [
+ const modes: { value: ThemeValue; label: string; icon: typeof Sun; keywords: string[] }[] = [
{ value: "light", label: t(($) => $.theme.light), icon: Sun, keywords: ["light", "bright", "浅色"] },
{ value: "dark", label: t(($) => $.theme.dark), icon: Moon, keywords: ["dark", "night", "深色"] },
{ value: "system", label: t(($) => $.theme.system), icon: Monitor, keywords: ["system", "auto", "系统"] },
];
- const visible = q ? options.filter((o) => scoreRow(o.label, o.keywords, q) > 0) : options;
+ const visibleModes = q ? modes.filter((o) => scoreRow(o.label, o.keywords, q) > 0) : modes;
+ const visibleThemes = q
+ ? themes.filter((manifest) => scoreRow(themeLabel(manifest), [manifest.id, manifest.name], q) > 0)
+ : themes;
return (
- <PaletteGroup heading={t(($) => $.pages.theme)}>
- {visible.map((option) => (
- <CommandPrimitive.Item
- key={option.value}
- value={`theme:${option.value}`}
- onSelect={() => {
- palette.close();
- setTheme(option.value);
- }}
- className={ROW_CLASS}
- >
- <option.icon className={ROW_ICON_CLASS} />
- <span className="min-w-0 flex-1 truncate">
- <HighlightText text={option.label} query={query} />
- </span>
- {theme === option.value && <RowCheck label={t(($) => $.commands.current_theme_aria)} />}
- </CommandPrimitive.Item>
- ))}
- </PaletteGroup>
+ <>
+ {visibleModes.length > 0 && (
+ <PaletteGroup heading={tLayout(($) => $.account.mode)}>
+ {visibleModes.map((option) => (
+ <CommandPrimitive.Item
+ key={option.value}
+ value={`theme:${option.value}`}
+ onSelect={() => {
+ palette.close();
+ setMode(option.value);
+ }}
+ className={ROW_CLASS}
+ >
+ <option.icon className={ROW_ICON_CLASS} />
+ <span className="min-w-0 flex-1 truncate">
+ <HighlightText text={option.label} query={query} />
+ </span>
+ {currentMode === option.value && <RowCheck label={t(($) => $.commands.current_mode_aria)} />}
+ </CommandPrimitive.Item>
+ ))}
+ </PaletteGroup>
+ )}
+ {visibleThemes.length > 0 && (
+ <PaletteGroup heading={tLayout(($) => $.account.theme)}>
+ {visibleThemes.map((manifest) => (
+ <CommandPrimitive.Item
+ key={manifest.id}
+ value={`color-theme:${manifest.id}`}
+ onSelect={() => {
+ palette.close();
+ setAppearance({ theme: manifest.id });
+ }}
+ className={ROW_CLASS}
+ >
+ <ThemeSwatch theme={manifest} mode={appliedMode} />
+ <span className="min-w-0 flex-1 truncate">
+ <HighlightText text={themeLabel(manifest)} query={query} />
+ </span>
+ {selected.id === manifest.id && <RowCheck label={t(($) => $.commands.current_theme_aria)} />}
+ </CommandPrimitive.Item>
+ ))}
+ </PaletteGroup>
+ )}
+ </>
);
}
diff --git a/packages/views/search/search-command.test.tsx b/packages/views/search/search-command.test.tsx
index 5a82238cf0..efb445508c 100644
--- a/packages/views/search/search-command.test.tsx
+++ b/packages/views/search/search-command.test.tsx
@@ -2,6 +2,7 @@ import { act, type ReactNode } from "react";
import { fireEvent, render, screen, waitFor, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { beforeEach, describe, expect, it, vi, type Mock } from "vitest";
+import { DEFAULT_APPEARANCE, useAppearanceStore, useInstalledThemesStore } from "@multica/core/appearance";
import { buildIssueStatusCatalog } from "@multica/core/issue-statuses/queries";
import {
useCommandBarContextStore,
@@ -377,6 +378,8 @@ describe("SearchCommand", () => {
mockToast.warning.mockReset();
mockSetTheme.mockReset();
mockTheme.current = "system";
+ useAppearanceStore.setState(DEFAULT_APPEARANCE);
+ useInstalledThemesStore.setState({ themes: [], folders: {}, fromStore: {} });
mockCommentCollapseAll.mockReset();
mockCommentExpandAll.mockReset();
mockResolvedCollapseAll.mockReset();
@@ -513,7 +516,7 @@ describe("SearchCommand", () => {
expect(useSearchStore.getState().open).toBe(false);
});
- it("changes theme through a submenu that marks the current theme", async () => {
+ it("changes the mode through a submenu that marks the current mode and theme", async () => {
const user = userEvent.setup();
mockTheme.current = "dark";
renderSearch();
@@ -521,14 +524,80 @@ describe("SearchCommand", () => {
await user.click(await rowText("Change theme..."));
expect(within(screen.getByRole("navigation", { name: "Current menu" })).getByText("Change theme")).toBeInTheDocument();
- expect(renderedValues()).toEqual(["theme:light", "theme:dark", "theme:system"]);
- expect(screen.getByLabelText("Current theme")).toBeInTheDocument();
+ expect(renderedHeadings()).toEqual(["Mode", "Theme"]);
+ expect(renderedValues()).toEqual([
+ "theme:light",
+ "theme:dark",
+ "theme:system",
+ "color-theme:default",
+ "color-theme:pop",
+ "color-theme:github",
+ "color-theme:blueprint",
+ "color-theme:notion",
+ ]);
+ expect(screen.getByLabelText("Current mode").closest("[cmdk-item]")).toHaveAttribute("data-value", "theme:dark");
+ expect(screen.getByLabelText("Current theme").closest("[cmdk-item]")).toHaveAttribute(
+ "data-value",
+ "color-theme:default",
+ );
await user.click(screen.getByText("Light"));
expect(mockSetTheme).toHaveBeenCalledWith("light");
expect(useSearchStore.getState().open).toBe(false);
});
+ it("switches the colour theme from the theme submenu", async () => {
+ const user = userEvent.setup();
+ useAppearanceStore.setState({ theme: "github" });
+ renderSearch();
+ await user.type(input(), "主题");
+ await user.click(await rowText("Change theme..."));
+
+ expect(screen.getByLabelText("Current theme").closest("[cmdk-item]")).toHaveAttribute(
+ "data-value",
+ "color-theme:github",
+ );
+ await user.click(screen.getByText("Pop"));
+
+ expect(useAppearanceStore.getState().theme).toBe("pop");
+ expect(mockSetTheme).not.toHaveBeenCalled();
+ expect(useSearchStore.getState().open).toBe(false);
+ });
+
+ it("finds installed themes by id and truncates a long name", async () => {
+ const user = userEvent.setup();
+ const name = "A very long community theme name, forty!";
+ useInstalledThemesStore.setState({
+ themes: [{ apiVersion: 1, id: "solarized", name, css: "" }],
+ folders: {},
+ fromStore: {},
+ });
+ renderSearch();
+ await user.type(input(), "theme");
+ await user.click(await rowText("Change theme..."));
+ await user.type(screen.getByPlaceholderText("Filter..."), "solar");
+
+ expect(renderedHeadings()).toEqual(["Theme"]);
+ expect(renderedValues()).toEqual(["color-theme:solarized"]);
+ expect(await rowText(name)).toHaveClass("min-w-0", "flex-1", "truncate");
+
+ await user.keyboard("{Enter}");
+ expect(useAppearanceStore.getState().theme).toBe("solarized");
+ });
+
+ it("marks Default when the chosen theme is no longer installed", async () => {
+ const user = userEvent.setup();
+ useAppearanceStore.setState({ theme: "uninstalled" });
+ renderSearch();
+ await user.type(input(), "theme");
+ await user.click(await rowText("Change theme..."));
+
+ expect(screen.getByLabelText("Current theme").closest("[cmdk-item]")).toHaveAttribute(
+ "data-value",
+ "color-theme:default",
+ );
+ });
+
it("Backspace on an empty submenu input returns to the root", async () => {
const user = userEvent.setup();
renderSearch();
diff --git a/packages/views/settings/components/appearance-tab.tsx b/packages/views/settings/components/appearance-tab.tsx
index 68a0c833f7..a12ea71e1f 100644
--- a/packages/views/settings/components/appearance-tab.tsx
+++ b/packages/views/settings/components/appearance-tab.tsx
@@ -103,7 +103,7 @@ import { docsLocalePrefix } from "../../common/docs-locale";
import { openExternal } from "../../platform/open-external";
import { themeFolderAPI } from "../../platform/theme-folder";
import { ThemesButton, useStoreThemeInstall } from "./themes-dialog";
-import { ThemeSwatch, useAppliedMode, useThemeLabel, type PreviewMode } from "./theme-swatch";
+import { ThemeSwatch, useAppliedMode, useColorThemes, useThemeLabel, type PreviewMode } from "./theme-swatch";
import {
SettingsCard,
SettingsRow,
@@ -196,8 +196,8 @@ function ColorSection() {
const themeLabel = t(($) => $.appearance.theme.title);
const imported = installed.filter((manifest) => !(manifest.id in folders));
const fromFolder = installed.filter((manifest) => manifest.id in folders);
- const selected = [...BUILT_IN_THEMES, ...installed].find((manifest) => manifest.id === theme);
- const items = [...BUILT_IN_THEMES, ...installed].map((manifest) => ({
+ const { themes, selected } = useColorThemes();
+ const items = themes.map((manifest) => ({
value: manifest.id,
label: themeLabelFor(manifest),
}));
@@ -235,19 +235,17 @@ function ColorSection() {
<div className="flex items-center gap-2">
<Select
items={items}
- value={selected ? theme : "default"}
+ value={selected.id}
onValueChange={(next) => {
if (next) set({ theme: next });
}}
>
<SelectTrigger size="sm" className="w-48" aria-label={themeLabel}>
<SelectValue>
- {selected ? (
- <span className="flex min-w-0 items-center gap-2">
- <ThemeSwatch theme={selected} mode={appliedMode} />
- <span className="truncate">{themeLabelFor(selected)}</span>
- </span>
- ) : null}
+ <span className="flex min-w-0 items-center gap-2">
+ <ThemeSwatch theme={selected} mode={appliedMode} />
+ <span className="truncate">{themeLabelFor(selected)}</span>
+ </span>
</SelectValue>
</SelectTrigger>
<SelectContent align="end" className="min-w-64">
diff --git a/packages/views/settings/components/theme-swatch.tsx b/packages/views/settings/components/theme-swatch.tsx
index 2e8d8960e8..5656e55a6e 100644
--- a/packages/views/settings/components/theme-swatch.tsx
+++ b/packages/views/settings/components/theme-swatch.tsx
@@ -1,6 +1,15 @@
"use client";
-import { themeModeVariables, type Theme } from "@multica/core/appearance";
+import { useMemo } from "react";
+import {
+ BUILT_IN_THEMES,
+ DEFAULT_THEME_ID,
+ findBuiltInTheme,
+ themeModeVariables,
+ useAppearanceStore,
+ useInstalledThemesStore,
+ type Theme,
+} from "@multica/core/appearance";
import { useTheme } from "@multica/ui/components/common/theme-provider";
import { useT } from "../../i18n";
@@ -23,6 +32,18 @@ export function useThemeLabel() {
: theme.name;
}
+/**
+ * The themes a person can pick, built-in ones first, and the one in use:
+ * Default when the chosen theme is no longer installed.
+ */
+export function useColorThemes(): { themes: readonly Theme[]; selected: Theme } {
+ const chosen = useAppearanceStore((s) => s.theme);
+ const installed = useInstalledThemesStore((s) => s.themes);
+ const themes = useMemo(() => [...BUILT_IN_THEMES, ...installed], [installed]);
+ const selected = themes.find((theme) => theme.id === chosen) ?? findBuiltInTheme(DEFAULT_THEME_ID)!;
+ return { themes, selected };
+}
+
type SwatchToken =
| "app-shell"
| "page-canvas"