From 65ab2776ebcd094192964e0ea7bc57c16ee453bc Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Tue, 11 Nov 2025 08:25:36 +1100 Subject: [PATCH] feat: enhance TagEditor to support primary category selection and reorder categories --- src/renderer/src/components/TagEditor.tsx | 111 ++++++++++++++++++---- 1 file changed, 94 insertions(+), 17 deletions(-) diff --git a/src/renderer/src/components/TagEditor.tsx b/src/renderer/src/components/TagEditor.tsx index ef3aa01..36e735e 100644 --- a/src/renderer/src/components/TagEditor.tsx +++ b/src/renderer/src/components/TagEditor.tsx @@ -71,16 +71,18 @@ export function TagEditor({ categories, availableCategories, onSave, showHeading }, [availableCategories, categoryFilter]); const selectedCategoryRecords = useMemo( - () => availableCategories - .filter((entry) => selectedCategories.has(entry.id)) - .sort((left, right) => { - const topLevelComparison = left.category.localeCompare(right.category); - if (topLevelComparison !== 0) { - return topLevelComparison; + () => { + // Preserve the order from the categories prop (first category is primary) + const orderedRecords: CategoryRecord[] = []; + for (const catId of categories) { + const record = availableCategories.find((entry) => entry.id === catId); + if (record && selectedCategories.has(catId)) { + orderedRecords.push(record); } - return left.subCategory.localeCompare(right.subCategory); - }), - [availableCategories, selectedCategories] + } + return orderedRecords; + }, + [availableCategories, selectedCategories, categories] ); const categoryColorMap = useMemo(() => { @@ -137,6 +139,16 @@ export function TagEditor({ categories, availableCategories, onSave, showHeading onSave(Array.from(next)); }; + const handleSetPrimaryCategory = (categoryId: string) => { + const currentList = Array.from(selectedCategories); + // Remove the category from its current position + const filteredList = currentList.filter((id) => id !== categoryId); + // Add it to the front + const reorderedList = [categoryId, ...filteredList]; + setSelectedCategories(new Set(reorderedList)); + void onSave(reorderedList); + }; + const handleRemoveCategory = (categoryId: string) => { if (!selectedCategories.has(categoryId)) { return; @@ -201,24 +213,89 @@ export function TagEditor({ categories, availableCategories, onSave, showHeading
{selectedCategoryRecords.length === 0 && No categories selected} - {selectedCategoryRecords.map((entry) => { + {selectedCategoryRecords.map((entry, index) => { const categoryLabel = formatCategoryLabel(entry.category); const subCategoryLabel = formatCategoryLabel(entry.subCategory); + const isPrimary = index === 0; return ( - {categoryLabel} {subCategoryLabel} - - + +
); })}