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:
@@ -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 (
|
||||
<TasksProvider initialTasks={initialTasks} initialStats={initialStats}>
|
||||
<TasksProvider
|
||||
initialTasks={initialTasks}
|
||||
initialStats={initialStats}
|
||||
initialTags={initialTags}
|
||||
>
|
||||
<HomePageContent />
|
||||
</TasksProvider>
|
||||
);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 (
|
||||
<HomePageClient
|
||||
initialTasks={initialTasks}
|
||||
initialStats={initialStats}
|
||||
initialTags={initialTags}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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<KanbanFilters>({});
|
||||
|
||||
Reference in New Issue
Block a user