feat: integrate tags into HomePage and TasksContext
- Added `initialTags` prop to `HomePageClient` for passing tag data. - Updated `TasksProvider` to accept and utilize `initialTags`, enhancing tag management. - Modified `useTags` hook to initialize state with provided tags and conditionally refresh tags based on initial data. - Updated server-side data fetching in `HomePage` to include tags from the `tagsService`.
This commit is contained in:
@@ -25,12 +25,13 @@ interface UseTagsActions {
|
||||
* Hook pour la gestion des tags
|
||||
*/
|
||||
export function useTags(
|
||||
initialData?: (Tag & { usage: number })[],
|
||||
initialFilters?: TagFilters
|
||||
): UseTagsState & UseTagsActions {
|
||||
const [state, setState] = useState<UseTagsState>({
|
||||
tags: [],
|
||||
popularTags: [],
|
||||
loading: false,
|
||||
tags: initialData?.map(tag => ({ id: tag.id, name: tag.name, color: tag.color, isPinned: tag.isPinned })) || [],
|
||||
popularTags: initialData || [],
|
||||
loading: !initialData,
|
||||
error: null
|
||||
});
|
||||
|
||||
@@ -168,10 +169,12 @@ export function useTags(
|
||||
}
|
||||
}, [refreshTags]);
|
||||
|
||||
// Charger les tags au montage et quand les filtres changent
|
||||
// Charger les tags au montage et quand les filtres changent (seulement si pas de données initiales)
|
||||
useEffect(() => {
|
||||
refreshTags();
|
||||
}, [refreshTags]);
|
||||
if (!initialData) {
|
||||
refreshTags();
|
||||
}
|
||||
}, [refreshTags, initialData]);
|
||||
|
||||
return {
|
||||
...state,
|
||||
|
||||
Reference in New Issue
Block a user