This repository has been archived by the owner on Aug 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
253 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { allAssessments, allHomework } from 'contentlayer/generated' | ||
import { notFound } from 'next/navigation' | ||
import { useMDXComponent } from 'next-contentlayer/hooks' | ||
import { mdxComponents } from '@/components/mdx' | ||
import { Card } from '@/components/Card' | ||
import { Prose } from '@/components/Prose' | ||
import { MenuItemActivator } from '@/app/menu' | ||
|
||
export async function generateStaticParams() { | ||
return allAssessments.map(page => ({ | ||
slug: page.slug, | ||
})).filter(slug => slug) | ||
} | ||
|
||
export default function Assessment({ params }: { params: { slug: string } }) { | ||
const page = allAssessments.find(page => page.slug === params.slug) | ||
if (!page) notFound() | ||
|
||
const MDXContent = useMDXComponent(page.body.code) | ||
const content = <MDXContent components={mdxComponents} /> | ||
|
||
return <Card title={<h1>{page.title}</h1>}> | ||
<Prose> | ||
{content} | ||
</Prose> | ||
</Card> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { allHomework } from 'contentlayer/generated' | ||
import { notFound } from 'next/navigation' | ||
import { useMDXComponent } from 'next-contentlayer/hooks' | ||
import { mdxComponents } from '@/components/mdx' | ||
import { Card } from '@/components/Card' | ||
import { Prose } from '@/components/Prose' | ||
import { MenuItemActivator } from '@/app/menu' | ||
|
||
export async function generateStaticParams() { | ||
return allHomework.map(page => ({ | ||
slug: page.slug, | ||
})).filter(slug => slug) | ||
} | ||
|
||
export default function Homework({ params }: { params: { slug: string } }) { | ||
const page = allHomework.find(page => page.slug === params.slug) | ||
if (!page) notFound() | ||
|
||
const MDXContent = useMDXComponent(page.body.code) | ||
const content = <MDXContent components={mdxComponents} /> | ||
|
||
return <Card title={<h1>{page.title}</h1>}> | ||
<Prose> | ||
{content} | ||
</Prose> | ||
</Card> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { ReactNode } from "react" | ||
import { MenuItemActivator } from "../menu" | ||
|
||
export default function RootLayout({ children }: { children: ReactNode }) { | ||
return <> | ||
<MenuItemActivator item="assignments" /> | ||
{children} | ||
</> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import { allHomework, allAssessments } from 'contentlayer/generated' | ||
import { Card } from '@/components/Card' | ||
import { MenuItemActivator } from '@/app/menu' | ||
import Link from 'next/link' | ||
import { format } from 'date-fns' | ||
|
||
type Assignment = { | ||
title: string | ||
href: string | ||
isReleased: boolean | ||
releaseDate?: Date | ||
dates: { | ||
name: string | ||
date: Date | ||
specifyTime: boolean | ||
}[] | ||
sortDate: Date | ||
} | ||
|
||
export const formattedHomework: Assignment[] = allHomework.map(hw => { | ||
const due = new Date(hw.dueDate) | ||
|
||
return { | ||
title: hw.title, | ||
href: `/assignments/hw/${hw.slug}`, | ||
isReleased: hw.isReleased, | ||
releaseDate: hw.releaseDate && new Date(hw.releaseDate), | ||
dates: [ | ||
...(hw.auxiliaryDates ?? []).map(aux => ({ | ||
name: aux.name, | ||
date: new Date(aux.date), | ||
specifyTime: true, | ||
})), | ||
{ | ||
name: "Due", | ||
date: due, | ||
specifyTime: true, | ||
} | ||
], | ||
sortDate: new Date(hw.dueDate), | ||
} | ||
}) | ||
|
||
export const formattedAssessments = allAssessments.map(a => { | ||
const date = new Date(a.assessmentDate) | ||
|
||
return { | ||
title: a.title, | ||
href: `/assignments/assessment/${a.slug}`, | ||
isReleased: a.isReleased, | ||
releaseDate: a.releaseDate && new Date(a.releaseDate), | ||
dates: [ | ||
{ | ||
name: "Scheduled", | ||
date, | ||
specifyTime: true, | ||
} | ||
], | ||
sortDate: date, | ||
} | ||
}) | ||
|
||
function AssignmentRow({ title, href, isReleased, releaseDate, dates }: Assignment) { | ||
let className = "border-b border-neutral-300 dark:border-neutral-600 py-2 last:pb-0 last:border-0 block lg:table-row w-full" | ||
if (!isReleased) { | ||
className += " opacity-50" | ||
} | ||
|
||
return <tr className={className}> | ||
<td className="lg:py-2 w-full block lg:table-cell"> | ||
{isReleased ? | ||
<Link href={href} className="link font-bold">{title}</Link> : | ||
<span className="italic">{title}{releaseDate && <> (available <strong>{format(releaseDate, "M/d")}</strong>)</>}</span>} | ||
</td> | ||
<td className="lg:py-2 block lg:table-cell"> | ||
{dates.map((item, index) => <div key={index}> | ||
{item.name} <strong>{format(item.date, item.specifyTime ? "E, M/d @ h:mmaa" : "E, M/d")}</strong> | ||
</div>)} | ||
</td> | ||
</tr> | ||
} | ||
|
||
export function AssignmentTable({ assignments: raw }: { assignments: Assignment[] }) { | ||
const data = raw.toSorted((a, b) => a.sortDate.getTime() - b.sortDate.getTime()) | ||
|
||
return <table className="block lg:table w-full"> | ||
<thead> | ||
<tr className="border-b-4 border-neutral-300 dark:border-neutral-600 sr-only lg:not-sr-only"> | ||
<th className="text-left pb-2 w-full">Name</th> | ||
<th className="text-left pb-2 lg:min-w-64">Date</th> | ||
</tr> | ||
</thead> | ||
<tbody className="block lg:table-row-group"> | ||
{data.map(assignment => <AssignmentRow {...assignment} key={assignment.href} />)} | ||
</tbody> | ||
</table> | ||
} | ||
|
||
export default function Assignments() { | ||
if (!allHomework.length && !allAssessments.length) { | ||
return <Card> | ||
There are currently no assignments for this class. | ||
</Card> | ||
} | ||
|
||
return <div> | ||
<div className="mb-4">Here you'll find all assignments for this class.</div> | ||
{allHomework.length > 0 && <Card title={<h2>Homework</h2>} margin={allAssessments.length > 0}> | ||
<AssignmentTable assignments={formattedHomework} /> | ||
</Card>} | ||
{allAssessments.length > 0 && <Card title={<h2>Assessments</h2>}> | ||
<AssignmentTable assignments={formattedAssessments} /> | ||
</Card>} | ||
</div> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { formattedAssessments, formattedHomework, AssignmentTable } from "@/app/assignments/page" | ||
|
||
const threshold = 5 * 7 * 24 * 60 * 60 * 1000 // 3 weeks | ||
const thresholdText = "3 weeks" | ||
|
||
const upcoming = [...formattedHomework, ...formattedAssessments].filter(({ sortDate }) => { | ||
const remainingTime = sortDate.getTime() - new Date().getTime() | ||
return remainingTime >= 0 && remainingTime <= threshold | ||
}) | ||
|
||
export function UpcomingAssignments() { | ||
if (!upcoming.length) return <div> | ||
There are no upcoming assignments in the next {thresholdText}. | ||
</div> | ||
|
||
return <> | ||
<div className="mb-4">There are {upcoming.length} {upcoming.length === 1 ? "assignment" : "assignments"} in the next {thresholdText}:</div> | ||
<AssignmentTable assignments={upcoming} /> | ||
</> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
title: HW0 - Xcode Setup | ||
isReleased: true | ||
dueDate: 2024-01-22T23:59:00 | ||
--- | ||
|
||
Just send us a screenshot of Xcode working |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
title: HW1 - Basic Swift | ||
isReleased: false | ||
dueDate: 2024-01-23T23:59:00 | ||
releaseDate: 2024-01-24T23:59:00 | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters