Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
fix(web): polish theme library buttons, search, and import dialog (#7580)
Utkarsh Patilf0fb83aff1be
diff --git a/apps/web/src/components/Icons.tsx b/apps/web/src/components/Icons.tsxindex 8ea38c519..cd0854e17 100644--- a/apps/web/src/components/Icons.tsx+++ b/apps/web/src/components/Icons.tsx@@ -68,23 +68,26 @@ export const JujutsuIcon: Icon = (props) => {);};-export const GitLabIcon: Icon = (props) => (+export const GitLabIcon = ({+ monochrome = false,+ ...props+}: SVGProps<SVGSVGElement> & { readonly monochrome?: boolean }) => (<svg {...props} viewBox="0 0 32 32" fill="none"><pathd="m31.46 12.78-.04-.12-4.35-11.35A1.14 1.14 0 0 0 25.94.6c-.24 0-.47.1-.66.24-.19.15-.33.36-.39.6l-2.94 9h-11.9l-2.94-9A1.14 1.14 0 0 0 6.07.58a1.15 1.15 0 0 0-1.14.72L.58 12.68l-.05.11a8.1 8.1 0 0 0 2.68 9.34l.02.01.04.03 6.63 4.97 3.28 2.48 2 1.52a1.35 1.35 0 0 0 1.62 0l2-1.52 3.28-2.48 6.67-5h.02a8.09 8.09 0 0 0 2.7-9.36Z"- fill="#E24329"+ fill={monochrome ? "currentColor" : "#E24329"}/><pathd="m31.46 12.78-.04-.12a14.75 14.75 0 0 0-5.86 2.64l-9.55 7.24 6.09 4.6 6.67-5h.02a8.09 8.09 0 0 0 2.67-9.36Z"- fill="#FC6D26"+ fill={monochrome ? "currentColor" : "#FC6D26"}/><pathd="m9.9 27.14 3.28 2.48 2 1.52a1.35 1.35 0 0 0 1.62 0l2-1.52 3.28-2.48-6.1-4.6-6.07 4.6Z"- fill="#FCA326"+ fill={monochrome ? "currentColor" : "#FCA326"}/><pathd="M6.44 15.3a14.71 14.71 0 0 0-5.86-2.63l-.05.12a8.1 8.1 0 0 0 2.68 9.34l.02.01.04.03 6.63 4.97 6.1-4.6-9.56-7.24Z"- fill="#FC6D26"+ fill={monochrome ? "currentColor" : "#FC6D26"}/></svg>);diff --git a/apps/web/src/components/settings/ThemeEditorPanel.tsx b/apps/web/src/components/settings/ThemeEditorPanel.tsxindex 58070db33..0bb0d1b0e 100644--- a/apps/web/src/components/settings/ThemeEditorPanel.tsx+++ b/apps/web/src/components/settings/ThemeEditorPanel.tsx@@ -1,4 +1,11 @@-import { ChevronDownIcon, ChevronUpIcon, MousePointer2Icon, PlusIcon, XIcon } from "lucide-react";+import {+ ChevronDownIcon,+ ChevronUpIcon,+ MousePointer2Icon,+ PaintbrushIcon,+ PlusIcon,+ XIcon,+} from "lucide-react";import {useCallback,useEffect,@@ -1248,7 +1255,7 @@ export function ThemeEditorPanel({</>) : (<>- <PlusIcon />+ <PaintbrushIcon />Create theme</>)}diff --git a/apps/web/src/components/settings/ThemeImportDialog.tsx b/apps/web/src/components/settings/ThemeImportDialog.tsxindex d6afe5f01..891294960 100644--- a/apps/web/src/components/settings/ThemeImportDialog.tsx+++ b/apps/web/src/components/settings/ThemeImportDialog.tsx@@ -20,14 +20,7 @@ import {} from "../../vscodeThemeImport";import { Alert } from "../ui/alert";import { Button } from "../ui/button";-import {- Dialog,- DialogFooter,- DialogHeader,- DialogPanel,- DialogPopup,- DialogTitle,-} from "../ui/dialog";+import { Dialog, DialogHeader, DialogPanel, DialogPopup, DialogTitle } from "../ui/dialog";import { ThemeSearchSection } from "./ThemeSearchSection";/**@@ -131,8 +124,8 @@ function ThemeJsonEditor({<textareaaria-label="Theme JSON"className={cn(- "relative z-10 block min-h-72 w-full resize-y overflow-auto bg-transparent p-3 font-mono text-[12px] leading-5 caret-foreground outline-none placeholder:text-muted-foreground selection:bg-accent/30",- isPlainText ? "text-foreground" : "text-transparent selection:text-transparent",+ "relative z-10 block min-h-44 w-full resize-y overflow-auto bg-transparent p-3 font-mono text-[12px] leading-5 caret-foreground outline-none placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground",+ isPlainText ? "text-foreground" : "text-transparent",)}id={id}onChange={(event) => onChange(event.currentTarget.value)}@@ -513,6 +506,9 @@ export function ThemeImportDialog({<Button size="sm" variant="ghost" onClick={() => setConflicts(null)}>Back</Button>+ <Button size="sm" variant="ghost" onClick={() => onOpenChange(false)}>+ Cancel+ </Button></div></div>);@@ -536,6 +532,19 @@ export function ThemeImportDialog({{fileInput}</div>{editorSection()}+ {/* The actions live with the import section, not in a DialogFooter,+ because Add theme only applies to the file in this section. Pinning+ them at the modal bottom would read as a modal-scoped action when+ the dialog also has the search and conflict views. */}+ <div className="flex flex-col-reverse gap-2 sm:flex-row sm:justify-end">+ <Button variant="ghost" onClick={() => onOpenChange(false)}>+ Cancel+ </Button>+ <Button disabled={!json.trim() || isReading} onClick={handleSubmit}>+ <PlusIcon />+ Add theme+ </Button>+ </div></div>);})()}@@ -546,15 +555,6 @@ export function ThemeImportDialog({</Alert>) : null}</DialogPanel>- <DialogFooter>- <Button variant="ghost" onClick={() => onOpenChange(false)}>- Cancel- </Button>- <Button disabled={!json.trim() || isReading} onClick={handleSubmit}>- <PlusIcon />- Add theme- </Button>- </DialogFooter></DialogPopup></Dialog>);diff --git a/apps/web/src/components/settings/ThemeSearchSection.tsx b/apps/web/src/components/settings/ThemeSearchSection.tsxindex ed04b1075..14919e09b 100644--- a/apps/web/src/components/settings/ThemeSearchSection.tsx+++ b/apps/web/src/components/settings/ThemeSearchSection.tsx@@ -1,12 +1,10 @@import {ExternalLinkIcon,+ PackagePlusIcon,PaletteIcon,- PlusIcon,RefreshCwIcon,SearchIcon,- ShieldCheckIcon,} from "lucide-react";-import type { FormEvent } from "react";import { useCallback, useEffect, useRef, useState } from "react";import {importOpenVsxThemeExtension,@@ -14,12 +12,14 @@ import {type OpenVsxThemeExtension,type OpenVsxThemeSort,} from "../../openVsxThemes";+import { useDebouncedValue } from "../../state/queries";import {getCustomThemes,getStoredCustomThemeCollection,replaceCustomThemeCollection,type ThemeDefinition,} from "../../themePalette";+import { GitHubIcon, GitLabIcon } from "../Icons";import {AlertDialog,AlertDialogClose,@@ -45,6 +45,20 @@ const SORT_OPTIONS: ReadonlyArray<{ value: OpenVsxThemeSort; label: string }> ={ value: "timestamp", label: "Newest" },{ value: "relevance", label: "Most relevant" },];+const SEARCH_DEBOUNCE_MS = 350;++function SourceLinkIcon({ url }: { url: string }) {+ try {+ const host = new URL(url).hostname.toLowerCase();+ if (host === "github.com" || host.endsWith(".github.com"))+ return <GitHubIcon className="size-3.5" />;+ if (host === "gitlab.com" || host.endsWith(".gitlab.com"))+ return <GitLabIcon className="size-3.5" monochrome />;+ } catch {+ // Fall through to the generic external-link icon.+ }+ return <ExternalLinkIcon className="size-3.5" />;+}function ThemeExtensionIcon({ extension }: { extension: OpenVsxThemeExtension }) {const [failed, setFailed] = useState(false);@@ -82,11 +96,21 @@ export function ThemeSearchSection({const [installingId, setInstallingId] = useState<string | null>(null);const [pendingUpdate, setPendingUpdate] = useState<OpenVsxThemeExtension | null>(null);const requestRef = useRef<AbortController | null>(null);+ // The (query, sort) pair the last search actually ran, so an install+ // finishing can tell a same-key rerun (which must not wipe an install+ // error) from a query that changed mid-install (which must be searched).+ const lastSearchKeyRef = useRef<string | null>(null);+ // The (query, sort) pair from the previous effect run, so a search error+ // that belongs to an older key can be cleared when the user returns to+ // already-shown results without clearing a fresh install error.+ const prevSearchKeyRef = useRef<string | null>(null);useEffect(() => {requestRef.current?.abort();requestRef.current = null;if (open) {+ lastSearchKeyRef.current = null;+ prevSearchKeyRef.current = null;setQuery("");setSortBy("downloadCount");setResults(null);@@ -108,18 +132,21 @@ export function ThemeSearchSection({requestRef.current?.abort();const controller = new AbortController();requestRef.current = controller;- setQuery(trimmed);- setIsSearching(true);setError(null);- setResults(null);+ setIsSearching(true);try {const nextResults = await searchOpenVsxThemes(trimmed, {signal: controller.signal,sortBy: nextSort,});- if (!controller.signal.aborted) setResults(nextResults);+ if (!controller.signal.aborted) {+ setResults(nextResults);+ lastSearchKeyRef.current = `${trimmed}\u0000${nextSort}`;+ }} catch (cause) {if (!controller.signal.aborted) {+ setResults(null);+ lastSearchKeyRef.current = null;setError(cause instanceof Error ? cause.message : "Open VSX search failed.");}}@@ -131,25 +158,66 @@ export function ThemeSearchSection({[sortBy],);- const handleSearch = useCallback(- (event: FormEvent<HTMLFormElement>) => {- event.preventDefault();- void runSearch(query);- },- [query, runSearch],- );+ const debouncedQuery = useDebouncedValue(query.trim(), SEARCH_DEBOUNCE_MS);- const handleSortChange = useCallback(- (value: OpenVsxThemeSort | null) => {- const nextSort = SORT_OPTIONS.find((option) => option.value === value)?.value;- if (!nextSort) return;- setSortBy(nextSort);- if ((results !== null || isSearching) && query.trim()) {- void runSearch(query, nextSort);- }- },- [isSearching, query, results, runSearch],- );+ useEffect(() => {+ if (query.trim() || installingId !== null) return;+ requestRef.current?.abort();+ requestRef.current = null;+ lastSearchKeyRef.current = null;+ setResults(null);+ setError(null);+ setIsSearching(false);+ }, [query, installingId]);++ useEffect(() => {+ if (!open) return;+ const searchKey = `${debouncedQuery}\u0000${sortBy}`;+ const keyChanged = prevSearchKeyRef.current !== searchKey;+ prevSearchKeyRef.current = searchKey;+ if (installingId !== null) return;+ if (!debouncedQuery) {+ lastSearchKeyRef.current = null;+ requestRef.current?.abort();+ requestRef.current = null;+ setResults(null);+ setError(null);+ setIsSearching(false);+ return;+ }+ if (debouncedQuery !== query.trim()) {+ // The debounced value still trails the input (dialog reopened with the+ // box reset, or the user is mid-keystroke). Searching it would hit Open+ // VSX for a query that is no longer visible; wait for the debounce to+ // catch up to the current input instead.+ return;+ }+ if (lastSearchKeyRef.current === searchKey) {+ // The results already match this query. A request for a newer key may+ // still be in flight (typed and then undone); abort it so it cannot+ // overwrite the results. Only a genuine key change makes a stale search+ // error irrelevant, so an install error on an unchanged query survives.+ requestRef.current?.abort();+ requestRef.current = null;+ setIsSearching(false);+ if (keyChanged) setError(null);+ return;+ }+ void runSearch(debouncedQuery);+ // `installingId` and `sortBy` are deliberately not dependencies: the+ // guards above read the current values from the fresh render closure. An+ // install finishing reruns the search only when the query or sort changed+ // while it was in flight (checked via lastSearchKeyRef, recorded only+ // once a search succeeds), so the install error the user needs to see is+ // preserved across that rerun.+ // eslint-disable-next-line react-hooks/exhaustive-deps+ }, [open, query, debouncedQuery, installingId, runSearch]);++ const handleSortChange = useCallback((value: OpenVsxThemeSort | null) => {+ const nextSort = SORT_OPTIONS.find((option) => option.value === value)?.value;+ if (!nextSort) return;+ setSortBy(nextSort);+ }, []);const handleInstall = useCallback(async (extension: OpenVsxThemeExtension, allowUpdate: boolean) => {@@ -170,6 +238,7 @@ export function ThemeSearchSection({requestRef.current?.abort();const controller = new AbortController();requestRef.current = controller;+ setIsSearching(false);setInstallingId(extension.id);try {const themes = await importOpenVsxThemeExtension(extension, controller.signal);@@ -202,42 +271,43 @@ export function ThemeSearchSection({Find open-source themes from Open VSX.</p></div>- <form className="flex gap-2" onSubmit={handleSearch}>- <InputGroup>- <InputGroupAddon>- <SearchIcon />- </InputGroupAddon>- <InputGroupInput- aria-label="Search Open VSX themes"- autoFocus- onChange={(event) => setQuery(event.currentTarget.value)}- placeholder="try dracula, nord, catppuccin..."- size="lg"- type="search"- value={query}- />- </InputGroup>- <Button- disabled={!query.trim() || isSearching || installingId !== null}+ <InputGroup>+ <InputGroupAddon>+ {isSearching ? <Spinner aria-hidden /> : <SearchIcon aria-hidden />}+ </InputGroupAddon>+ <InputGroupInput+ aria-label="Search Open VSX themes"+ autoFocus+ onChange={(event) => setQuery(event.currentTarget.value)}+ onKeyDown={(event) => {+ if (event.nativeEvent.isComposing || event.keyCode === 229) return;+ if (event.key === "Enter" && !isSearching && installingId === null)+ void runSearch(query.trim());+ }}+ placeholder="Search themes..."size="lg"- type="submit"- variant="outline"- >- {isSearching ? <Spinner /> : <SearchIcon />}- Search- </Button>- </form>+ type="search"+ value={query}+ />+ </InputGroup>- {!isSearching ? (+ {!isSearching || results !== null ? (<div className="flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between"><div className="flex min-w-0 flex-wrap items-center gap-1.5"><p className="text-muted-foreground text-xs">Popular</p>{SUGGESTED_SEARCHES.map((suggestion) => (<Buttonkey={suggestion}+ disabled={installingId !== null}size="xs"variant="ghost"- onClick={() => void runSearch(suggestion)}+ onClick={() => {+ if (query.trim() === suggestion) {+ void runSearch(suggestion);+ } else {+ setQuery(suggestion);+ }+ }}>{suggestion}</Button>@@ -271,7 +341,7 @@ export function ThemeSearchSection({<div className="sr-only" role="status">{isSearching- ? "Finding themes..."+ ? "Searching themes...": results? `${results.length} supported ${results.length === 1 ? "theme" : "themes"} found.`: ""}@@ -286,9 +356,9 @@ export function ThemeSearchSection({</div>) : null}- {isSearching ? (+ {isSearching && results === null ? (<div className="flex min-h-20 items-center justify-center gap-2 text-muted-foreground text-sm">- <Spinner /> Finding themes...+ <Spinner /> Searching themes...</div>) : null}@@ -305,8 +375,8 @@ export function ThemeSearchSection({const isInstalled = getCustomThemes().some((theme) => theme.collection?.id === extension.collectionId,);- const action = isInstalled ? "Update" : "Add";- const progressAction = isInstalled ? "Updating" : "Adding";+ const action = isInstalled ? "Update" : "Install";+ const progressAction = isInstalled ? "Updating" : "Installing";return (<articleclassName="group flex min-w-0 flex-col gap-3 rounded-xl border border-border/70 bg-card/60 p-3 transition-colors hover:bg-accent/20"@@ -327,19 +397,15 @@ export function ThemeSearchSection({</p><div className="mt-auto flex items-center justify-between gap-2"><div className="flex min-w-0 items-center gap-2">- <span className="inline-flex items-center gap-1 text-muted-foreground text-[11px]">- <ShieldCheckIcon className="size-3" /> {extension.license}- </span>{extension.sourceUrl ? (- <a+ <Buttonaria-label={`View source for ${extension.name}`}- className="inline-flex items-center gap-1 text-muted-foreground text-[11px] hover:text-foreground"- href={extension.sourceUrl}- rel="noreferrer"- target="_blank"+ render={<a href={extension.sourceUrl} rel="noreferrer" target="_blank" />}+ size="icon-micro"+ variant="ghost-muted">- Source <ExternalLinkIcon className="size-3" />- </a>+ <SourceLinkIcon url={extension.sourceUrl} />+ </Button>) : null}</div><Button@@ -349,7 +415,13 @@ export function ThemeSearchSection({variant="outline"onClick={() => void handleInstall(extension, false)}>- {isInstalling ? <Spinner /> : isInstalled ? <RefreshCwIcon /> : <PlusIcon />}+ {isInstalling ? (+ <Spinner />+ ) : isInstalled ? (+ <RefreshCwIcon />+ ) : (+ <PackagePlusIcon />+ )}{isInstalling ? `${progressAction}...` : action}</Button></div>diff --git a/apps/web/src/components/settings/ThemeSettings.tsx b/apps/web/src/components/settings/ThemeSettings.tsxindex 7e4b80d19..929e00d6c 100644--- a/apps/web/src/components/settings/ThemeSettings.tsx+++ b/apps/web/src/components/settings/ThemeSettings.tsx@@ -1,8 +1,8 @@import {CheckIcon,CopyIcon,- DownloadIcon,MoonIcon,+ PaintbrushIcon,PenLineIcon,PlusIcon,SunIcon,@@ -768,7 +768,7 @@ export function ThemeLibrary({<TooltipProvider><divclassName="mx-auto grid w-full max-w-[56rem] gap-2 px-3 sm:px-4"- style={{ gridTemplateColumns: "repeat(auto-fit, minmax(min(100%, 17rem), 1fr))" }}+ style={{ gridTemplateColumns: "repeat(auto-fit, minmax(min(100%, 16rem), 1fr))" }}>{STANDARD_THEME_CARDS.map((standardTheme) => (<ThemeLibraryCard@@ -870,12 +870,12 @@ export function ThemeLibrary({})}>- <PlusIcon />+ <PaintbrushIcon />Create theme</Button><Button size="xs" variant="outline" onClick={() => onImportOpenChange(true)}>- <DownloadIcon />- Import theme+ <PlusIcon />+ Add theme</Button></div></div>