diff --git a/taskncoffee-app/src/pages/Dashboard.jsx b/taskncoffee-app/src/pages/Dashboard.jsx index eb3251e..436bb0f 100644 --- a/taskncoffee-app/src/pages/Dashboard.jsx +++ b/taskncoffee-app/src/pages/Dashboard.jsx @@ -12,24 +12,67 @@ const menuItems = [ ]; export default function Dashboard() { - const daysOfWeek = [ - { - name: 'Monday', - tasks: [ - { id: 1, title: 'Task 1 super task enable', completed: false }, - { id: 2, title: 'Task 2', completed: false }, - { id: 3, title: 'Task 3', completed: true } - ] - }, - { name: 'Tuesday', tasks: [] }, - { name: 'Wednesday', tasks: [] }, - { name: 'Thursday', tasks: [] }, - { name: 'Friday', tasks: [] }, - { name: 'Saturday', tasks: [] }, - { name: 'Sunday', tasks: [] } + // Mock data from backend + const tasksFromBackend = [ + { title: "testtitle", due_date: "2025-10-14", priority: "medium", id: 1, status: "open" }, + { title: "title", due_date: "2025-10-15", priority: "high", id: 3, status: "open" }, + { title: "title title2", due_date: "2025-10-15", priority: "medium", id: 4, status: "closed" }, + { title: "title title3", due_date: "2025-10-15", priority: "medium", id: 5, status: "open" }, + { title: "title16", due_date: "2025-10-15", priority: "medium", id: 6, status: "completed" }, + { title: "super late title", due_date: "2025-10-15", priority: "low", id: 2, status: "open" } ]; - const today = new Date().getDay(); + // Get current date and week + const today = new Date(); + const currentDay = today.getDay(); + + // Calculate the Monday of current week + const currentDate = new Date(today); + const dayOffset = currentDay === 0 ? -6 : 1 - currentDay; + currentDate.setDate(today.getDate() + dayOffset); + + // Group tasks by day + const groupTasksByDay = (tasks) => { + const grouped = {}; + + tasks.forEach(task => { + const taskDate = new Date(task.due_date); + const dateKey = taskDate.toDateString(); + + if (!grouped[dateKey]) { + grouped[dateKey] = []; + } + + grouped[dateKey].push({ + id: task.id, + title: task.title, + priority: task.priority, + completed: task.status === 'closed' || task.status === 'completed', + dueDate: task.due_date + }); + }); + + return grouped; + }; + + const groupedTasks = groupTasksByDay(tasksFromBackend); + + // Generate days of week with dates and tasks + const daysOfWeek = [ + 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday' + ].map((name, index) => { + const date = new Date(currentDate); + date.setDate(currentDate.getDate() + index); + const dateKey = date.toDateString(); + + return { + name, + date: date.getDate(), + month: date.toLocaleDateString('en-US', { month: 'short' }), + fullDate: date, + tasks: groupedTasks[dateKey] || [] + }; + }); return (
- Material Design 3 filled container with large rounded corners. -
-- Elevated surface with prominent shadow for hierarchy. -
-- Outlined container with subtle border emphasis. -
-{task.title}
-No tasks
- )} + {daysOfWeek.map((day, index) => { + const isToday = day.fullDate.toDateString() === today.toDateString(); + + return ( +{day.month} {day.date}
+{task.title}
+No tasks
+ )} +