Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Properly fix it this time
  • Loading branch information
regalijan committed Nov 5, 2024
1 parent cbe2913 commit fa288b6
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions app/routes/events-calendar.tsx
Expand Up @@ -14,6 +14,7 @@ import {
} from "@chakra-ui/react";
import { useLoaderData } from "@remix-run/react";
import { useState } from "react";
import utc from "dayjs/plugin/utc.js";

export const links: LinksFunction = () => {
return [
Expand Down Expand Up @@ -55,8 +56,8 @@ export async function loader({ context }: { context: RequestContext }) {
title: (e.type as string).toUpperCase(),
allDay: true,
// A Date object will not survive being passed to the client
start: `${e.year}-${e.month}-${e.day}T00:00:00.000Z`,
end: `${e.year}-${e.month}-${e.day}T00:00:00.000Z`,
start: `${e.year}-${(e.month as number).toString().padStart(2, "0")}-${(e.day as number).toString().padStart(2, "0")}T00:00:00.000Z`,
end: `${e.year}-${(e.month as number).toString().padStart(2, "0")}-${(e.day as number).toString().padStart(2, "0")}T00:00:00.000Z`,
};
});

Expand All @@ -79,22 +80,31 @@ export default function () {
) as { [k: string]: any }[];
};

dayjs.extend(utc);

return (
<Container maxW="container.lg" h="600px">
<Calendar
events={data?.calendarData.map((event) => {
// @ts-expect-error
event.end = new Date(event.end);
// @ts-expect-error
event.start = new Date(event.start);

return event;
})}
endAccessor={(event) => new Date(event.end)}
events={data.calendarData}
localizer={dayjsLocalizer(dayjs)}
onSelectSlot={(s) => {
setDate(s.slots.at(0) as Date);
}}
startAccessor={(event) => {
const date = new Date(event.start);
date.setUTCDate(date.getUTCDate() + 1);

return date;
}}
style={{ height: 500 }}
views={{
month: true,
week: false,
work_week: false,
day: false,
agenda: false,
}}
/>
<Accordion id="events-accordion" mt="16px">
<AccordionItem>
Expand Down

0 comments on commit fa288b6

Please sign in to comment.