Skip to content

Commit

Permalink
dashboard (?)
Browse files Browse the repository at this point in the history
  • Loading branch information
c0repwn3r committed Nov 9, 2024
1 parent 114b257 commit 996f62c
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scheddy",
"version": "0.0.7",
"version": "0.0.8",
"type": "module",
"scripts": {
"dev": "vite dev",
Expand Down
43 changes: 43 additions & 0 deletions src/routes/(authed)/dash/cal/+page.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { loadUserData } from '$lib/userInfo';
import { roleOf } from '$lib';
import { ROLE_STAFF } from '$lib/utils';
import { redirect } from '@sveltejs/kit';
import { db } from '$lib/server/db';
import { mentors, sessions, sessionTypes, students, users } from '$lib/server/db/schema';
import { eq } from 'drizzle-orm';
import type { PageServerLoad } from './$types';
import type { MentorAvailability } from '$lib/availability';
import { DateTime } from 'luxon';

export const load: PageServerLoad = async ({ cookies, params }) => {
const { user } = (await loadUserData(cookies))!;
if (roleOf(user) < ROLE_STAFF) {
redirect(307, '/schedule');
}

const validTypes = await db.select().from(sessionTypes);

const typesMap: Record<string, string> = {};
for (const typ of validTypes) {
typesMap[typ.id] = typ.name;
}

const allSessions = await db
.select()
.from(sessions)
.leftJoin(students, eq(students.id, sessions.student))
.leftJoin(mentors, eq(mentors.id, sessions.mentor))

const mentorSessions = [];
const now = DateTime.utc();
for (const sess of allSessions) {
const start = DateTime.fromISO(sess.session.start);
if (start < now) continue;
mentorSessions.push(sess);
}

return {
user,
mentorSessions
};
};
52 changes: 52 additions & 0 deletions src/routes/(authed)/dash/cal/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<script lang="ts">
import type { PageData } from "./$types";
import { DateTime } from 'luxon';
import TableRoot from '$lib/ui/table/TableRoot.svelte';
import TableHead from '$lib/ui/table/TableHead.svelte';
import TableHeadColumn from '$lib/ui/table/TableHeadColumn.svelte';
import TableBody from '$lib/ui/table/TableBody.svelte';
import TableRow from '$lib/ui/table/TableRow.svelte';
import TableColumn from '$lib/ui/table/TableColumn.svelte';
import Button from '$lib/ui/Button.svelte';
import { PencilIcon } from 'lucide-svelte';
interface Props {
data: PageData
}
let { data }: Props = $props();
</script>

<div class="relative overflow-x-auto shadow-md rounded mt-2">
<TableRoot>
<TableHead>
<TableHeadColumn>Date</TableHeadColumn>
<TableHeadColumn>Session Type</TableHeadColumn>
<TableHeadColumn>Student</TableHeadColumn>
<TableHeadColumn>Mentor</TableHeadColumn>
<TableHeadColumn>
<div class="flex flex-row align-middle justify-between items-center">
<span>Actions</span>
</div>
</TableHeadColumn>
</TableHead>
<TableBody>
{#each data.mentorSessions as sess}
<TableRow>
<TableColumn
>{DateTime.fromISO(sess.session.start)
.setZone(data.mentor.timezone)
.toLocaleString(DateTime.DATETIME_MED_WITH_WEEKDAY)}</TableColumn
>
<TableColumn>{data.typesMap[sess.session.type]}</TableColumn>
<TableColumn>{sess.student.firstName} {sess.student.lastName}</TableColumn>
<TableColumn>{sess.mentor.firstName} {sess.mentor.lastName}</TableColumn>
<TableColumn>
<Button size="icon" href="/dash/sessions/{sess.session.id}">
<PencilIcon class="w-4 h-4" />
</Button>
</TableColumn>
</TableRow>
{/each}
</TableBody>
</TableRoot>
</div>

0 comments on commit 996f62c

Please sign in to comment.