Office Hour block, codebase clean up for schemas and utils
This commit is contained in:
@@ -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>
|
||||
@@ -1,10 +1,9 @@
|
||||
<script lang="ts">
|
||||
import OhBlock from './OHBlock.svelte';
|
||||
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);
|
||||
if (!a) return;
|
||||
if (!a) return 0;
|
||||
|
||||
let hours = parseInt(a[1], 10);
|
||||
let minutes = parseInt(a[2] || '0', 10);
|
||||
@@ -13,7 +12,7 @@
|
||||
if (period.toUpperCase() === 'PM' && hours !== 12) hours += 12;
|
||||
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 sortedOHs = $state(
|
||||
@@ -21,15 +20,22 @@
|
||||
return parseTime(a.startTime) - parseTime(b.startTime);
|
||||
})
|
||||
);
|
||||
const daysOfTheWeek = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'];
|
||||
</script>
|
||||
|
||||
<div class="grid grid-cols-5 gap-8">
|
||||
{#each daysOfTheWeek as DOTW}
|
||||
<div class="grid min-w-2/3 grid-cols-5 gap-2 place-self-center">
|
||||
{#each ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'] as day}
|
||||
<div>
|
||||
{DOTW}
|
||||
{#each sortedOHs.filter((OH) => OH.day == DOTW) as OH}
|
||||
<OhBlock member={OH.member} startTime={OH.startTime} endTime={OH.endTime}></OhBlock>
|
||||
<p>- {day} -</p>
|
||||
{#each sortedOHs.filter((OH) => OH.day == day) as OH}
|
||||
<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}
|
||||
</div>
|
||||
{/each}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export interface EventPost {
|
||||
export type EventPost = {
|
||||
id: string;
|
||||
title: string;
|
||||
description: string;
|
||||
@@ -9,16 +9,7 @@ export interface EventPost {
|
||||
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';
|
||||
|
||||
@@ -35,8 +26,19 @@ export type OhCMSResponse = {
|
||||
day: string;
|
||||
startTime: string;
|
||||
endTime: string;
|
||||
host: {
|
||||
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 };
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getFromCMS } from 'utils/utils.js';
|
||||
import { getFromCMS } from '$lib/utils.js';
|
||||
import type { HomepageCMSResponse, OhCMSResponse } from '$lib/schemas';
|
||||
|
||||
const homepageQuery = `*[_type == "homepage"]{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getFromCMS } from 'utils/utils.js';
|
||||
import { getFromCMS } from '$lib/utils.js';
|
||||
|
||||
const query = `*[_type == "members"]{
|
||||
name,
|
||||
@@ -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"]{
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
};
|
||||
23
src/routes/r/[shortname]/+page.server.ts
Normal file
23
src/routes/r/[shortname]/+page.server.ts
Normal 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
|
||||
};
|
||||
};
|
||||
@@ -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"]{
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
export default interface CouncilMember {
|
||||
name: string;
|
||||
email: string;
|
||||
position: string;
|
||||
positionDescription: string;
|
||||
image: string; // URL
|
||||
yearProgram: string;
|
||||
}
|
||||
Reference in New Issue
Block a user