feat(frontend): tie-break category-name tag sort by tag name

Mirror the server's secondary sort in the client-side sortTags (used for
a file's assigned tags) so the assigned and available lists agree.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-11 21:47:55 +03:00
parent cb1588ecc0
commit fedfa8df3a
+7 -1
View File
@@ -54,5 +54,11 @@ function tagSortKey(t: Tag, field: TagSortField): string {
*/
export function sortTags(tags: Tag[], { sort, order }: SortState<TagSortField>): Tag[] {
const dir = order === 'asc' ? 1 : -1;
return [...tags].sort((a, b) => dir * tagSortKey(a, sort).localeCompare(tagSortKey(b, sort)));
return [...tags].sort((a, b) => {
const primary = dir * tagSortKey(a, sort).localeCompare(tagSortKey(b, sort));
if (primary !== 0 || sort !== 'category_name') return primary;
// Same category: break the tie by the tag's own name (same direction), so
// tags are grouped by category then alphabetical — matching the server.
return dir * (a.name ?? '').localeCompare(b.name ?? '');
});
}