refactor: update tag data structure and improve tag handling

- Changed `TagsResponse` and `UseTagsState` to include `usage` count in the tag data structure for better tracking.
- Simplified tag initialization in `useTags` to directly use `initialData`.
- Enhanced `TagsPageClient` to filter and sort tags based on usage, improving user experience in tag management.
- Removed unused variables and streamlined the search functionality for better performance.
This commit is contained in:
Julien Froidefond
2025-09-15 09:29:38 +02:00
parent fc20154ef6
commit 631da57ea2
3 changed files with 142 additions and 156 deletions

View File

@@ -5,7 +5,7 @@ import { tagsClient, TagFilters, CreateTagData, UpdateTagData, TagsClient } from
import { Tag } from '@/lib/types';
interface UseTagsState {
tags: Tag[];
tags: Array<Tag & { usage: number }>;
popularTags: Array<Tag & { usage: number }>;
loading: boolean;
error: string | null;
@@ -29,7 +29,7 @@ export function useTags(
initialFilters?: TagFilters
): UseTagsState & UseTagsActions {
const [state, setState] = useState<UseTagsState>({
tags: initialData?.map(tag => ({ id: tag.id, name: tag.name, color: tag.color, isPinned: tag.isPinned })) || [],
tags: initialData || [],
popularTags: initialData || [],
loading: !initialData,
error: null