Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(appearance): sort all store themes by downloads (#10588)
Jiayuan Zhang44e7d1f09b0f
diff --git a/packages/views/settings/components/themes-dialog.test.tsx b/packages/views/settings/components/themes-dialog.test.tsxindex b05bd9bdd8..034b79ca95 100644--- a/packages/views/settings/components/themes-dialog.test.tsx+++ b/packages/views/settings/components/themes-dialog.test.tsx@@ -1,6 +1,6 @@import type { ReactNode } from "react";import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";-import { cleanup, render, screen, waitFor } from "@testing-library/react";+import { act, cleanup, render, screen, waitFor } from "@testing-library/react";import userEvent from "@testing-library/user-event";import { QueryClient, QueryClientProvider } from "@tanstack/react-query";import { I18nProvider } from "@multica/core/i18n/react";@@ -136,13 +136,50 @@ describe("ThemesButton", () => {expect(screen.getByText("by Someone · 1 download")).toBeTruthy();expect(screen.getAllByRole("heading", { level: 3 }).map((h) => h.textContent)).toEqual(["Sand", "Ink"]);- api.listStoreThemes.mockResolvedValue([listed("ink", "Ink", "1.0.0", 2), listed("sand", "Sand", "1.0.0", 1250)]);- const [installSand] = screen.getAllByRole("button", { name: "Install" });- await user.click(installSand!);- expect(await screen.findByText("by Someone · 2 downloads")).toBeTruthy();+ api.listStoreThemes.mockResolvedValue([listed("ink", "Ink", "1.0.0", 2000), listed("sand", "Sand", "1.0.0", 1250)]);+ const [, installInk] = screen.getAllByRole("button", { name: "Install" });+ await user.click(installInk!);+ expect(await screen.findByText("by Someone · 2K downloads")).toBeTruthy();+ expect(screen.getAllByRole("heading", { level: 3 }).map((h) => h.textContent)).toEqual(["Ink", "Sand"]);expect(api.listStoreThemes).toHaveBeenCalledTimes(2);});+ it("ranks installed and available themes together after loading, preserving the order through filters", async () => {+ for (const [id, name] of [["ink", "Ink"], ["sand", "Sand"], ["paper", "Paper"]] as const) {+ const parsed = parseTheme({ manifest: manifest(id, name, "1.0.0"), css });+ if (!parsed.ok) throw new Error("fixture");+ if (id === "paper") useInstalledThemesStore.getState().install(parsed.theme);+ else useInstalledThemesStore.getState().installFromStore(parsed.theme, "1.0.0");+ }+ let resolveListing!: (themes: StoreTheme[]) => void;+ api.listStoreThemes.mockReturnValueOnce(new Promise<StoreTheme[]>((resolve) => {+ resolveListing = resolve;+ }));+ const user = userEvent.setup();+ renderButton();+ await user.click(screen.getByRole("button", { name: "Manage" }));+ const names = () => screen.getAllByRole("heading", { level: 3 }).map((h) => h.textContent);+ expect(names()).toEqual(["Ink", "Sand", "Paper"]);++ await act(async () => resolveListing([+ listed("ink", "Ink", "1.0.0", 2),+ listed("ash", "Ash"),+ listed("sand", "Sand", "1.0.0", 1250),+ listed("moss", "Moss", "1.0.0", 200),+ listed("birch", "Birch"),+ ]));+ await screen.findByRole("heading", { name: "Moss" });+ expect(names()).toEqual(["Sand", "Moss", "Ink", "Paper", "Ash", "Birch"]);++ await user.click(screen.getByRole("switch", { name: "Show installed only" }));+ expect(names()).toEqual(["Sand", "Ink", "Paper"]);+ await user.click(screen.getByRole("switch", { name: "Show installed only" }));+ await user.type(screen.getByRole("textbox", { name: "Search themes" }), "a");+ expect(names()).toEqual(["Sand", "Paper", "Ash"]);+ await user.clear(screen.getByRole("textbox", { name: "Search themes" }));+ expect(names()).toEqual(["Sand", "Moss", "Ink", "Paper", "Ash", "Birch"]);+ });+it("offers the listed release as an update", async () => {const parsed = parseTheme({ manifest: manifest("ink", "Ink", "0.9.0"), css });if (!parsed.ok) throw new Error("fixture");diff --git a/packages/views/settings/components/themes-dialog.tsx b/packages/views/settings/components/themes-dialog.tsxindex 863aabf4c7..a8675fc96c 100644--- a/packages/views/settings/components/themes-dialog.tsx+++ b/packages/views/settings/components/themes-dialog.tsx@@ -121,8 +121,7 @@ function Themes() {const [installedOnly, setInstalledOnly] = useState(false);const needle = query.trim().toLowerCase();- // Installed themes, then what the store offers. A theme installed from the- // store is shown as the store lists it.+ // A theme installed from the store is shown as the store lists it.const listed = new Map((listing.data ?? []).map((theme) => [theme.id, theme]));const local = (theme: Theme): Entry => {const store = theme.id in fromStore ? listed.get(theme.id) : undefined;@@ -132,8 +131,8 @@ function Themes() {: { kind: "local", key: theme.id, name: themeLabelFor(theme), author: theme.author ?? "", installed: true, theme };};const entries = installed.map(local);- for (const theme of [...listed.values()].sort((a, b) => b.downloads - a.downloads)) {- // A listed theme whose id is taken on this device is shown next to the one that has it.+ for (const theme of listed.values()) {+ // A listed theme whose id is taken on this device keeps a separate card.const taken = entries.some((entry) => entry.key === theme.id);entries.push({kind: "store",@@ -144,11 +143,14 @@ function Themes() {theme,});}- // A card keeps its place while the window is open, so installing or- // removing a theme does not move it from under the pointer.+ // Equal download counts keep their order, including after an install or removal.const order = useRef(new Map<string, number>()).current;for (const entry of entries) if (!order.has(entry.key)) order.set(entry.key, order.size);- entries.sort((a, b) => order.get(a.key)! - order.get(b.key)!);+ entries.sort((a, b) => {+ const aDownloads = a.kind === "store" ? a.theme.downloads : 0;+ const bDownloads = b.kind === "store" ? b.theme.downloads : 0;+ return bDownloads - aDownloads || order.get(a.key)! - order.get(b.key)!;+ });const shown = entries.filter((entry) =>