-
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.
feat: implement frontcover with basic assessment status handling
- Loading branch information
1 parent
aba7be9
commit 87766af
Showing
5 changed files
with
107 additions
and
20 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,70 @@ | ||
import { ClockIcon } from '@radix-ui/react-icons' | ||
import { Callout, Strong, Text } from '@radix-ui/themes' | ||
import { addMinutes, format, isAfter, isBefore } from 'date-fns' | ||
import React, { FC } from 'react' | ||
|
||
import FormattedCard from './components/FormattedCard' | ||
import Markdown from './components/Markdown' | ||
import Body from './components/pageStructure/Body' | ||
import Header from './components/pageStructure/Header' | ||
import { useAssessmentSummary } from './hooks/assessmentSummary' | ||
|
||
const FrontCover: FC = () => { | ||
const { summary, summaryIsLoaded } = useAssessmentSummary() | ||
|
||
if (!summaryIsLoaded) return <div>Loading...</div> | ||
if (summary === undefined) return <div>Error</div> | ||
|
||
function bannerColour(start: Date, end: Date) { | ||
if (isBefore(new Date(), start)) return 'blue' | ||
if (isAfter(new Date(), end)) return 'red' | ||
return 'amber' | ||
} | ||
|
||
function bannerText(start: Date, end: Date) { | ||
const FMT = "'on' cccc d MMMM Y 'at' hh:mma" | ||
if (isBefore(new Date(), start)) | ||
return ( | ||
<Text> | ||
This assessment<Strong>begins {format(start, FMT)} (UK time)</Strong>, when the questions | ||
will be released | ||
</Text> | ||
) | ||
if (isAfter(new Date(), end)) | ||
return ( | ||
<Text> | ||
This assessment <Strong>ended {format(end, FMT)} (UK time).</Strong> Submissions are no | ||
longer accepted. | ||
</Text> | ||
) | ||
return ( | ||
<Text> | ||
This assessment <Strong>ends {format(end, FMT)} (UK time)</Strong>, after which submissions | ||
will not be accepted. | ||
</Text> | ||
) | ||
} | ||
|
||
return ( | ||
<> | ||
<Header primaryText={summary.courseCode} secondaryText={summary.courseName} /> | ||
<Body> | ||
<FormattedCard title="Instructions"> | ||
<Markdown>{summary.rubric.instructions}</Markdown> | ||
<Callout.Root | ||
color={bannerColour(summary.begins, addMinutes(summary.begins, summary.duration))} | ||
> | ||
<Callout.Icon> | ||
<ClockIcon /> | ||
</Callout.Icon> | ||
<Callout.Text> | ||
{bannerText(summary.begins, addMinutes(summary.begins, summary.duration))} | ||
</Callout.Text> | ||
</Callout.Root> | ||
</FormattedCard> | ||
</Body> | ||
</> | ||
) | ||
} | ||
|
||
export default FrontCover |
This file was deleted.
Oops, something went wrong.
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,18 @@ | ||
import { plainToInstance } from 'class-transformer' | ||
import { useEffect, useState } from 'react' | ||
|
||
import axiosInstance from '../api/axiosInstance' | ||
import routes from '../api/routes' | ||
import { Summary } from '../types/exam' | ||
|
||
export const useAssessmentSummary = () => { | ||
const [summary, setSummary] = useState<Summary>() | ||
const [summaryIsLoaded, setSummaryIsLoaded] = useState(false) | ||
useEffect(() => { | ||
axiosInstance | ||
.get(routes.summary) | ||
.then(({ data }) => setSummary(plainToInstance(Summary, data))) | ||
.finally(() => setSummaryIsLoaded(true)) | ||
}, []) | ||
return { summary, summaryIsLoaded } | ||
} |
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