Skip to content

Open source alternative to Semrush and Ahrefs

Port the saved keywords page to shadcn, with a tag combobox and a Manage tags dialog (EVE-312) (#753)

Carter Smith07a3ddab98a3
diff --git a/src/client/components/PageHeader.tsx b/src/client/components/PageHeader.tsx
index c39d5c16..17fe2926 100644
--- a/src/client/components/PageHeader.tsx
+++ b/src/client/components/PageHeader.tsx
@@ -16,7 +16,7 @@ export function PageHeader({
}) {
return (
<div className="flex flex-wrap items-start justify-between gap-3">
- <div className="min-w-0 flex-1 space-y-1">
+ <div className="min-w-0 flex-1 basis-64 space-y-1">
<h1 className="text-2xl font-semibold tracking-tight">{title}</h1>
{description ? (
<div className="text-sm text-muted-foreground">{description}</div>
diff --git a/src/client/components/ui/combobox.tsx b/src/client/components/ui/combobox.tsx
index 2ba35098..bec5bd76 100644
--- a/src/client/components/ui/combobox.tsx
+++ b/src/client/components/ui/combobox.tsx
@@ -260,6 +260,7 @@ function ComboboxChip({
render={<Button variant="ghost" size="icon-xs" />}
className="-ml-1 opacity-50 hover:opacity-100"
data-slot="combobox-chip-remove"
+ aria-label="Remove"
>
<XIcon className="pointer-events-none" />
</ComboboxPrimitive.ChipRemove>
diff --git a/src/client/features/saved-keywords/ManageTagRow.tsx b/src/client/features/saved-keywords/ManageTagRow.tsx
index 81000afd..cc5785e2 100644
--- a/src/client/features/saved-keywords/ManageTagRow.tsx
+++ b/src/client/features/saved-keywords/ManageTagRow.tsx
@@ -1,5 +1,8 @@
-import { Pencil, Trash2 } from "lucide-react";
-import { useState } from "react";
+import { Trash2 } from "lucide-react";
+import { useId, useState } from "react";
+import { Button } from "@/client/components/ui/button";
+import { Input } from "@/client/components/ui/input";
+import { Label } from "@/client/components/ui/label";
import {
resolveTagColor,
TAG_COLOR_KEYS,
@@ -21,6 +24,7 @@ export function ManageTagRow({
onDelete: () => void;
onCancel: () => void;
}) {
+ const nameId = useId();
const [name, setName] = useState(tag.name);
const currentColor = resolveTagColor(tag);
const [color, setColor] = useState<TagColorKey>(currentColor);
@@ -29,34 +33,28 @@ export function ManageTagRow({
const canSave = (nameChanged || colorChanged) && !isBusy;
return (
- <div className="space-y-2 border-y border-base-300 bg-base-200/40 px-3 py-2.5">
- <div className="space-y-1">
- <label className="text-[11px] font-semibold uppercase tracking-wide text-base-content/55">
- Rename
- </label>
- <div className="flex items-center gap-1.5">
- <Pencil className="size-3 opacity-50" />
- <input
- value={name}
- onChange={(event) => setName(event.target.value)}
- className="min-w-0 flex-1 rounded border border-base-300 bg-base-100 px-2 py-1 text-sm outline-none focus:border-primary"
- />
- </div>
+ <div className="space-y-3 border-y border-border bg-muted/40 px-4 py-3">
+ <div className="space-y-1.5">
+ <Label htmlFor={nameId}>Name</Label>
+ <Input
+ id={nameId}
+ value={name}
+ onChange={(event) => setName(event.target.value)}
+ />
</div>
- <div className="space-y-1">
- <label className="text-[11px] font-semibold uppercase tracking-wide text-base-content/55">
- Color
- </label>
+ <div className="space-y-1.5">
+ <p className="text-sm leading-none font-medium">Color</p>
<div className="flex flex-wrap items-center gap-1.5">
{TAG_COLOR_KEYS.map((key) => (
<button
key={key}
type="button"
aria-label={key}
- className={`size-5 rounded-full transition ${tagSwatchClass(key)} ${
+ aria-pressed={color === key}
+ className={`size-5 rounded-full transition outline-none focus-visible:ring-3 focus-visible:ring-ring/50 ${tagSwatchClass(key)} ${
color === key
- ? "ring-2 ring-offset-2 ring-offset-base-200 ring-base-content/40"
+ ? "ring-2 ring-foreground/40 ring-offset-2 ring-offset-background"
: "hover:scale-110"
}`}
onClick={() => setColor(key)}
@@ -65,27 +63,23 @@ export function ManageTagRow({
</div>
</div>
- <div className="flex items-center justify-between pt-1">
- <button
- type="button"
- className="inline-flex items-center gap-1 text-xs text-error hover:underline disabled:opacity-50"
+ <div className="flex items-center justify-between">
+ <Button
+ variant="ghost"
+ size="xs"
+ className="text-destructive hover:bg-destructive/10 hover:text-destructive"
onClick={onDelete}
disabled={isBusy}
>
- <Trash2 className="size-3" />
+ <Trash2 data-icon="inline-start" />
Delete
- </button>
+ </Button>
<div className="flex items-center gap-1.5">
- <button
- type="button"
- className="rounded px-2 py-1 text-xs text-base-content/70 hover:bg-base-300"
- onClick={onCancel}
- >
+ <Button variant="ghost" size="xs" onClick={onCancel}>
Cancel
- </button>
- <button
- type="button"
- className="rounded bg-primary px-2 py-1 text-xs font-medium text-primary-content disabled:opacity-50"
+ </Button>
+ <Button
+ size="xs"
disabled={!canSave}
onClick={() =>
onSave({
@@ -95,7 +89,7 @@ export function ManageTagRow({
}
>
Save
- </button>
+ </Button>
</div>
</div>
</div>
diff --git a/src/client/features/saved-keywords/SavedKeywordsBulkActionBar.tsx b/src/client/features/saved-keywords/SavedKeywordsBulkActionBar.tsx
index 30c97c41..3fdd8c12 100644
--- a/src/client/features/saved-keywords/SavedKeywordsBulkActionBar.tsx
+++ b/src/client/features/saved-keywords/SavedKeywordsBulkActionBar.tsx
@@ -62,7 +62,7 @@ export function SavedKeywordsBulkActionBar({
/>
</div>
- <div className="flex items-center border-l border-base-content/10 px-1.5">
+ <div className="flex items-center border-l border-border px-1.5">
<TableBulkActionButton
icon={<Trash2 className="size-3.5" />}
onClick={onDelete}
diff --git a/src/client/features/saved-keywords/SavedKeywordsBulkTagsModal.tsx b/src/client/features/saved-keywords/SavedKeywordsBulkTagsModal.tsx
index 1bd94d2d..27adaa16 100644
--- a/src/client/features/saved-keywords/SavedKeywordsBulkTagsModal.tsx
+++ b/src/client/features/saved-keywords/SavedKeywordsBulkTagsModal.tsx
@@ -1,9 +1,27 @@
-import { Check, Loader2, Plus, Search, X } from "lucide-react";
+import { Check, Plus, Search, X } from "lucide-react";
import { useMemo, useRef, useState } from "react";
-import { Modal } from "@/client/components/Modal";
+import { Badge } from "@/client/components/ui/badge";
+import { Button } from "@/client/components/ui/button";
+import { Checkbox } from "@/client/components/ui/checkbox";
+import {
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+} from "@/client/components/ui/dialog";
+import {
+ InputGroup,
+ InputGroupAddon,
+ InputGroupInput,
+} from "@/client/components/ui/input-group";
+import {
+ ToggleGroup,
+ ToggleGroupItem,
+} from "@/client/components/ui/toggle-group";
import type { SavedKeywordTag, SavedKeywordTagSummary } from "@/types/keywords";
-import { TagCheckboxRow } from "./TagCheckboxRow";
-import { TagChip } from "./TagChip";
+import { TagChip, TagDot } from "./TagChip";
type Mode = "add" | "remove";
@@ -93,38 +111,44 @@ export function SavedKeywordsBulkTagsModal({
};
return (
- <Modal maxWidth="max-w-lg" onClose={onClose} labelledBy="bulk-tags-title">
- <div className="space-y-4">
- <div>
- <h3 id="bulk-tags-title" className="text-lg font-semibold">
- Update tags
- </h3>
- <p className="text-sm text-base-content/65">
+ <Dialog
+ open
+ onOpenChange={(open) => {
+ if (!open) onClose();
+ }}
+ >
+ <DialogContent showCloseButton={false} className="sm:max-w-lg">
+ <DialogHeader>
+ <DialogTitle>Update tags</DialogTitle>
+ <DialogDescription>
Apply or remove tags across {selectedCount} selected keyword
{selectedCount !== 1 ? "s" : ""}.
- </p>
- </div>
+ </DialogDescription>
+ </DialogHeader>
- <div className="inline-flex rounded-md border border-base-300 bg-base-200/40 p-0.5 text-sm">
- <SegmentButton
- active={mode === "add"}
- onClick={() => setMode("add")}
- label="Add tags"
- count={addNames.length}
- />
- <SegmentButton
- active={mode === "remove"}
- onClick={() => setMode("remove")}
+ <ToggleGroup
+ size="sm"
+ spacing={0.5}
+ value={[mode]}
+ onValueChange={(next) => {
+ // A press on the active item empties the group. Keep one mode on.
+ if (next[0] === "add" || next[0] === "remove") setMode(next[0]);
+ }}
+ className="rounded-lg bg-muted p-0.5 ring-1 ring-border ring-inset"
+ >
+ <SegmentItem value="add" label="Add tags" count={addNames.length} />
+ <SegmentItem
+ value="remove"
label="Remove tags"
count={removeIds.length}
disabled={selectedRowTags.length === 0}
/>
- </div>
+ </ToggleGroup>
{mode === "add" ? (
<div className="space-y-2">
{addNames.length > 0 ? (
- <div className="flex flex-wrap items-center gap-1.5 rounded-md border border-base-300 bg-base-200/40 px-2 py-2">
+ <div className="flex flex-wrap items-center gap-1.5 rounded-lg border border-border bg-muted/40 p-2">
{addNames.map((name) => {
const existing = availableByNormalized.get(
name.toLocaleLowerCase(),
@@ -155,10 +179,13 @@ export function SavedKeywordsBulkTagsModal({
</div>
) : null}
- <label className="flex items-center gap-2 rounded-md border border-base-300 bg-base-100 px-2 py-2">
- <Search className="size-3.5 opacity-50" />
- <input
+ <InputGroup>
+ <InputGroupAddon>
+ <Search />
+ </InputGroupAddon>
+ <InputGroupInput
ref={inputRef}
+ aria-label="Search or create a tag"
value={query}
onChange={(event) => setQuery(event.target.value)}
onKeyDown={(event) => {
@@ -168,47 +195,53 @@ export function SavedKeywordsBulkTagsModal({
}
}}
placeholder="Search or create…"
- className="min-w-0 flex-1 bg-transparent text-sm outline-none placeholder:text-base-content/40"
/>
- </label>
+ </InputGroup>
- <div className="max-h-56 overflow-y-auto rounded-md border border-base-300">
+ <div className="max-h-56 overflow-y-auto rounded-lg border border-border py-1">
{showCreate ? (
- <button
- type="button"
+ <Button
+ variant="ghost"
+ className="w-full justify-start rounded-none font-normal"
onClick={handleCreate}
- className="flex w-full items-center gap-2 px-3 py-2 text-left text-sm hover:bg-base-200"
>
- <Plus className="size-3.5 text-primary" />
- <span className="text-base-content/70">Create</span>
+ <Plus data-icon="inline-start" className="text-primary" />
+ <span className="text-muted-foreground">Create</span>
<span className="font-medium">
&ldquo;{trimmedQuery}&rdquo;
</span>
- </button>
+ </Button>
) : null}
{filteredAvailable.length === 0 && !showCreate ? (
- <div className="px-3 py-6 text-center text-xs text-base-content/55">
+ <p className="px-3 py-6 text-center text-xs text-muted-foreground">
{availableTags.length === 0
? "No tags yet. Type a name above to create one."
: "No tags match that search."}
- </div>
+ </p>
) : null}
{filteredAvailable.map((tag) => (
- <TagCheckboxRow
+ <label
key={tag.id}
- tag={tag}
- checked={normalizedAddSet.has(tag.normalizedName)}
- onToggle={() => handleToggleAdd(tag)}
- className="w-full px-3 py-1.5 hover:bg-base-200"
- />
+ className="flex cursor-pointer items-center gap-2 px-3 py-1.5 text-sm hover:bg-muted"
+ >
+ <Checkbox
+ checked={normalizedAddSet.has(tag.normalizedName)}
+ onCheckedChange={() => handleToggleAdd(tag)}
+ />
+ <TagDot tag={tag} />
+ <span className="min-w-0 flex-1 truncate">{tag.name}</span>
+ <span className="text-xs text-muted-foreground tabular-nums">
+ {tag.keywordCount}
+ </span>
+ </label>
))}
</div>
</div>
) : (
<div className="space-y-2">
- <div className="flex flex-wrap gap-1.5 rounded-md border border-base-300 p-3">
+ <div className="flex flex-wrap gap-1.5 rounded-lg border border-border p-3">
{selectedRowTags.map((tag) => {
const checked = removeIds.includes(tag.id);
return (
@@ -225,7 +258,7 @@ export function SavedKeywordsBulkTagsModal({
})}
</div>
{removeIds.length > 0 ? (
- <p className="text-xs text-base-content/55">
+ <p className="text-xs text-muted-foreground">
{removeIds.length} tag{removeIds.length !== 1 ? "s" : ""} will
be detached from the selected keywords.
</p>
@@ -233,17 +266,12 @@ export function SavedKeywordsBulkTagsModal({
</div>
)}
- <div className="flex items-center justify-end gap-2 pt-2">
- <button
- type="button"
- className="rounded-md px-3 py-1.5 text-sm text-base-content/70 hover:bg-base-200"
- onClick={onClose}
- >
+ <DialogFooter>
+ <Button variant="outline" onClick={onClose}>
Cancel
- </button>
- <button
- type="button"
- className="inline-flex items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-sm font-medium text-primary-content disabled:opacity-50"
+ </Button>
+ <Button
+ pending={isPending}
disabled={!canApply}
onClick={() =>
onApply({
@@ -252,45 +280,33 @@ export function SavedKeywordsBulkTagsModal({
})
}
>
- {isPending ? <Loader2 className="size-3.5 animate-spin" /> : null}
Apply
- </button>
- </div>
- </div>
- </Modal>
+ </Button>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
);
}
-function SegmentButton({
- active,
- onClick,
+function SegmentItem({
+ value,
label,
count,
disabled,
}: {
- active: boolean;
- onClick: () => void;
+ value: Mode;
label: string;
count: number;
disabled?: boolean;
}) {
return (
- <button
- type="button"
- onClick={onClick}
+ <ToggleGroupItem
+ value={value}
disabled={disabled}
- className={`inline-flex items-center gap-1.5 rounded px-3 py-1 text-sm transition ${
- active
- ? "bg-base-100 font-medium shadow-sm"
- : "text-base-content/65 hover:text-base-content"
- } disabled:opacity-40`}
+ className="h-6 text-muted-foreground aria-pressed:bg-background aria-pressed:text-foreground aria-pressed:shadow-sm"
>
{label}
- {count > 0 ? (
- <span className="inline-flex h-4 min-w-4 items-center justify-center rounded-full bg-primary px-1 text-[10px] font-semibold text-primary-content">
- {count}
- </span>
- ) : null}
- </button>
+ {count > 0 ? <Badge size="sm">{count}</Badge> : null}
+ </ToggleGroupItem>
);
}
diff --git a/src/client/features/saved-keywords/SavedKeywordsFilters.tsx b/src/client/features/saved-keywords/SavedKeywordsFilters.tsx
index efffe1ba..18f0f85d 100644
--- a/src/client/features/saved-keywords/SavedKeywordsFilters.tsx
+++ b/src/client/features/saved-keywords/SavedKeywordsFilters.tsx
@@ -45,14 +45,7 @@ export function SavedKeywordsFilters({
availableTags={availableTags}
selectedTagIds={selectedTagIds}
busyTagIds={busyTagIds}
- onToggleTagFilter={(tagId) =>
- onSelectedTagIdsChange(
- selectedTagIds.includes(tagId)
- ? selectedTagIds.filter((id) => id !== tagId)
- : [...selectedTagIds, tagId],
- )
- }
- onClearSelection={() => onSelectedTagIdsChange([])}
+ onSelectedTagIdsChange={onSelectedTagIdsChange}
onUpdateTag={onUpdateTag}
onDeleteTag={onDeleteTag}
/>
diff --git a/src/client/features/saved-keywords/SavedKeywordsHeader.tsx b/src/client/features/saved-keywords/SavedKeywordsHeader.tsx
index 14de7b3e..08668685 100644
--- a/src/client/features/saved-keywords/SavedKeywordsHeader.tsx
+++ b/src/client/features/saved-keywords/SavedKeywordsHeader.tsx
@@ -1,14 +1,9 @@
import { useState } from "react";
-import { ChevronDown, RefreshCw } from "lucide-react";
+import { RefreshCw } from "lucide-react";
import { ConfirmDialog } from "@/client/components/ConfirmDialog";
import { ExportMenu } from "@/client/components/ExportMenu";
+import { PageHeader } from "@/client/components/PageHeader";
import { Button } from "@/client/components/ui/button";
-import {
- DropdownMenu,
- DropdownMenuContent,
- DropdownMenuItem,
- DropdownMenuTrigger,
-} from "@/client/components/ui/dropdown-menu";
export function SavedKeywordsHeader({
totalCount,
@@ -29,55 +24,37 @@ export function SavedKeywordsHeader({
const disabled = totalCount === 0 || exporting != null;
return (
- <div className="flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between">
- <div>
- <h1 className="text-2xl font-semibold">Saved Keywords</h1>
- <p className="text-sm text-base-content/70">
- Save keyword ideas from research, organize them with tags, and revisit
- when you&apos;re ready to act.
- </p>
- </div>
-
- <div className="flex items-center gap-2">
- <DropdownMenu>
- <DropdownMenuTrigger
- render={
- <Button
- variant="ghost"
- size="sm"
- disabled={disabled || metricsRefreshing}
+ <>
+ <PageHeader
+ title="Saved Keywords"
+ description="Save keyword ideas from research, organize them with tags, and revisit when you're ready to act."
+ actions={
+ <>
+ <Button
+ variant="ghost"
+ size="sm"
+ title="Fetch new volume, difficulty, and CPC"
+ disabled={disabled || metricsRefreshing}
+ onClick={() => setConfirmingRefresh(true)}
+ >
+ <RefreshCw
+ data-icon="inline-start"
+ className={metricsRefreshing ? "animate-spin" : ""}
/>
- }
- >
- <RefreshCw
- data-icon="inline-start"
- className={metricsRefreshing ? "animate-spin" : ""}
- />
- {metricsRefreshing ? "Updating..." : "Actions"}
- <ChevronDown data-icon="inline-end" className="opacity-60" />
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end" className="w-64">
- <DropdownMenuItem onClick={() => setConfirmingRefresh(true)}>
- <RefreshCw />
- <span className="flex flex-col">
- <span>Update keyword stats</span>
- <span className="text-xs text-muted-foreground">
- Volume, difficulty &amp; CPC
- </span>
- </span>
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenu>
+ {metricsRefreshing ? "Updating..." : "Update keyword stats"}
+ </Button>
- <ExportMenu
- actions={["sheets", "csv"]}
- busy={exporting != null}
- disabled={disabled}
- onExport={(action) =>
- action === "sheets" ? onExportSheets() : onExportCsv()
- }
- />
- </div>
+ <ExportMenu
+ actions={["sheets", "csv"]}
+ busy={exporting != null}
+ disabled={disabled}
+ onExport={(action) =>
+ action === "sheets" ? onExportSheets() : onExportCsv()
+ }
+ />
+ </>
+ }
+ />
{confirmingRefresh ? (
<ConfirmDialog
@@ -93,6 +70,6 @@ export function SavedKeywordsHeader({
in this project. Each keyword uses credits.
</ConfirmDialog>
) : null}
- </div>
+ </>
);
}
diff --git a/src/client/features/saved-keywords/SavedKeywordsModals.tsx b/src/client/features/saved-keywords/SavedKeywordsModals.tsx
index 38cd693f..958421af 100644
--- a/src/client/features/saved-keywords/SavedKeywordsModals.tsx
+++ b/src/client/features/saved-keywords/SavedKeywordsModals.tsx
@@ -1,12 +1,13 @@
-import { AlertCircle, Loader2 } from "lucide-react";
-import { Modal } from "@/client/components/Modal";
+import { AlertCircle } from "lucide-react";
+import { ConfirmDialog } from "@/client/components/ConfirmDialog";
+import { Alert, AlertDescription } from "@/client/components/ui/alert";
export function RemoveSavedKeywordsError({ message }: { message: string }) {
return (
- <div className="flex items-start gap-2 rounded-lg border border-error/30 bg-error/10 p-3 text-sm text-error">
- <AlertCircle className="mt-0.5 size-4 shrink-0" />
- <span>{message}</span>
- </div>
+ <Alert variant="destructive">
+ <AlertCircle />
+ <AlertDescription>{message}</AlertDescription>
+ </Alert>
);
}
@@ -21,34 +22,17 @@ export function DeleteSavedKeywordsModal({
onClose: () => void;
onConfirm: () => void;
}) {
+ const plural = selectedCount !== 1 ? "s" : "";
return (
- <Modal onClose={onClose} labelledBy="delete-keywords-title">
- <h3 id="delete-keywords-title" className="text-lg font-semibold">
- Delete keywords?
- </h3>
- <p className="text-sm text-base-content/70">
- This will permanently delete {selectedCount} saved keyword
- {selectedCount !== 1 ? "s" : ""}.
- </p>
- <div className="flex justify-end gap-2">
- <button
- type="button"
- className="btn btn-ghost btn-sm"
- onClick={onClose}
- >
- Cancel
- </button>
- <button
- type="button"
- className="btn btn-error btn-sm gap-1"
- onClick={onConfirm}
- disabled={isPending}
- >
- {isPending ? <Loader2 className="size-3 animate-spin" /> : null}
- Delete {selectedCount} keyword
- {selectedCount !== 1 ? "s" : ""}
- </button>
- </div>
- </Modal>
+ <ConfirmDialog
+ title="Delete keywords?"
+ confirmLabel={`Delete ${selectedCount} keyword${plural}`}
+ destructive
+ pending={isPending}
+ onClose={onClose}
+ onConfirm={onConfirm}
+ >
+ This will permanently delete {selectedCount} saved keyword{plural}.
+ </ConfirmDialog>
);
}
diff --git a/src/client/features/saved-keywords/SavedKeywordsTagFilter.tsx b/src/client/features/saved-keywords/SavedKeywordsTagFilter.tsx
index ce58a5ab..1fb0e95c 100644
--- a/src/client/features/saved-keywords/SavedKeywordsTagFilter.tsx
+++ b/src/client/features/saved-keywords/SavedKeywordsTagFilter.tsx
@@ -1,279 +1,212 @@
+import { Pencil, Settings2, Tag as TagIcon } from "lucide-react";
+import { useState } from "react";
+import { Button } from "@/client/components/ui/button";
import {
- ChevronDown,
- MoreHorizontal,
- Search,
- Tag as TagIcon,
- X,
-} from "lucide-react";
-import { useEffect, useMemo, useRef, useState } from "react";
-import type { TagColorKey } from "@/shared/tag-colors";
+ Combobox,
+ ComboboxChip,
+ ComboboxChips,
+ ComboboxChipsInput,
+ ComboboxContent,
+ ComboboxEmpty,
+ ComboboxItem,
+ ComboboxList,
+ ComboboxValue,
+ useComboboxAnchor,
+} from "@/client/components/ui/combobox";
+import {
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogHeader,
+ DialogTitle,
+} from "@/client/components/ui/dialog";
+import {
+ resolveTagColor,
+ tagChipClass,
+ type TagColorKey,
+} from "@/shared/tag-colors";
import type { SavedKeywordTagSummary } from "@/types/keywords";
import { ManageTagRow } from "./ManageTagRow";
-import { TagCheckboxRow } from "./TagCheckboxRow";
-import { TagChip } from "./TagChip";
+import { TagDot } from "./TagChip";
+
+type UpdateTagInput = {
+ tagId: string;
+ name?: string;
+ color?: TagColorKey | null;
+};
export function SavedKeywordsTagFilter({
availableTags,
selectedTagIds,
- onToggleTagFilter,
- onClearSelection,
+ busyTagIds,
+ onSelectedTagIdsChange,
onUpdateTag,
onDeleteTag,
- busyTagIds,
}: {
availableTags: SavedKeywordTagSummary[];
selectedTagIds: string[];
- onToggleTagFilter: (tagId: string) => void;
- onClearSelection: () => void;
- onUpdateTag: (input: {
- tagId: string;
- name?: string;
- color?: TagColorKey | null;
- }) => void;
- onDeleteTag: (tagId: string) => void;
busyTagIds: Set<string>;
+ onSelectedTagIdsChange: (tagIds: string[]) => void;
+ onUpdateTag: (input: UpdateTagInput) => void;
+ onDeleteTag: (tagId: string) => void;
}) {
- const [open, setOpen] = useState(false);
- const [query, setQuery] = useState("");
- const [managingTagId, setManagingTagId] = useState<string | null>(null);
- const containerRef = useRef<HTMLDivElement>(null);
-
- useEffect(() => {
- if (!open) return;
- const handleClick = (event: MouseEvent) => {
- const target = event.target;
- if (
- target instanceof Node &&
- containerRef.current &&
- containerRef.current.contains(target)
- ) {
- return;
- }
- setOpen(false);
- setManagingTagId(null);
- };
- const handleKey = (event: KeyboardEvent) => {
- if (event.key === "Escape") {
- setOpen(false);
- setManagingTagId(null);
- }
- };
- document.addEventListener("mousedown", handleClick);
- document.addEventListener("keydown", handleKey);
- return () => {
- document.removeEventListener("mousedown", handleClick);
- document.removeEventListener("keydown", handleKey);
- };
- }, [open]);
-
- const filteredTags = useMemo(() => {
- const q = query.trim().toLocaleLowerCase();
- if (!q) return availableTags;
- return availableTags.filter((tag) => tag.normalizedName.includes(q));
- }, [availableTags, query]);
-
+ const anchor = useComboboxAnchor();
+ const [managing, setManaging] = useState(false);
const selectedTags = availableTags.filter((tag) =>
selectedTagIds.includes(tag.id),
);
- const hasSelection = selectedTagIds.length > 0;
return (
- <div ref={containerRef} className="relative">
- <button
- type="button"
- className={`inline-flex h-9 items-center gap-2 rounded-md border px-3 text-sm transition ${
- hasSelection
- ? "border-primary/50 bg-primary/10 text-base-content"
- : "border-base-300 bg-base-100 hover:border-base-content/30"
- }`}
- onClick={() => setOpen((v) => !v)}
+ <div className="flex items-center gap-1">
+ <Combobox
+ multiple
+ items={availableTags}
+ value={selectedTags}
+ onValueChange={(tags) => onSelectedTagIdsChange(tags.map((t) => t.id))}
+ itemToStringLabel={(tag) => tag.name}
+ isItemEqualToValue={(a, b) => a.id === b.id}
>
- <TagIcon className="size-3.5 opacity-70" />
- <span className="font-medium">Tags</span>
- {hasSelection ? (
- <span className="inline-flex h-5 min-w-5 items-center justify-center rounded-full bg-primary px-1.5 text-[11px] font-semibold text-primary-content">
- {selectedTags.length}
- </span>
- ) : null}
- <ChevronDown className="size-3.5 opacity-60" />
- </button>
+ <ComboboxChips ref={anchor} className="w-72 max-w-full">
+ <TagIcon className="ml-1 size-3.5 shrink-0 text-muted-foreground" />
+ <ComboboxValue>
+ {(tags: SavedKeywordTagSummary[]) =>
+ tags.map((tag) => (
+ <ComboboxChip
+ key={tag.id}
+ className={tagChipClass(resolveTagColor(tag))}
+ >
+ <TagDot tag={tag} />
+ {tag.name}
+ </ComboboxChip>
+ ))
+ }
+ </ComboboxValue>
+ <ComboboxChipsInput
+ aria-label="Filter by tag"
+ placeholder={selectedTags.length > 0 ? "" : "Filter by tag…"}
+ />
+ </ComboboxChips>
+ <ComboboxContent anchor={anchor}>
+ <ComboboxEmpty className="px-3">
+ {availableTags.length === 0
+ ? "No tags yet. Add tags from a selection of keywords."
+ : "No tags match that search."}
+ </ComboboxEmpty>
+ <ComboboxList>
+ {(tag: SavedKeywordTagSummary) => (
+ <ComboboxItem key={tag.id} value={tag}>
+ <TagDot tag={tag} />
+ <span className="min-w-0 flex-1 truncate">{tag.name}</span>
+ <span className="text-xs text-muted-foreground tabular-nums">
+ {tag.keywordCount}
+ </span>
+ </ComboboxItem>
+ )}
+ </ComboboxList>
+ </ComboboxContent>
+ </Combobox>
- {hasSelection ? (
- <div className="mt-2 flex flex-wrap items-center gap-1.5">
- {selectedTags.map((tag) => (
- <TagChip
- key={tag.id}
- tag={tag}
- size="sm"
- selected
- onClick={() => onToggleTagFilter(tag.id)}
- trailing={<X className="size-3 opacity-70" />}
- title="Remove filter"
- />
- ))}
- <button
- type="button"
- className="text-xs text-base-content/60 underline-offset-2 hover:text-base-content hover:underline"
- onClick={onClearSelection}
- >
- Clear
- </button>
- </div>
- ) : null}
+ <Button
+ variant="ghost"
+ size="icon-sm"
+ aria-label="Manage tags"
+ title="Manage tags"
+ disabled={availableTags.length === 0}
+ onClick={() => setManaging(true)}
+ >
+ <Settings2 />
+ </Button>
- {open ? (
- <TagFilterPopover
- availableTags={availableTags}
- filteredTags={filteredTags}
- selectedTagIds={selectedTagIds}
- query={query}
- managingTagId={managingTagId}
+ {managing ? (
+ <TagManagerDialog
+ tags={availableTags}
busyTagIds={busyTagIds}
- onQueryChange={setQuery}
- onToggleTagFilter={onToggleTagFilter}
- onStartManaging={setManagingTagId}
- onUpdateTag={(tagId, input) => {
- onUpdateTag({ tagId, ...input });
- setManagingTagId(null);
- }}
- onDeleteTag={(tagId) => {
- onDeleteTag(tagId);
- setManagingTagId(null);
- }}
+ onUpdateTag={onUpdateTag}
+ onDeleteTag={onDeleteTag}
+ onClose={() => setManaging(false)}
/>
) : null}
</div>
);
}
-function TagFilterPopover({
- availableTags,
- filteredTags,
- selectedTagIds,
- query,
- managingTagId,
+function TagManagerDialog({
+ tags,
busyTagIds,
- onQueryChange,
- onToggleTagFilter,
- onStartManaging,
onUpdateTag,
onDeleteTag,
+ onClose,
}: {
- availableTags: SavedKeywordTagSummary[];
- filteredTags: SavedKeywordTagSummary[];
- selectedTagIds: string[];
- query: string;
- managingTagId: string | null;
+ tags: SavedKeywordTagSummary[];
busyTagIds: Set<string>;
- onQueryChange: (value: string) => void;
- onToggleTagFilter: (tagId: string) => void;
- onStartManaging: (tagId: string | null) => void;
- onUpdateTag: (
- tagId: string,
- input: { name?: string; color?: TagColorKey | null },
- ) => void;
+ onUpdateTag: (input: UpdateTagInput) => void;
onDeleteTag: (tagId: string) => void;
+ onClose: () => void;
}) {
- return (
- <div className="absolute right-0 top-full z-20 mt-2 w-80 max-w-[calc(100vw-2rem)] overflow-hidden rounded-lg border border-base-300 bg-base-100 shadow-2xl">
- <div className="border-b border-base-300 p-2">
- <label className="flex items-center gap-2 rounded-md border border-base-300 bg-base-200/50 px-2 py-1.5">
- <Search className="size-3.5 opacity-50" />
- <input
- autoFocus
- value={query}
- onChange={(event) => onQueryChange(event.target.value)}
- placeholder="Search tags…"
- className="min-w-0 flex-1 bg-transparent text-sm outline-none placeholder:text-base-content/40"
- />
- {query ? (
- <button
- type="button"
- className="text-base-content/40 hover:text-base-content"
- onClick={() => onQueryChange("")}
- >
- <X className="size-3.5" />
- </button>
- ) : null}
- </label>
- </div>
-
- <div className="max-h-72 overflow-y-auto py-1">
- {filteredTags.length === 0 ? (
- <div className="px-3 py-6 text-center text-xs text-base-content/55">
- {availableTags.length === 0
- ? "No tags yet. Add tags from a selection of keywords."
- : "No tags match that search."}
- </div>
- ) : null}
-
- {filteredTags.map((tag) => (
- <TagFilterRow
- key={tag.id}
- tag={tag}
- checked={selectedTagIds.includes(tag.id)}
- isManaging={managingTagId === tag.id}
- isBusy={busyTagIds.has(tag.id)}
- onToggle={() => onToggleTagFilter(tag.id)}
- onStartManaging={onStartManaging}
- onUpdate={(input) => onUpdateTag(tag.id, input)}
- onDelete={() => onDeleteTag(tag.id)}
- />
- ))}
- </div>
- </div>
- );
-}
+ const [editingTagId, setEditingTagId] = useState<string | null>(null);
-function TagFilterRow({
- tag,
- checked,
- isManaging,
- isBusy,
- onToggle,
- onStartManaging,
- onUpdate,
- onDelete,
-}: {
- tag: SavedKeywordTagSummary;
- checked: boolean;
- isManaging: boolean;
- isBusy: boolean;
- onToggle: () => void;
- onStartManaging: (tagId: string | null) => void;
- onUpdate: (input: { name?: string; color?: TagColorKey | null }) => void;
- onDelete: () => void;
-}) {
return (
- <div>
- <div className="group flex items-center gap-2 px-2 py-1.5 hover:bg-base-200">
- <TagCheckboxRow
- tag={tag}
- checked={checked}
- onToggle={onToggle}
- className="min-w-0 flex-1"
- />
- <button
- type="button"
- className={`rounded p-1 text-base-content/45 hover:bg-base-300 hover:text-base-content ${
- isManaging ? "bg-base-300 text-base-content" : ""
- }`}
- onClick={() => onStartManaging(isManaging ? null : tag.id)}
- aria-label={`Manage ${tag.name}`}
- >
- <MoreHorizontal className="size-3.5" />
- </button>
- </div>
+ <Dialog
+ open
+ onOpenChange={(open) => {
+ if (!open) onClose();
+ }}
+ >
+ <DialogContent className="sm:max-w-md">
+ <DialogHeader>
+ <DialogTitle>Manage tags</DialogTitle>
+ <DialogDescription>
+ Rename, recolor, or delete the tags in this project.
+ </DialogDescription>
+ </DialogHeader>
- {isManaging ? (
- <ManageTagRow
- tag={tag}
- isBusy={isBusy}
- onSave={onUpdate}
- onDelete={onDelete}
- onCancel={() => onStartManaging(null)}
- />
- ) : null}
- </div>
+ <div className="-mx-4 -mb-4 max-h-96 overflow-y-auto border-t border-border py-1">
+ {tags.length === 0 ? (
+ <p className="px-4 py-6 text-center text-sm text-muted-foreground">
+ No tags yet. Add tags from a selection of keywords.
+ </p>
+ ) : null}
+ {tags.map((tag) => {
+ const editing = editingTagId === tag.id;
+ return (
+ <div key={tag.id}>
+ <div className="flex items-center gap-2 px-4 py-1.5 text-sm">
+ <TagDot tag={tag} />
+ <span className="min-w-0 flex-1 truncate">{tag.name}</span>
+ <span className="text-xs text-muted-foreground tabular-nums">
+ {tag.keywordCount}
+ </span>
+ <Button
+ variant="ghost"
+ size="icon-xs"
+ aria-label={`Edit ${tag.name}`}
+ aria-pressed={editing}
+ className="aria-pressed:bg-muted"
+ onClick={() => setEditingTagId(editing ? null : tag.id)}
+ >
+ <Pencil />
+ </Button>
+ </div>
+ {editing ? (
+ <ManageTagRow
+ tag={tag}
+ isBusy={busyTagIds.has(tag.id)}
+ onSave={(input) => {
+ onUpdateTag({ tagId: tag.id, ...input });
+ setEditingTagId(null);
+ }}
+ onDelete={() => {
+ onDeleteTag(tag.id);
+ setEditingTagId(null);
+ }}
+ onCancel={() => setEditingTagId(null)}
+ />
+ ) : null}
+ </div>
+ );
+ })}
+ </div>
+ </DialogContent>
+ </Dialog>
);
}
diff --git a/src/client/features/saved-keywords/TagCheckboxRow.tsx b/src/client/features/saved-keywords/TagCheckboxRow.tsx
deleted file mode 100644
index e251a3e6..00000000
--- a/src/client/features/saved-keywords/TagCheckboxRow.tsx
+++ /dev/null
@@ -1,41 +0,0 @@
-import { Check } from "lucide-react";
-import { resolveTagColor, tagDotClass } from "@/shared/tag-colors";
-import type { SavedKeywordTagSummary } from "@/types/keywords";
-
-/** Checkbox, color dot, name and keyword count for one tag in a tag list. */
-export function TagCheckboxRow({
- tag,
- checked,
- onToggle,
- className,
-}: {
- tag: SavedKeywordTagSummary;
- checked: boolean;
- onToggle: () => void;
- className: string;
-}) {
- return (
- <button
- type="button"
- className={`flex items-center gap-2 text-left ${className}`}
- onClick={onToggle}
- >
- <span
- className={`flex size-4 shrink-0 items-center justify-center rounded border ${
- checked
- ? "border-primary bg-primary text-primary-content"
- : "border-base-300"
- }`}
- >
- {checked ? <Check className="size-3" /> : null}
- </span>
- <span
- className={`size-2 shrink-0 rounded-full ${tagDotClass(resolveTagColor(tag))}`}
- />
- <span className="min-w-0 flex-1 truncate text-sm">{tag.name}</span>
- <span className="shrink-0 text-[11px] tabular-nums text-base-content/45">
- {tag.keywordCount}
- </span>
- </button>
- );
-}
diff --git a/src/client/features/saved-keywords/TagChip.tsx b/src/client/features/saved-keywords/TagChip.tsx
index d1fb2d36..0eac423d 100644
--- a/src/client/features/saved-keywords/TagChip.tsx
+++ b/src/client/features/saved-keywords/TagChip.tsx
@@ -6,6 +6,18 @@ import {
} from "@/shared/tag-colors";
import type { SavedKeywordTag } from "@/types/keywords";
+export function TagDot({
+ tag,
+}: {
+ tag: Pick<SavedKeywordTag, "id" | "color">;
+}) {
+ return (
+ <span
+ className={`size-2 shrink-0 rounded-full ${tagDotClass(resolveTagColor(tag))}`}
+ />
+ );
+}
+
type Size = "xs" | "sm";
const SIZE_CLASS: Record<Size, string> = {
@@ -33,7 +45,7 @@ export function TagChip({
const interactive = onClick
? "cursor-pointer hover:brightness-110 transition"
: "";
- const ring = selected ? "ring-2 ring-offset-1 ring-offset-base-100" : "";
+ const ring = selected ? "ring-2 ring-offset-1 ring-offset-background" : "";
const content = (
<>