From 9c3e2fad64b26f1c251ed5144753e9df13f3f573 Mon Sep 17 00:00:00 2001 From: Antoine Phan Date: Tue, 8 Jul 2025 17:47:54 -0400 Subject: [PATCH] Checkpoint for implementing OH Schedule --- src/components/OHBlock.svelte | 9 +++++++ src/components/OHSchedule.svelte | 36 +++++++++++++++++++++++++++ src/lib/schemas.ts | 42 ++++++++++++++++++++++++++++++++ src/lib/types.js | 25 ------------------- src/routes/+page.server.js | 39 ----------------------------- src/routes/+page.server.ts | 34 ++++++++++++++++++++++++++ src/routes/+page.svelte | 3 ++- 7 files changed, 123 insertions(+), 65 deletions(-) create mode 100644 src/lib/schemas.ts delete mode 100644 src/lib/types.js delete mode 100644 src/routes/+page.server.js create mode 100644 src/routes/+page.server.ts diff --git a/src/components/OHBlock.svelte b/src/components/OHBlock.svelte index e69de29..8e611c3 100644 --- a/src/components/OHBlock.svelte +++ b/src/components/OHBlock.svelte @@ -0,0 +1,9 @@ + + +
+

{member}

+
+

{startTime} - {endTime}

+
\ No newline at end of file diff --git a/src/components/OHSchedule.svelte b/src/components/OHSchedule.svelte index e69de29..848448d 100644 --- a/src/components/OHSchedule.svelte +++ b/src/components/OHSchedule.svelte @@ -0,0 +1,36 @@ + + +
+ {#each daysOfTheWeek as DOTW} +
+ {DOTW} + {#each sortedOHs.filter((OH) => OH.day == DOTW) as OH} + + {/each} +
+ {/each} +
diff --git a/src/lib/schemas.ts b/src/lib/schemas.ts new file mode 100644 index 0000000..8cbb55e --- /dev/null +++ b/src/lib/schemas.ts @@ -0,0 +1,42 @@ +export interface EventPost { + id: string; + title: string; + description: string; + date: string; + time: string; + location: string; + image: string; + link: string; + category: string; + payment: string; // event payment link (e.g., Zeffy) +} + +export interface CouncilMember { + role: string; + name: string; + email: string; + image: string; + major: string; + year: string; +} + +import type { InputValue } from '@portabletext/svelte'; + +export type HomepageCMSResponse = { + description: InputValue; + councilPhoto: string; + faqs: { + question: string; + answer: string; + }[]; +}; + +export type OhCMSResponse = { + day: string; + startTime: string; + endTime: string; + host: { + name: string; + position: string; + }; +}[]; diff --git a/src/lib/types.js b/src/lib/types.js deleted file mode 100644 index 9f18f20..0000000 --- a/src/lib/types.js +++ /dev/null @@ -1,25 +0,0 @@ -/** - * @typedef {Object} EventPost event object - * @property {string} id - event id - * @property {string} title - event title - * @property {string} description - event description - * @property {string} date - event date - * @property {string} time - event time - * @property {string} location - event location - * @property {string} image - event image - * @property {string} link - event link - * @property {string} category - event category - * @property {string} payment - event payment link (e.g., Zeffy)3 - */ - -/** - * @typedef {Object} CouncilMember - * @property {string} role - * @property {string} name - * @property {string} email - * @property {string} image - * @property {string} major - * @property {string} year - */ - -export {}; diff --git a/src/routes/+page.server.js b/src/routes/+page.server.js deleted file mode 100644 index 97378eb..0000000 --- a/src/routes/+page.server.js +++ /dev/null @@ -1,39 +0,0 @@ -import { getFromCMS } from 'utils/utils.js'; - -const homepageQuery = `*[_type == "homepage"]{ - "description": description[], - "councilPhoto": councilPhoto.asset->url, - "faqs": faqs[]{ question, answer }, -}[0]`; - -const ohQuery = `*[_type=="oh"].schedule[]{ - day, - startTime, - endTime, - "host": member->name -}`; - -export const load = async () => { - /** - * @description Response data type based on the `homepageQuery` above. - * Note that `description` is a rich/portable text type - * - * @type {{ - * description: import('@portabletext/svelte').InputValue, - * councilPhoto: string, - * faqs: [{ - * question: string, - * answer: string - * }], - * }} - * - */ - let CMSresponse = await getFromCMS(homepageQuery); - - return { - description: CMSresponse.description, - councilPhoto: CMSresponse.councilPhoto, - faqs: CMSresponse.faqs - // ohs: await getFromCMS(ohQuery), - }; -}; diff --git a/src/routes/+page.server.ts b/src/routes/+page.server.ts new file mode 100644 index 0000000..b06f9da --- /dev/null +++ b/src/routes/+page.server.ts @@ -0,0 +1,34 @@ +import { getFromCMS } from 'utils/utils.js'; +import type { HomepageCMSResponse, OhCMSResponse } from '$lib/schemas'; + +const homepageQuery = `*[_type == "homepage"]{ + "description": description[], + "councilPhoto": councilPhoto.asset->url, + "faqs": faqs[]{ question, answer }, +}[0]`; + +const ohQuery = `*[_type=="officeHours"]{ + day, + startTime, + endTime, + "host": { + "name": member->name, + "position": member->position + } +}`; + +export const load = async () => { + /** + * @description Response data type based on the `homepageQuery` above. + * Note that `description` is a rich/portable text type + */ + let homepageResp: HomepageCMSResponse = await getFromCMS(homepageQuery); + let officeHourResp: OhCMSResponse = await getFromCMS(ohQuery); + + return { + description: homepageResp.description, + councilPhoto: homepageResp.councilPhoto, + faqs: homepageResp.faqs, + allOHs: officeHourResp + }; +}; diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index e2c54cf..a556e49 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -2,6 +2,7 @@ import FaqAccordion from 'components/FAQAccordion.svelte'; import Section from 'components/Section.svelte'; import { PortableText } from '@portabletext/svelte'; + import OhSchedule from 'components/OHSchedule.svelte'; /** loading things from the server side */ let { data } = $props(); @@ -34,6 +35,6 @@

Office Hours

-

Under development

+