Skip to content

Commit

Permalink
view homework by name
Browse files Browse the repository at this point in the history
  • Loading branch information
NOOBDY committed Nov 4, 2024
1 parent 82c3816 commit 5739242
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 6 deletions.
4 changes: 2 additions & 2 deletions web/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
<Table.Row>
<Table.Cell>
<a
href={`/${data.data.semester}/${i.student_id}`}
href={`/student/${data.data.semester}/${i.student_id}`}
class="text-primary underline hover:text-primary/70"
>
{i.student_id}
</a>
</Table.Cell>
<Table.Cell>{i.grade}</Table.Cell>
<Table.Cell>{i.grade ?? 'Not submitted'}</Table.Cell>
</Table.Row>
{/each}
</Table.Body>
Expand Down
2 changes: 1 addition & 1 deletion web/src/routes/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { PageLoad } from './$types';

type GradeInfo = {
student_id: string;
grade: number;
grade: number | null;
};

type LatestData = {
Expand Down
39 changes: 39 additions & 0 deletions web/src/routes/homework/[semester]/[homework_name]/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<script lang="ts">
import type { PageData } from './$types';
import * as Table from '$lib/components/ui/table';
let { data }: { data: PageData } = $props();
</script>

<h1 class="scroll-m-20 text-4xl font-bold tracking-tight lg:text-5xl">
{data.data.semester.toUpperCase()}
{data.data.name}
</h1>

<div class="my-6 w-full">
<Table.Root>
<Table.Header>
<Table.Row>
<Table.Head>Student ID</Table.Head>
<Table.Head>Grade</Table.Head>
</Table.Row>
</Table.Header>

<Table.Body>
{#each data.data.info as i}
<Table.Row>
<Table.Cell>
<a
href={`/student/${data.data.semester}/${i.student_id}`}
class="text-primary underline hover:text-primary/70"
>
{i.student_id}
</a>
</Table.Cell>
<Table.Cell>{i.grade ?? 'Not submitted'}</Table.Cell>
</Table.Row>
{/each}
</Table.Body>
</Table.Root>
</div>
24 changes: 24 additions & 0 deletions web/src/routes/homework/[semester]/[homework_name]/+page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { error } from '@sveltejs/kit';
import type { PageLoad } from './$types';

type GradeInfo = {
student_id: string;
grade: number | null;
};

export const load: PageLoad = async ({ params, fetch }) => {
const res = await fetch(`/api/grade/${params.semester}/${params.homework_name}`);
if (!res.ok) {
error(res.status, await res.json());
}

const info: GradeInfo[] = await res.json();

return {
data: {
semester: params.semester,
name: params.homework_name,
info
}
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@
<Table.Body>
{#each data.data.info as i}
<Table.Row>
<Table.Cell>{i.name}</Table.Cell>
<Table.Cell>{i.grade}</Table.Cell>
<Table.Cell>
<a
href={`/homework/${data.data.semester}/${i.name}`}
class="text-primary underline hover:text-primary/70"
>
{i.name}
</a>
</Table.Cell>
<Table.Cell>{i.grade ?? 'Not submitted'}</Table.Cell>
</Table.Row>
{/each}
</Table.Body>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { error } from '@sveltejs/kit';
import type { PageLoad } from './$types';

type GradeInfo = {
name: string;
grade: number;
grade: number | null;
};

export const load: PageLoad = async ({ params, fetch }) => {
const res = await fetch(`/api/student/${params.semester}/${params.student_id}`);
if (!res.ok) {
error(res.status, await res.json());
}

const info: GradeInfo[] = await res.json();

return {
Expand Down

0 comments on commit 5739242

Please sign in to comment.