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 (
-
+ {
+ e.stopPropagation();
+ handleRemoveCategory(entry.id);
+ }}
+ style={{
+ background: 'none',
+ border: 'none',
+ padding: '0 4px',
+ cursor: 'pointer',
+ fontSize: '18px',
+ lineHeight: 1
+ }}
+ aria-label="Remove category"
+ >
+ ×
+
+
);
})}