import { useState } from "react"; import { Button } from "@/components/ui/button"; import { ChevronLeft, ChevronRight } from "lucide-react"; import { useQuery } from "@tanstack/react-query"; import type { ScheduledPost } from "@shared/schema"; export default function CalendarView() { const [currentDate, setCurrentDate] = useState(new Date()); const { data: scheduledPosts = [] } = useQuery({ queryKey: ["/api/scheduled-posts"], }); const getPostsForDate = (date: Date) => { return (scheduledPosts || []).filter(post => { if (!post.scheduledAt) return false; const postDate = new Date(post.scheduledAt); return postDate.toDateString() === date.toDateString(); }); }; const goToPreviousMonth = () => { setCurrentDate(new Date(currentDate.getFullYear(), currentDate.getMonth() - 1, 1)); }; const goToNextMonth = () => { setCurrentDate(new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 1)); }; const monthNames = [ "Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre" ]; const daysOfWeek = ["Lun", "Mar", "Mer", "Jeu", "Ven", "Sam", "Dim"]; const getDaysInMonth = (date: Date) => { const year = date.getFullYear(); const month = date.getMonth(); const firstDay = new Date(year, month, 1); const lastDay = new Date(year, month + 1, 0); const daysInMonth = lastDay.getDate(); const startingDayOfWeek = firstDay.getDay() === 0 ? 6 : firstDay.getDay() - 1; const days = []; // Previous month days for (let i = 0; i < startingDayOfWeek; i++) { const prevMonthDay = new Date(year, month, -startingDayOfWeek + i + 1); days.push({ date: prevMonthDay, isCurrentMonth: false }); } // Current month days for (let i = 1; i <= daysInMonth; i++) { days.push({ date: new Date(year, month, i), isCurrentMonth: true }); } // Next month days to fill the grid const remainingDays = 42 - days.length; for (let i = 1; i <= remainingDays; i++) { days.push({ date: new Date(year, month + 1, i), isCurrentMonth: false }); } return days; }; const days = getDaysInMonth(currentDate); const isToday = (date: Date) => { const today = new Date(); return date.toDateString() === today.toDateString(); }; return (

Calendrier des publications

Planifiez vos publications sur plusieurs pages

{monthNames[currentDate.getMonth()]} {currentDate.getFullYear()}
{/* Calendar Header */}
{daysOfWeek.map((day) => (
{day}
))}
{/* Calendar Grid */}
{days.map((day, index) => (
{day.date.getDate()} {isToday(day.date) && ( Aujourd'hui )}
{/* Real scheduled posts for this date */} {(() => { if (!day.isCurrentMonth) return null; const postsForDay = getPostsForDate(day.date); if (postsForDay.length === 0) return null; return (
{postsForDay.slice(0, 2).map((post, idx) => { const time = post.scheduledAt ? new Date(post.scheduledAt).toLocaleTimeString('fr-FR', { hour: '2-digit', minute: '2-digit' }) : ''; const isPending = !post.publishedAt; const isPublished = !!post.publishedAt; return (
{time} - {post.postType || 'Post'}
); })} {postsForDay.length > 2 && (
+{postsForDay.length - 2} autre(s)
)}
); })()}
))}
{/* Legend */}
Programmé
Publié
); }