From 95af83b0bc82353d91b3c6bc70260de5ba4b09b9 Mon Sep 17 00:00:00 2001 From: Julien Froidefond Date: Sun, 14 Sep 2025 22:45:52 +0200 Subject: [PATCH] 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`. --- components/HomePageClient.tsx | 11 ++++++++--- hooks/useTags.ts | 15 +++++++++------ src/app/page.tsx | 7 +++++-- src/contexts/TasksContext.tsx | 5 +++-- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/components/HomePageClient.tsx b/components/HomePageClient.tsx index 126275d..78efd74 100644 --- a/components/HomePageClient.tsx +++ b/components/HomePageClient.tsx @@ -3,7 +3,7 @@ import { KanbanBoardContainer } from '@/components/kanban/BoardContainer'; import { Header } from '@/components/ui/Header'; import { TasksProvider, useTasksContext } from '@/contexts/TasksContext'; -import { Task } from '@/lib/types'; +import { Task, Tag } from '@/lib/types'; interface HomePageClientProps { initialTasks: Task[]; @@ -14,6 +14,7 @@ interface HomePageClientProps { todo: number; completionRate: number; }; + initialTags: (Tag & { usage: number })[]; } function HomePageContent() { @@ -35,9 +36,13 @@ function HomePageContent() { ); } -export function HomePageClient({ initialTasks, initialStats }: HomePageClientProps) { +export function HomePageClient({ initialTasks, initialStats, initialTags }: HomePageClientProps) { return ( - + ); diff --git a/hooks/useTags.ts b/hooks/useTags.ts index 69ac84e..7ca0cd1 100644 --- a/hooks/useTags.ts +++ b/hooks/useTags.ts @@ -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({ - 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, diff --git a/src/app/page.tsx b/src/app/page.tsx index 8f23f1f..61f025a 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,17 +1,20 @@ import { tasksService } from '@/services/tasks'; +import { tagsService } from '@/services/tags'; import { HomePageClient } from '@/components/HomePageClient'; export default async function HomePage() { // SSR - Récupération des données côté serveur - const [initialTasks, initialStats] = await Promise.all([ + const [initialTasks, initialStats, initialTags] = await Promise.all([ tasksService.getTasks(), - tasksService.getTaskStats() + tasksService.getTaskStats(), + tagsService.getTags() ]); return ( ); } diff --git a/src/contexts/TasksContext.tsx b/src/contexts/TasksContext.tsx index 23d9ea6..8f88049 100644 --- a/src/contexts/TasksContext.tsx +++ b/src/contexts/TasksContext.tsx @@ -43,15 +43,16 @@ interface TasksProviderProps { children: ReactNode; initialTasks: Task[]; initialStats: TasksContextType['stats']; + initialTags?: (Tag & { usage: number })[]; } -export function TasksProvider({ children, initialTasks, initialStats }: TasksProviderProps) { +export function TasksProvider({ children, initialTasks, initialStats, initialTags }: TasksProviderProps) { const tasksState = useTasks( { limit: 20 }, { tasks: initialTasks, stats: initialStats } ); - const { tags, loading: tagsLoading, error: tagsError } = useTags(); + const { tags, loading: tagsLoading, error: tagsError } = useTags(initialTags); // État des filtres Kanban avec persistance const [kanbanFilters, setKanbanFilters] = useState({});