Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Hopefully make accordion update
  • Loading branch information
regalijan committed Nov 8, 2024
1 parent 231ae73 commit cbb26f4
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions app/routes/events-calendar.tsx
Expand Up @@ -70,15 +70,14 @@ export async function loader({ context }: { context: RequestContext }) {
export default function () {
const data = useLoaderData<typeof loader>();
const [selectedDate, setDate] = useState(new Date());

const eventsOfDay = () => {
return data.eventList.filter(
const getEventsOfDay = (date: Date) =>
data.eventList.filter(
(e) =>
e.day === selectedDate.getUTCDate() &&
e.month === selectedDate.getUTCMonth() + 1 &&
e.year === selectedDate.getUTCFullYear(),
e.day === date.getUTCDate() &&
e.month === date.getUTCMonth() + 1 &&
e.year === date.getUTCFullYear(),
) as { [k: string]: any }[];
};
const [eventsOfDay, setEventsOfDay] = useState(getEventsOfDay(selectedDate));

dayjs.extend(utc);

Expand All @@ -89,15 +88,12 @@ export default function () {
events={data.calendarData}
localizer={dayjsLocalizer(dayjs)}
onSelectSlot={(s) => {
setDate(s.slots.at(0) as Date);
const date = s.slots.at(0) as Date;
setDate(date);
setEventsOfDay(getEventsOfDay(date));
}}
popup
startAccessor={(event) => {
const date = new Date(event.start);
date.setUTCDate(date.getUTCDate() + 1);

return date;
}}
startAccessor={(event) => new Date(event.start)}
style={{ height: 500 }}
views={{
month: true,
Expand All @@ -118,7 +114,7 @@ export default function () {
</AccordionButton>
</h2>
<AccordionPanel pb={4}>
{eventsOfDay().find((e) => e.type === "fotd")?.details || "None"}
{eventsOfDay.find((e) => e.type === "fotd")?.details || "None"}
<br />
</AccordionPanel>
</AccordionItem>
Expand All @@ -132,8 +128,7 @@ export default function () {
</AccordionButton>
</h2>
<AccordionPanel pb={4}>
{eventsOfDay().find((e) => e.type === "gamenight")?.details ||
"None"}
{eventsOfDay.find((e) => e.type === "gamenight")?.details || "None"}
</AccordionPanel>
</AccordionItem>
<AccordionItem>
Expand All @@ -145,7 +140,7 @@ export default function () {
</AccordionButton>
</h2>
<AccordionPanel pb={4}>
{eventsOfDay().find((e) => e.type === "rotw")?.details || "None"}
{eventsOfDay.find((e) => e.type === "rotw")?.details || "None"}
</AccordionPanel>
</AccordionItem>
<AccordionItem>
Expand All @@ -157,7 +152,7 @@ export default function () {
</AccordionButton>
</h2>
<AccordionPanel pb={4}>
{eventsOfDay().find((e) => e.type === "qotd")?.details || "None"}
{eventsOfDay.find((e) => e.type === "qotd")?.details || "None"}
</AccordionPanel>
</AccordionItem>
</Accordion>
Expand Down

0 comments on commit cbb26f4

Please sign in to comment.