From 784493f144da08a1afc48fcbf241a5084db66cc2 Mon Sep 17 00:00:00 2001 From: "t3-code[bot]" <269035359+t3-code[bot]@users.noreply.github.com> Date: Fri, 7 Aug 2026 22:27:04 +0000 Subject: [PATCH] feat(web): integrate theme search with import --- .../components/settings/ThemeImportDialog.tsx | 19 +- .../components/settings/ThemeSearchDialog.tsx | 269 ------------------ .../settings/ThemeSearchSection.tsx | 246 ++++++++++++++++ .../src/components/settings/ThemeSettings.tsx | 23 -- 4 files changed, 264 insertions(+), 293 deletions(-) delete mode 100644 apps/web/src/components/settings/ThemeSearchDialog.tsx create mode 100644 apps/web/src/components/settings/ThemeSearchSection.tsx diff --git a/apps/web/src/components/settings/ThemeImportDialog.tsx b/apps/web/src/components/settings/ThemeImportDialog.tsx index a74842acac..d39b27b38c 100644 --- a/apps/web/src/components/settings/ThemeImportDialog.tsx +++ b/apps/web/src/components/settings/ThemeImportDialog.tsx @@ -28,6 +28,7 @@ import { DialogPopup, DialogTitle, } from "../ui/dialog"; +import { ThemeSearchSection } from "./ThemeSearchSection"; /** * A full theme export is a few KB, so anything past this is not a theme file. @@ -426,7 +427,23 @@ export function ThemeImportDialog({ Add a theme - + + { + onImportedMany(themes, { updated: false }); + onOpenChange(false); + }} + open={open} + /> + +
+
+ + or import a file + +
+
+ {(() => { const dropHandlers = { onDragEnter: (event: DragEvent) => { diff --git a/apps/web/src/components/settings/ThemeSearchDialog.tsx b/apps/web/src/components/settings/ThemeSearchDialog.tsx deleted file mode 100644 index 329c989c17..0000000000 --- a/apps/web/src/components/settings/ThemeSearchDialog.tsx +++ /dev/null @@ -1,269 +0,0 @@ -import { CheckCircle2Icon, PaletteIcon, PlusIcon, SearchIcon, ShieldCheckIcon } from "lucide-react"; -import type { FormEvent } from "react"; -import { useCallback, useEffect, useRef, useState } from "react"; -import { - importOpenVsxThemeExtension, - searchOpenVsxThemes, - type OpenVsxThemeExtension, -} from "../../openVsxThemes"; -import { - getCustomThemes, - installCustomTheme, - removeCustomTheme, - type ThemeDefinition, -} from "../../themePalette"; -import { Button } from "../ui/button"; -import { - Dialog, - DialogDescription, - DialogHeader, - DialogPanel, - DialogPopup, - DialogTitle, -} from "../ui/dialog"; -import { Input } from "../ui/input"; -import { Spinner } from "../ui/spinner"; - -const DOWNLOAD_FORMAT = new Intl.NumberFormat(undefined, { - notation: "compact", - maximumFractionDigits: 1, -}); -const SUGGESTED_SEARCHES = ["Dracula", "Catppuccin", "Nord", "Tokyo Night"]; - -export function ThemeSearchDialog({ - open, - onOpenChange, - onInstalled, -}: { - open: boolean; - onOpenChange: (open: boolean) => void; - onInstalled: (themes: ReadonlyArray) => void; -}) { - const [query, setQuery] = useState(""); - const [results, setResults] = useState | null>(null); - const [error, setError] = useState(null); - const [isSearching, setIsSearching] = useState(false); - const [installingId, setInstallingId] = useState(null); - const requestRef = useRef(null); - - useEffect(() => { - requestRef.current?.abort(); - requestRef.current = null; - if (!open) return; - setQuery(""); - setResults(null); - setError(null); - setIsSearching(false); - setInstallingId(null); - }, [open]); - - const runSearch = useCallback(async (searchText: string) => { - const trimmed = searchText.trim(); - if (!trimmed) return; - requestRef.current?.abort(); - const controller = new AbortController(); - requestRef.current = controller; - setQuery(trimmed); - setIsSearching(true); - setError(null); - setResults(null); - try { - const nextResults = await searchOpenVsxThemes(trimmed, controller.signal); - if (!controller.signal.aborted) setResults(nextResults); - } catch (cause) { - if (!controller.signal.aborted) { - setError(cause instanceof Error ? cause.message : "Open VSX search failed."); - } - } finally { - if (requestRef.current === controller) { - requestRef.current = null; - setIsSearching(false); - } - } - }, []); - - const handleSearch = useCallback( - (event: FormEvent) => { - event.preventDefault(); - void runSearch(query); - }, - [query, runSearch], - ); - - const handleInstall = useCallback( - async (extension: OpenVsxThemeExtension) => { - requestRef.current?.abort(); - const controller = new AbortController(); - requestRef.current = controller; - setInstallingId(extension.id); - setError(null); - try { - const themes = await importOpenVsxThemeExtension(extension, controller.signal); - if (controller.signal.aborted) return; - const existingIds = new Set(getCustomThemes().map((theme) => theme.id)); - const duplicates = themes.filter((theme) => existingIds.has(theme.id)); - if (duplicates.length > 0) { - throw new Error(`${duplicates.map((theme) => theme.label).join(", ")} is already added.`); - } - - const installed: ThemeDefinition[] = []; - try { - for (const theme of themes) installed.push(installCustomTheme(theme)); - } catch (cause) { - for (const theme of installed) { - try { - removeCustomTheme(theme.id); - } catch { - // Best effort rollback. The original storage failure is clearer. - } - } - throw cause; - } - onInstalled(installed); - onOpenChange(false); - } catch (cause) { - if (!controller.signal.aborted) { - setError(cause instanceof Error ? cause.message : "That theme could not be added."); - } - } finally { - if (requestRef.current === controller) { - requestRef.current = null; - setInstallingId(null); - } - } - }, - [onInstalled, onOpenChange], - ); - - return ( - { - if (!nextOpen) requestRef.current?.abort(); - onOpenChange(nextOpen); - }} - > - - - Search themes - - Find community themes from Open VSX and add them in one click. - - - -
- - setQuery(event.currentTarget.value)} - placeholder="try dracula, nord, catppuccin..." - size="lg" - type="search" - value={query} - /> - - - - {error ? ( -
- {error} -
- ) : null} - - {results === null && !isSearching ? ( -
-
-

What theme are you looking for?

-

- Only themes with a supported open-source license are shown. -

-
-
- {SUGGESTED_SEARCHES.map((suggestion) => ( - - ))} -
-
- ) : null} - - {isSearching ? ( -
- Finding themes... -
- ) : null} - - {results ? ( - results.length === 0 ? ( -
-

No supported open-source themes found

-

Try a broader search.

-
- ) : ( -
- {results.map((extension) => { - const isInstalling = installingId === extension.id; - return ( -
-
-
- -
-
-

{extension.name}

-

- {extension.publisher} ·{" "} - {DOWNLOAD_FORMAT.format(extension.downloadCount)} downloads -

-
-
-

- {extension.description || "A community color theme for your editor."} -

-
- - {extension.license} - - -
-
- ); - })} -
- ) - ) : null} - -
- Sourced from Open VSX, with license and package - integrity checks -
-
-
-
- ); -} diff --git a/apps/web/src/components/settings/ThemeSearchSection.tsx b/apps/web/src/components/settings/ThemeSearchSection.tsx new file mode 100644 index 0000000000..2e8aedc378 --- /dev/null +++ b/apps/web/src/components/settings/ThemeSearchSection.tsx @@ -0,0 +1,246 @@ +import { CheckCircle2Icon, PaletteIcon, PlusIcon, SearchIcon, ShieldCheckIcon } from "lucide-react"; +import type { FormEvent } from "react"; +import { useCallback, useEffect, useRef, useState } from "react"; +import { + importOpenVsxThemeExtension, + searchOpenVsxThemes, + type OpenVsxThemeExtension, +} from "../../openVsxThemes"; +import { + getCustomThemes, + installCustomTheme, + removeCustomTheme, + type ThemeDefinition, +} from "../../themePalette"; +import { Button } from "../ui/button"; +import { Input } from "../ui/input"; +import { Spinner } from "../ui/spinner"; + +const DOWNLOAD_FORMAT = new Intl.NumberFormat(undefined, { + notation: "compact", + maximumFractionDigits: 1, +}); +const SUGGESTED_SEARCHES = ["Dracula", "Catppuccin", "Nord", "Tokyo Night"]; + +export function ThemeSearchSection({ + open, + onInstalled, +}: { + open: boolean; + onInstalled: (themes: ReadonlyArray) => void; +}) { + const [query, setQuery] = useState(""); + const [results, setResults] = useState | null>(null); + const [error, setError] = useState(null); + const [isSearching, setIsSearching] = useState(false); + const [installingId, setInstallingId] = useState(null); + const requestRef = useRef(null); + + useEffect(() => { + requestRef.current?.abort(); + requestRef.current = null; + if (!open) return; + setQuery(""); + setResults(null); + setError(null); + setIsSearching(false); + setInstallingId(null); + }, [open]); + + const runSearch = useCallback(async (searchText: string) => { + const trimmed = searchText.trim(); + if (!trimmed) return; + requestRef.current?.abort(); + const controller = new AbortController(); + requestRef.current = controller; + setQuery(trimmed); + setIsSearching(true); + setError(null); + setResults(null); + try { + const nextResults = await searchOpenVsxThemes(trimmed, controller.signal); + if (!controller.signal.aborted) setResults(nextResults); + } catch (cause) { + if (!controller.signal.aborted) { + setError(cause instanceof Error ? cause.message : "Open VSX search failed."); + } + } finally { + if (requestRef.current === controller) { + requestRef.current = null; + setIsSearching(false); + } + } + }, []); + + const handleSearch = useCallback( + (event: FormEvent) => { + event.preventDefault(); + void runSearch(query); + }, + [query, runSearch], + ); + + const handleInstall = useCallback( + async (extension: OpenVsxThemeExtension) => { + requestRef.current?.abort(); + const controller = new AbortController(); + requestRef.current = controller; + setInstallingId(extension.id); + setError(null); + try { + const themes = await importOpenVsxThemeExtension(extension, controller.signal); + if (controller.signal.aborted) return; + const existingIds = new Set(getCustomThemes().map((theme) => theme.id)); + const duplicates = themes.filter((theme) => existingIds.has(theme.id)); + if (duplicates.length > 0) { + throw new Error(`${duplicates.map((theme) => theme.label).join(", ")} is already added.`); + } + + const installed: ThemeDefinition[] = []; + try { + for (const theme of themes) installed.push(installCustomTheme(theme)); + } catch (cause) { + for (const theme of installed) { + try { + removeCustomTheme(theme.id); + } catch { + // Best effort rollback. The original storage failure is clearer. + } + } + throw cause; + } + onInstalled(installed); + } catch (cause) { + if (!controller.signal.aborted) { + setError(cause instanceof Error ? cause.message : "That theme could not be added."); + } + } finally { + if (requestRef.current === controller) { + requestRef.current = null; + setInstallingId(null); + } + } + }, + [onInstalled], + ); + + return ( +
+
+

+ Search community themes +

+

+ Find open-source themes from Open VSX. +

+
+
+ + setQuery(event.currentTarget.value)} + placeholder="try dracula, nord, catppuccin..." + size="lg" + type="search" + value={query} + /> + + + + {error ? ( +
+ {error} +
+ ) : null} + + {results === null && !isSearching ? ( +
+ Popular + {SUGGESTED_SEARCHES.map((suggestion) => ( + + ))} +
+ ) : null} + + {isSearching ? ( +
+ Finding themes... +
+ ) : null} + + {results ? ( + results.length === 0 ? ( +
+

No supported open-source themes found

+

Try a broader search.

+
+ ) : ( +
+ {results.map((extension) => { + const isInstalling = installingId === extension.id; + return ( +
+
+
+ +
+
+

{extension.name}

+

+ {extension.publisher} · {DOWNLOAD_FORMAT.format(extension.downloadCount)}{" "} + downloads +

+
+
+

+ {extension.description || "A community color theme for your editor."} +

+
+ + {extension.license} + + +
+
+ ); + })} +
+ ) + ) : null} + +
+ Licensed themes only, with package integrity checks +
+
+ ); +} diff --git a/apps/web/src/components/settings/ThemeSettings.tsx b/apps/web/src/components/settings/ThemeSettings.tsx index b8cfee9eda..2a9a4989b2 100644 --- a/apps/web/src/components/settings/ThemeSettings.tsx +++ b/apps/web/src/components/settings/ThemeSettings.tsx @@ -3,7 +3,6 @@ import { DownloadIcon, PenLineIcon, PlusIcon, - SearchIcon, Trash2Icon, UploadIcon, } from "lucide-react"; @@ -36,7 +35,6 @@ import { Button } from "../ui/button"; import { stackedThreadToast, toastManager } from "../ui/toast"; import { Tooltip, TooltipPopup, TooltipProvider, TooltipTrigger } from "../ui/tooltip"; import { ThemeImportDialog } from "./ThemeImportDialog"; -import { ThemeSearchDialog } from "./ThemeSearchDialog"; import { useThemeEditorStore } from "./themeEditorStore"; import { STANDARD_THEME_CARDS, @@ -252,7 +250,6 @@ export function ThemeLibrary({ setThemeHalf: (appearance: ThemeAppearance, themeId: string | null) => boolean; }) { const openThemeEditor = useThemeEditorStore((store) => store.openThemeEditor); - const [isSearchOpen, setIsSearchOpen] = useState(false); const [themeToRemove, setThemeToRemove] = useState(null); // Keep the last removal target so the dialog title stays populated while the // close animation plays after confirming. @@ -557,10 +554,6 @@ export function ThemeLibrary({

Themes

-
{renderPairGrid()} - { - toastManager.add( - stackedThreadToast({ - type: "success", - title: - installedThemes.length === 1 - ? `${installedThemes[0]!.label} added` - : `${installedThemes.length} themes added`, - description: installedThemes.map((installed) => installed.label).join(", "), - }), - ); - }} - onOpenChange={setIsSearchOpen} - open={isSearchOpen} - /> { // An updated theme that is showing (as the base or either half)