Office Hour block, codebase clean up for schemas and utils

This commit is contained in:
Antoine Phan
2025-07-19 12:32:47 -04:00
parent fe3495227d
commit e0a4aa1fa8
11 changed files with 57 additions and 67 deletions

View File

@@ -1,10 +0,0 @@
<script lang="ts">
let { member, startTime, endTime } = $props();
</script>
<div class="card w-full bg-ecsess-200 text-ecsess-black max-w-md p-4 m-4 text-center rounded-xl">
<p>{member.name}</p>
<p>{member.position}</p>
<hr>
<p>{startTime} - {endTime}</p>
</div>

View File

@@ -1,10 +1,9 @@
<script lang="ts"> <script lang="ts">
import OhBlock from './OHBlock.svelte';
import type { OhCMSResponse } from '$lib/schemas'; import type { OhCMSResponse } from '$lib/schemas';
function parseTime(timeStr: string) { function parseTime(timeStr: string): number {
let a = timeStr.match(/^(\d{1,2})(?::(\d{2}))?(AM|PM)$/i); let a = timeStr.match(/^(\d{1,2})(?::(\d{2}))?(AM|PM)$/i);
if (!a) return; if (!a) return 0;
let hours = parseInt(a[1], 10); let hours = parseInt(a[1], 10);
let minutes = parseInt(a[2] || '0', 10); let minutes = parseInt(a[2] || '0', 10);
@@ -13,7 +12,7 @@
if (period.toUpperCase() === 'PM' && hours !== 12) hours += 12; if (period.toUpperCase() === 'PM' && hours !== 12) hours += 12;
if (period.toUpperCase() === 'AM' && hours === 12) hours = 0; if (period.toUpperCase() === 'AM' && hours === 12) hours = 0;
return hours * 60 + minutes; // total minutes since midnight return Number(hours * 60 + minutes); // total minutes since midnight
} }
let { allOhs }: { allOhs: OhCMSResponse } = $props(); let { allOhs }: { allOhs: OhCMSResponse } = $props();
let sortedOHs = $state( let sortedOHs = $state(
@@ -21,15 +20,22 @@
return parseTime(a.startTime) - parseTime(b.startTime); return parseTime(a.startTime) - parseTime(b.startTime);
}) })
); );
const daysOfTheWeek = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'];
</script> </script>
<div class="grid grid-cols-5 gap-8"> <div class="grid min-w-2/3 grid-cols-5 gap-2 place-self-center">
{#each daysOfTheWeek as DOTW} {#each ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'] as day}
<div> <div>
{DOTW} <p>- {day} -</p>
{#each sortedOHs.filter((OH) => OH.day == DOTW) as OH} {#each sortedOHs.filter((OH) => OH.day == day) as OH}
<OhBlock member={OH.member} startTime={OH.startTime} endTime={OH.endTime}></OhBlock> <div
class="
card w-64 grid h-38 grid-rows-[3fr_2fr_3fr] bg-ecsess-200 text-ecsess-black m-3 place-content-center rounded-xl
p-4 text-center"
>
<p class="text-lg">{OH.startTime} - {OH.endTime}</p>
<p class="text-2xl">{OH.member.name.split(" ")[0]}</p>
<p class="text-sm italic">{OH.member.position}</p>
</div>
{/each} {/each}
</div> </div>
{/each} {/each}

View File

@@ -1,4 +1,4 @@
export interface EventPost { export type EventPost = {
id: string; id: string;
title: string; title: string;
description: string; description: string;
@@ -9,16 +9,7 @@ export interface EventPost {
link: string; link: string;
category: string; category: string;
payment: string; // event payment link (e.g., Zeffy) 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'; import type { InputValue } from '@portabletext/svelte';
@@ -35,8 +26,19 @@ export type OhCMSResponse = {
day: string; day: string;
startTime: string; startTime: string;
endTime: string; endTime: string;
host: { member: {
name: string; name: string;
position: 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 };

View File

@@ -1,4 +1,4 @@
import { getFromCMS } from 'utils/utils.js'; import { getFromCMS } from '$lib/utils.js';
import type { HomepageCMSResponse, OhCMSResponse } from '$lib/schemas'; import type { HomepageCMSResponse, OhCMSResponse } from '$lib/schemas';
const homepageQuery = `*[_type == "homepage"]{ const homepageQuery = `*[_type == "homepage"]{

View File

@@ -1,4 +1,4 @@
import { getFromCMS } from 'utils/utils.js'; import { getFromCMS } from '$lib/utils.js';
const query = `*[_type == "members"]{ const query = `*[_type == "members"]{
name, name,

View File

@@ -1,4 +1,4 @@
import { getFromCMS } from 'utils/utils.js'; import { getFromCMS } from '$lib/utils.js';
// needs to concat and format this text // needs to concat and format this text
const eventQuery = `*[_type == "events"]{ const eventQuery = `*[_type == "events"]{

View File

@@ -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,
}
};

View File

@@ -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
};
};

View File

@@ -1,4 +1,4 @@
import { getFromCMS } from 'utils/utils.js'; import { getFromCMS } from '$lib/utils.js';
// needs to concat and format this text // needs to concat and format this text
const query = `*[_type == "resources"]{ const query = `*[_type == "resources"]{

View File

@@ -1,8 +0,0 @@
export default interface CouncilMember {
name: string;
email: string;
position: string;
positionDescription: string;
image: string; // URL
yearProgram: string;
}