feat(06-02): replace EmojiPicker with IconPicker across all category components

- CategoryPicker shows LucideIcon prefix and uses IconPicker for inline create
- CategoryHeader displays LucideIcon in view mode and IconPicker in edit mode
- OnboardingWizard uses IconPicker for category creation step
- CreateThreadModal drops emoji from category select options
- Fixed categoryEmoji -> categoryIcon in routes and useCategories hook

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-15 17:57:56 +01:00
parent 615c8944c4
commit 570bcea5c9
7 changed files with 391 additions and 338 deletions

View File

@@ -1,11 +1,13 @@
import { useState } from "react"; import { useState } from "react";
import { formatWeight, formatPrice } from "../lib/formatters"; import { formatWeight, formatPrice } from "../lib/formatters";
import { useUpdateCategory, useDeleteCategory } from "../hooks/useCategories"; import { useUpdateCategory, useDeleteCategory } from "../hooks/useCategories";
import { LucideIcon } from "../lib/iconData";
import { IconPicker } from "./IconPicker";
interface CategoryHeaderProps { interface CategoryHeaderProps {
categoryId: number; categoryId: number;
name: string; name: string;
emoji: string; icon: string;
totalWeight: number; totalWeight: number;
totalCost: number; totalCost: number;
itemCount: number; itemCount: number;
@@ -14,14 +16,14 @@ interface CategoryHeaderProps {
export function CategoryHeader({ export function CategoryHeader({
categoryId, categoryId,
name, name,
emoji, icon,
totalWeight, totalWeight,
totalCost, totalCost,
itemCount, itemCount,
}: CategoryHeaderProps) { }: CategoryHeaderProps) {
const [isEditing, setIsEditing] = useState(false); const [isEditing, setIsEditing] = useState(false);
const [editName, setEditName] = useState(name); const [editName, setEditName] = useState(name);
const [editEmoji, setEditEmoji] = useState(emoji); const [editIcon, setEditIcon] = useState(icon);
const updateCategory = useUpdateCategory(); const updateCategory = useUpdateCategory();
const deleteCategory = useDeleteCategory(); const deleteCategory = useDeleteCategory();
@@ -30,7 +32,7 @@ export function CategoryHeader({
function handleSave() { function handleSave() {
if (!editName.trim()) return; if (!editName.trim()) return;
updateCategory.mutate( updateCategory.mutate(
{ id: categoryId, name: editName.trim(), emoji: editEmoji }, { id: categoryId, name: editName.trim(), icon: editIcon },
{ onSuccess: () => setIsEditing(false) }, { onSuccess: () => setIsEditing(false) },
); );
} }
@@ -46,13 +48,7 @@ export function CategoryHeader({
if (isEditing) { if (isEditing) {
return ( return (
<div className="flex items-center gap-3 py-4"> <div className="flex items-center gap-3 py-4">
<input <IconPicker value={editIcon} onChange={setEditIcon} size="sm" />
type="text"
value={editEmoji}
onChange={(e) => setEditEmoji(e.target.value)}
className="w-12 text-center text-xl border border-gray-200 rounded-md px-1 py-1"
maxLength={4}
/>
<input <input
type="text" type="text"
value={editName} value={editName}
@@ -84,7 +80,7 @@ export function CategoryHeader({
return ( return (
<div className="group flex items-center gap-3 py-4"> <div className="group flex items-center gap-3 py-4">
<span className="text-xl">{emoji}</span> <LucideIcon name={icon} size={22} className="text-gray-500" />
<h2 className="text-lg font-semibold text-gray-900">{name}</h2> <h2 className="text-lg font-semibold text-gray-900">{name}</h2>
<span className="text-sm text-gray-400"> <span className="text-sm text-gray-400">
{itemCount} {itemCount === 1 ? "item" : "items"} ·{" "} {itemCount} {itemCount === 1 ? "item" : "items"} ·{" "}
@@ -96,7 +92,7 @@ export function CategoryHeader({
type="button" type="button"
onClick={() => { onClick={() => {
setEditName(name); setEditName(name);
setEditEmoji(emoji); setEditIcon(icon);
setIsEditing(true); setIsEditing(true);
}} }}
className="p-1 text-gray-400 hover:text-gray-600 rounded" className="p-1 text-gray-400 hover:text-gray-600 rounded"

View File

@@ -1,8 +1,10 @@
import { useState, useRef, useEffect } from "react"; import { useEffect, useRef, useState } from "react";
import { import {
useCategories, useCategories,
useCreateCategory, useCreateCategory,
} from "../hooks/useCategories"; } from "../hooks/useCategories";
import { LucideIcon } from "../lib/iconData";
import { IconPicker } from "./IconPicker";
interface CategoryPickerProps { interface CategoryPickerProps {
value: number; value: number;
@@ -15,6 +17,8 @@ export function CategoryPicker({ value, onChange }: CategoryPickerProps) {
const [inputValue, setInputValue] = useState(""); const [inputValue, setInputValue] = useState("");
const [isOpen, setIsOpen] = useState(false); const [isOpen, setIsOpen] = useState(false);
const [highlightIndex, setHighlightIndex] = useState(-1); const [highlightIndex, setHighlightIndex] = useState(-1);
const [isCreating, setIsCreating] = useState(false);
const [newCategoryIcon, setNewCategoryIcon] = useState("package");
const containerRef = useRef<HTMLDivElement>(null); const containerRef = useRef<HTMLDivElement>(null);
const inputRef = useRef<HTMLInputElement>(null); const inputRef = useRef<HTMLInputElement>(null);
const listRef = useRef<HTMLUListElement>(null); const listRef = useRef<HTMLUListElement>(null);
@@ -36,11 +40,15 @@ export function CategoryPicker({ value, onChange }: CategoryPickerProps) {
useEffect(() => { useEffect(() => {
function handleClickOutside(e: MouseEvent) { function handleClickOutside(e: MouseEvent) {
const target = e.target as Node;
if ( if (
containerRef.current && containerRef.current &&
!containerRef.current.contains(e.target as Node) !containerRef.current.contains(target) &&
!(target instanceof Element && target.closest("[data-icon-picker]"))
) { ) {
setIsOpen(false); setIsOpen(false);
setIsCreating(false);
setNewCategoryIcon("package");
// Reset input to selected category name // Reset input to selected category name
if (selectedCategory) { if (selectedCategory) {
setInputValue(""); setInputValue("");
@@ -58,13 +66,19 @@ export function CategoryPicker({ value, onChange }: CategoryPickerProps) {
setHighlightIndex(-1); setHighlightIndex(-1);
} }
async function handleCreate() { function handleStartCreate() {
setIsCreating(true);
}
async function handleConfirmCreate() {
const name = inputValue.trim(); const name = inputValue.trim();
if (!name) return; if (!name) return;
createCategory.mutate( createCategory.mutate(
{ name, emoji: "\u{1F4E6}" }, { name, icon: newCategoryIcon },
{ {
onSuccess: (newCat) => { onSuccess: (newCat) => {
setIsCreating(false);
setNewCategoryIcon("package");
handleSelect(newCat.id); handleSelect(newCat.id);
}, },
}, },
@@ -91,19 +105,26 @@ export function CategoryPicker({ value, onChange }: CategoryPickerProps) {
break; break;
case "Enter": case "Enter":
e.preventDefault(); e.preventDefault();
if (highlightIndex >= 0 && highlightIndex < filtered.length) { if (isCreating) {
handleConfirmCreate();
} else if (highlightIndex >= 0 && highlightIndex < filtered.length) {
handleSelect(filtered[highlightIndex].id); handleSelect(filtered[highlightIndex].id);
} else if ( } else if (
showCreateOption && showCreateOption &&
highlightIndex === filtered.length highlightIndex === filtered.length
) { ) {
handleCreate(); handleStartCreate();
} }
break; break;
case "Escape": case "Escape":
if (isCreating) {
setIsCreating(false);
setNewCategoryIcon("package");
} else {
setIsOpen(false); setIsOpen(false);
setHighlightIndex(-1); setHighlightIndex(-1);
setInputValue(""); setInputValue("");
}
break; break;
} }
} }
@@ -118,6 +139,16 @@ export function CategoryPicker({ value, onChange }: CategoryPickerProps) {
return ( return (
<div ref={containerRef} className="relative"> <div ref={containerRef} className="relative">
<div className="relative">
{!isOpen && selectedCategory && (
<div className="absolute left-3 top-1/2 -translate-y-1/2 pointer-events-none">
<LucideIcon
name={selectedCategory.icon}
size={16}
className="text-gray-500"
/>
</div>
)}
<input <input
ref={inputRef} ref={inputRef}
type="text" type="text"
@@ -126,13 +157,15 @@ export function CategoryPicker({ value, onChange }: CategoryPickerProps) {
aria-autocomplete="list" aria-autocomplete="list"
aria-controls="category-listbox" aria-controls="category-listbox"
aria-activedescendant={ aria-activedescendant={
highlightIndex >= 0 ? `category-option-${highlightIndex}` : undefined highlightIndex >= 0
? `category-option-${highlightIndex}`
: undefined
} }
value={ value={
isOpen isOpen
? inputValue ? inputValue
: selectedCategory : selectedCategory
? `${selectedCategory.emoji} ${selectedCategory.name}` ? selectedCategory.name
: "" : ""
} }
placeholder="Search or create category..." placeholder="Search or create category..."
@@ -146,8 +179,11 @@ export function CategoryPicker({ value, onChange }: CategoryPickerProps) {
setInputValue(""); setInputValue("");
}} }}
onKeyDown={handleKeyDown} onKeyDown={handleKeyDown}
className="w-full px-3 py-2 border border-gray-200 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent" className={`w-full py-2 border border-gray-200 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent ${
!isOpen && selectedCategory ? "pl-8 pr-3" : "px-3"
}`}
/> />
</div>
{isOpen && ( {isOpen && (
<ul <ul
ref={listRef} ref={listRef}
@@ -161,7 +197,7 @@ export function CategoryPicker({ value, onChange }: CategoryPickerProps) {
id={`category-option-${i}`} id={`category-option-${i}`}
role="option" role="option"
aria-selected={cat.id === value} aria-selected={cat.id === value}
className={`px-3 py-2 text-sm cursor-pointer ${ className={`px-3 py-2 text-sm cursor-pointer flex items-center gap-1.5 ${
i === highlightIndex i === highlightIndex
? "bg-blue-50 text-blue-900" ? "bg-blue-50 text-blue-900"
: "hover:bg-gray-50" : "hover:bg-gray-50"
@@ -169,10 +205,15 @@ export function CategoryPicker({ value, onChange }: CategoryPickerProps) {
onClick={() => handleSelect(cat.id)} onClick={() => handleSelect(cat.id)}
onMouseEnter={() => setHighlightIndex(i)} onMouseEnter={() => setHighlightIndex(i)}
> >
{cat.emoji} {cat.name} <LucideIcon
name={cat.icon}
size={16}
className="text-gray-500 shrink-0"
/>
{cat.name}
</li> </li>
))} ))}
{showCreateOption && ( {showCreateOption && !isCreating && (
<li <li
id={`category-option-${filtered.length}`} id={`category-option-${filtered.length}`}
role="option" role="option"
@@ -182,12 +223,34 @@ export function CategoryPicker({ value, onChange }: CategoryPickerProps) {
? "bg-blue-50 text-blue-900" ? "bg-blue-50 text-blue-900"
: "hover:bg-gray-50 text-gray-600" : "hover:bg-gray-50 text-gray-600"
}`} }`}
onClick={handleCreate} onClick={handleStartCreate}
onMouseEnter={() => setHighlightIndex(filtered.length)} onMouseEnter={() => setHighlightIndex(filtered.length)}
> >
+ Create "{inputValue.trim()}" + Create "{inputValue.trim()}"
</li> </li>
)} )}
{isCreating && (
<li className="px-3 py-2 border-t border-gray-100">
<div className="flex items-center gap-2">
<IconPicker
value={newCategoryIcon}
onChange={setNewCategoryIcon}
size="sm"
/>
<span className="text-sm text-gray-700 truncate flex-1">
{inputValue.trim()}
</span>
<button
type="button"
onClick={handleConfirmCreate}
disabled={createCategory.isPending}
className="text-xs font-medium text-blue-600 hover:text-blue-800 disabled:opacity-50"
>
{createCategory.isPending ? "..." : "Create"}
</button>
</div>
</li>
)}
{filtered.length === 0 && !showCreateOption && ( {filtered.length === 0 && !showCreateOption && (
<li className="px-3 py-2 text-sm text-gray-400"> <li className="px-3 py-2 text-sm text-gray-400">
No categories found No categories found

View File

@@ -112,7 +112,7 @@ export function CreateThreadModal() {
> >
{categories?.map((cat) => ( {categories?.map((cat) => (
<option key={cat.id} value={cat.id}> <option key={cat.id} value={cat.id}>
{cat.emoji} {cat.name} {cat.name}
</option> </option>
))} ))}
</select> </select>

View File

@@ -2,6 +2,7 @@ import { useState } from "react";
import { useCreateCategory } from "../hooks/useCategories"; import { useCreateCategory } from "../hooks/useCategories";
import { useCreateItem } from "../hooks/useItems"; import { useCreateItem } from "../hooks/useItems";
import { useUpdateSetting } from "../hooks/useSettings"; import { useUpdateSetting } from "../hooks/useSettings";
import { IconPicker } from "./IconPicker";
interface OnboardingWizardProps { interface OnboardingWizardProps {
onComplete: () => void; onComplete: () => void;
@@ -12,7 +13,7 @@ export function OnboardingWizard({ onComplete }: OnboardingWizardProps) {
// Step 2 state // Step 2 state
const [categoryName, setCategoryName] = useState(""); const [categoryName, setCategoryName] = useState("");
const [categoryEmoji, setCategoryEmoji] = useState(""); const [categoryIcon, setCategoryIcon] = useState("");
const [categoryError, setCategoryError] = useState(""); const [categoryError, setCategoryError] = useState("");
const [createdCategoryId, setCreatedCategoryId] = useState<number | null>(null); const [createdCategoryId, setCreatedCategoryId] = useState<number | null>(null);
@@ -41,7 +42,7 @@ export function OnboardingWizard({ onComplete }: OnboardingWizardProps) {
} }
setCategoryError(""); setCategoryError("");
createCategory.mutate( createCategory.mutate(
{ name, emoji: categoryEmoji.trim() || undefined }, { name, icon: categoryIcon.trim() || undefined },
{ {
onSuccess: (created) => { onSuccess: (created) => {
setCreatedCategoryId(created.id); setCreatedCategoryId(created.id);
@@ -164,20 +165,13 @@ export function OnboardingWizard({ onComplete }: OnboardingWizardProps) {
</div> </div>
<div> <div>
<label <label className="block text-sm font-medium text-gray-700 mb-1">
htmlFor="onboard-cat-emoji" Icon (optional)
className="block text-sm font-medium text-gray-700 mb-1"
>
Emoji (optional)
</label> </label>
<input <IconPicker
id="onboard-cat-emoji" value={categoryIcon}
type="text" onChange={setCategoryIcon}
value={categoryEmoji} size="md"
onChange={(e) => setCategoryEmoji(e.target.value)}
className="w-20 px-3 py-2 border border-gray-200 rounded-lg text-center text-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
placeholder="&#9978;"
maxLength={4}
/> />
</div> </div>

View File

@@ -98,7 +98,7 @@ function CollectionView() {
// Group items by categoryId // Group items by categoryId
const groupedItems = new Map< const groupedItems = new Map<
number, number,
{ items: typeof items; categoryName: string; categoryEmoji: string } { items: typeof items; categoryName: string; categoryIcon: string }
>(); >();
for (const item of items) { for (const item of items) {
@@ -109,7 +109,7 @@ function CollectionView() {
groupedItems.set(item.categoryId, { groupedItems.set(item.categoryId, {
items: [item], items: [item],
categoryName: item.categoryName, categoryName: item.categoryName,
categoryEmoji: item.categoryEmoji, categoryIcon: item.categoryIcon,
}); });
} }
} }
@@ -134,7 +134,7 @@ function CollectionView() {
{Array.from(groupedItems.entries()).map( {Array.from(groupedItems.entries()).map(
([ ([
categoryId, categoryId,
{ items: categoryItems, categoryName, categoryEmoji }, { items: categoryItems, categoryName, categoryIcon },
]) => { ]) => {
const catTotals = categoryTotalsMap.get(categoryId); const catTotals = categoryTotalsMap.get(categoryId);
return ( return (
@@ -142,7 +142,7 @@ function CollectionView() {
<CategoryHeader <CategoryHeader
categoryId={categoryId} categoryId={categoryId}
name={categoryName} name={categoryName}
emoji={categoryEmoji} icon={categoryIcon}
totalWeight={catTotals?.totalWeight ?? 0} totalWeight={catTotals?.totalWeight ?? 0}
totalCost={catTotals?.totalCost ?? 0} totalCost={catTotals?.totalCost ?? 0}
itemCount={catTotals?.itemCount ?? categoryItems.length} itemCount={catTotals?.itemCount ?? categoryItems.length}
@@ -156,7 +156,7 @@ function CollectionView() {
weightGrams={item.weightGrams} weightGrams={item.weightGrams}
priceCents={item.priceCents} priceCents={item.priceCents}
categoryName={categoryName} categoryName={categoryName}
categoryEmoji={categoryEmoji} categoryIcon={categoryIcon}
imageFilename={item.imageFilename} imageFilename={item.imageFilename}
/> />
))} ))}
@@ -268,7 +268,7 @@ function PlanningView() {
<option value="">All categories</option> <option value="">All categories</option>
{categories?.map((cat) => ( {categories?.map((cat) => (
<option key={cat.id} value={cat.id}> <option key={cat.id} value={cat.id}>
{cat.emoji} {cat.name} {cat.name}
</option> </option>
))} ))}
</select> </select>
@@ -356,7 +356,7 @@ function PlanningView() {
createdAt={thread.createdAt} createdAt={thread.createdAt}
status={thread.status} status={thread.status}
categoryName={thread.categoryName} categoryName={thread.categoryName}
categoryEmoji={thread.categoryEmoji} categoryIcon={thread.categoryIcon}
/> />
))} ))}
</div> </div>

View File

@@ -66,7 +66,7 @@ function SetupDetailPage() {
{ {
items: typeof setup.items; items: typeof setup.items;
categoryName: string; categoryName: string;
categoryEmoji: string; categoryIcon: string;
} }
>(); >();
@@ -78,7 +78,7 @@ function SetupDetailPage() {
groupedItems.set(item.categoryId, { groupedItems.set(item.categoryId, {
items: [item], items: [item],
categoryName: item.categoryName, categoryName: item.categoryName,
categoryEmoji: item.categoryEmoji, categoryIcon: item.categoryIcon,
}); });
} }
} }
@@ -177,7 +177,7 @@ function SetupDetailPage() {
{Array.from(groupedItems.entries()).map( {Array.from(groupedItems.entries()).map(
([ ([
categoryId, categoryId,
{ items: categoryItems, categoryName, categoryEmoji }, { items: categoryItems, categoryName, categoryIcon },
]) => { ]) => {
const catWeight = categoryItems.reduce( const catWeight = categoryItems.reduce(
(sum, item) => sum + (item.weightGrams ?? 0), (sum, item) => sum + (item.weightGrams ?? 0),
@@ -192,7 +192,7 @@ function SetupDetailPage() {
<CategoryHeader <CategoryHeader
categoryId={categoryId} categoryId={categoryId}
name={categoryName} name={categoryName}
emoji={categoryEmoji} icon={categoryIcon}
totalWeight={catWeight} totalWeight={catWeight}
totalCost={catCost} totalCost={catCost}
itemCount={categoryItems.length} itemCount={categoryItems.length}
@@ -206,7 +206,7 @@ function SetupDetailPage() {
weightGrams={item.weightGrams} weightGrams={item.weightGrams}
priceCents={item.priceCents} priceCents={item.priceCents}
categoryName={categoryName} categoryName={categoryName}
categoryEmoji={categoryEmoji} categoryIcon={categoryIcon}
imageFilename={item.imageFilename} imageFilename={item.imageFilename}
onRemove={() => removeItem.mutate(item.id)} onRemove={() => removeItem.mutate(item.id)}
/> />

View File

@@ -134,7 +134,7 @@ function ThreadDetailPage() {
weightGrams={candidate.weightGrams} weightGrams={candidate.weightGrams}
priceCents={candidate.priceCents} priceCents={candidate.priceCents}
categoryName={candidate.categoryName} categoryName={candidate.categoryName}
categoryEmoji={candidate.categoryEmoji} categoryIcon={candidate.categoryIcon}
imageFilename={candidate.imageFilename} imageFilename={candidate.imageFilename}
threadId={threadId} threadId={threadId}
isActive={isActive} isActive={isActive}