-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Useable Events / Schedule Page (#106)
* update: created getSchedule file * update: synced sanity data with schedule component * feat: update event schema * feat: group events by day * feat: format date ranges * fix: group events by America/Los_Angeles day * fix: event order asc * fix: remove resources from nav --------- Co-authored-by: Tyler Yu <tyleryy@uci.edu>
- Loading branch information
1 parent
d1e4446
commit 3f0fc0e
Showing
9 changed files
with
164 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import dayjs from "dayjs"; | ||
import utc from "dayjs/plugin/utc"; | ||
import timezone from "dayjs/plugin/timezone"; | ||
|
||
dayjs.extend(utc); | ||
dayjs.extend(timezone); | ||
|
||
export default dayjs; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
import ClipboardSchedule from "./sections/ClipboardSchedule/ClipboardSchedule"; | ||
import { getSchedule } from "./getSchedule"; | ||
import { PortableText } from "@portabletext/react"; | ||
|
||
import styles from "./Schedule.module.scss"; | ||
|
||
export default function Schedule() { | ||
export default async function Schedule() { | ||
const days = await getSchedule(); | ||
|
||
const schedule = days.map((events) => | ||
events.map(({ description, ...event }) => ({ | ||
...event, | ||
description: <PortableText value={description} />, | ||
})), | ||
); | ||
|
||
return ( | ||
<div className={styles.schedule}> | ||
<h1>Schedule</h1> | ||
<ClipboardSchedule | ||
schedule={[ | ||
{ | ||
_key: "test", | ||
title: "test", | ||
description: "test", | ||
location: "test", | ||
startDate: new Date(), | ||
endDate: new Date(), | ||
}, | ||
]} | ||
/> | ||
<ClipboardSchedule schedule={schedule} /> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { z } from "zod"; | ||
import { cache } from "react"; | ||
import { client } from "@/lib/sanity/client"; | ||
import { SanityDocument } from "@/lib/sanity/types"; | ||
import dayjs from "@/lib/day"; | ||
|
||
const Events = z.array( | ||
SanityDocument.extend({ | ||
_type: z.literal("event"), | ||
title: z.string(), | ||
location: z.string().optional(), | ||
virtual: z.string().url().optional(), | ||
startTime: z | ||
.string() | ||
.datetime() | ||
.transform((time) => new Date(time)), | ||
endTime: z | ||
.string() | ||
.datetime() | ||
.transform((time) => new Date(time)), | ||
organization: z.string().optional(), | ||
hosts: z.array(z.string()).optional(), | ||
description: z.array( | ||
z.object({ | ||
_key: z.string(), | ||
markDefs: z.array( | ||
z.object({ | ||
_type: z.string(), | ||
href: z.optional(z.string()), | ||
_key: z.string(), | ||
}), | ||
), | ||
children: z.array( | ||
z.object({ | ||
text: z.string(), | ||
_key: z.string(), | ||
_type: z.literal("span"), | ||
marks: z.array(z.string()), | ||
}), | ||
), | ||
_type: z.literal("block"), | ||
style: z.literal("normal"), | ||
}), | ||
), | ||
}), | ||
); | ||
|
||
export const getSchedule = cache(async () => { | ||
const events = Events.parse( | ||
await client.fetch("*[_type == 'event'] | order(startTime asc)"), | ||
); | ||
const eventsByDay = new Map<string, z.infer<typeof Events>>(); | ||
|
||
events.forEach((event) => { | ||
const date = dayjs | ||
.utc(event.startTime) | ||
.tz("America/Los_Angeles") | ||
.format("YYYY-MM-DD"); | ||
|
||
eventsByDay.set(date, [...(eventsByDay.get(date) ?? []), event]); | ||
}); | ||
|
||
return Array.from(eventsByDay.values()); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.