diff --git a/src/components/OHBlock.svelte b/src/components/OHBlock.svelte deleted file mode 100644 index e69de29..0000000 diff --git a/src/components/OHSchedule.svelte b/src/components/OHSchedule.svelte index e69de29..fa451b0 100644 --- a/src/components/OHSchedule.svelte +++ b/src/components/OHSchedule.svelte @@ -0,0 +1,42 @@ + + +
+ {#each ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'] as day} +
+

- {day} -

+ {#each sortedOHs.filter((OH) => OH.day == day) as OH} +
+

{OH.startTime} - {OH.endTime}

+

{OH.member.name.split(" ")[0]}

+

{OH.member.position}

+
+ {/each} +
+ {/each} +
diff --git a/src/lib/schemas.ts b/src/lib/schemas.ts new file mode 100644 index 0000000..605e69a --- /dev/null +++ b/src/lib/schemas.ts @@ -0,0 +1,44 @@ +export type 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) +}; + +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; + member: { + name: string; + position: string; + }; +}[]; + +export type CouncilMember = { + name: string; + email: string; + position: string; + positionDescription: string; + image: string; // URL + yearProgram: string; +}; + +export type Redirect = { shortname: string; url: 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/utils/utils.js b/src/lib/utils.js similarity index 100% rename from src/utils/utils.js rename to src/lib/utils.js 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..e7f4a6d --- /dev/null +++ b/src/routes/+page.server.ts @@ -0,0 +1,34 @@ +import { getFromCMS } from '$lib/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, + "member": { + "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 c50fd77..5edaa75 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(); @@ -46,6 +47,6 @@

Office Hours

-

Under development

+
diff --git a/src/routes/council/+page.server.js b/src/routes/council/+page.server.ts similarity index 89% rename from src/routes/council/+page.server.js rename to src/routes/council/+page.server.ts index c9fce06..d4a5936 100644 --- a/src/routes/council/+page.server.js +++ b/src/routes/council/+page.server.ts @@ -1,4 +1,4 @@ -import { getFromCMS } from 'utils/utils.js'; +import { getFromCMS } from '$lib/utils.js'; const query = `*[_type == "members"]{ name, diff --git a/src/routes/council/+page.svelte b/src/routes/council/+page.svelte index 069abec..6cf1964 100644 --- a/src/routes/council/+page.svelte +++ b/src/routes/council/+page.svelte @@ -34,7 +34,7 @@ selectedMember = member; } - console.log(ureps) + console.log(ureps); // svelte-ignore state_referenced_locally // console.log(selectedMember); diff --git a/src/routes/events/+page.server.ts b/src/routes/events/+page.server.ts index d73c5bb..4cf80bb 100644 --- a/src/routes/events/+page.server.ts +++ b/src/routes/events/+page.server.ts @@ -1,4 +1,4 @@ -import { getFromCMS } from 'utils/utils.js'; +import { getFromCMS } from '$lib/utils.js'; // needs to concat and format this text const eventQuery = `*[_type == "events"]{ diff --git a/src/routes/r/[shortname]/+page.server.js b/src/routes/r/[shortname]/+page.server.js deleted file mode 100644 index 68be477..0000000 --- a/src/routes/r/[shortname]/+page.server.js +++ /dev/null @@ -1,23 +0,0 @@ -import { redirect } from '@sveltejs/kit'; -import { getFromCMS } from 'utils/utils.js'; - -const redirectQuery = `*[_type == "redirects"]{ shortname, url }`; - -export const load = async ({ params }) => { - /** @type {[{shortname: String, url: String}]} */ - let CMSresponse = await getFromCMS(redirectQuery); - - const { shortname } = params; - - CMSresponse.forEach(res => { - if(res.shortname == shortname) { - // if match - throw redirect(302, res.url); - } - }); - - return { - shortname: shortname, - availableShortnames: CMSresponse, - } -}; diff --git a/src/routes/r/[shortname]/+page.server.ts b/src/routes/r/[shortname]/+page.server.ts new file mode 100644 index 0000000..9620ed5 --- /dev/null +++ b/src/routes/r/[shortname]/+page.server.ts @@ -0,0 +1,23 @@ +import { redirect } from '@sveltejs/kit'; +import { getFromCMS } from '$lib/utils.js'; +import type { Redirect } from '$lib/schemas'; + +const redirectQuery = `*[_type == "redirects"]{ shortname, url }`; + +export const load = async ({ params }) => { + let CMSresponse: Redirect[] = await getFromCMS(redirectQuery); + + const { shortname } = params; + + CMSresponse.forEach((res) => { + if (res.shortname == shortname) { + // if match + throw redirect(302, res.url); + } + }); + + return { + shortname: shortname, + availableShortnames: CMSresponse + }; +}; diff --git a/src/routes/resources/+page.server.js b/src/routes/resources/+page.server.js index e983751..3d1dfea 100644 --- a/src/routes/resources/+page.server.js +++ b/src/routes/resources/+page.server.js @@ -1,4 +1,4 @@ -import { getFromCMS } from 'utils/utils.js'; +import { getFromCMS } from '$lib/utils.js'; // needs to concat and format this text const query = `*[_type == "resources"]{ diff --git a/src/utils/schemas.ts b/src/utils/schemas.ts deleted file mode 100644 index 592f756..0000000 --- a/src/utils/schemas.ts +++ /dev/null @@ -1,8 +0,0 @@ -export default interface CouncilMember { - name: string; - email: string; - position: string; - positionDescription: string; - image: string; // URL - yearProgram: string; -}