|
| 1 | +import { useState } from "react"; |
| 2 | +import { changeMonth, dayNames, months } from "./utils.ts"; |
| 3 | +import times from "lodash/times"; |
| 4 | +import DayCard from "./DayCard.tsx"; |
| 5 | + |
| 6 | +export default function Events() { |
| 7 | + // const today = new Date(); |
| 8 | + const [currentDate, setCurrentDate] = useState<Date>(new Date()); |
| 9 | + |
| 10 | + return ( |
| 11 | + <main className="flex h-full w-full flex-col"> |
| 12 | + <section className="flex h-full flex-col justify-center"> |
| 13 | + <h3 className="my-12 text-center text-3xl text-secondary">Events</h3> |
| 14 | + <div className="flex w-full flex-col items-center justify-center bg-background px-16"> |
| 15 | + <div className="mb-6 flex w-full justify-center"> |
| 16 | + <button |
| 17 | + className="text-3xl" |
| 18 | + onClick={() => { |
| 19 | + const newDate = changeMonth(-1, currentDate); |
| 20 | + setCurrentDate(new Date(newDate.toDateString())); |
| 21 | + }} |
| 22 | + > |
| 23 | + < |
| 24 | + </button> |
| 25 | + <span className="mx-12 text-3xl"> |
| 26 | + {months[currentDate.getMonth()][0]} |
| 27 | + </span> |
| 28 | + <button |
| 29 | + className="text-3xl" |
| 30 | + onClick={() => { |
| 31 | + const newDate = changeMonth(1, currentDate); |
| 32 | + setCurrentDate(new Date(newDate.toDateString())); |
| 33 | + }} |
| 34 | + > |
| 35 | + > |
| 36 | + </button> |
| 37 | + </div> |
| 38 | + <div className="grid w-full grid-cols-7 gap-4"> |
| 39 | + {dayNames.map((dayName, i) => ( |
| 40 | + <span key={i} className="text-center"> |
| 41 | + {dayName} |
| 42 | + </span> |
| 43 | + ))} |
| 44 | + </div> |
| 45 | + <div className="grid w-full grid-cols-7 gap-4"> |
| 46 | + {times(months[currentDate.getMonth()][1], (i) => ( |
| 47 | + <DayCard key={i} date={i + 1} /> |
| 48 | + ))} |
| 49 | + </div> |
| 50 | + </div> |
| 51 | + </section> |
| 52 | + </main> |
| 53 | + ); |
| 54 | +} |
0 commit comments