-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'compsci-adl:main' into main
- Loading branch information
Showing
12 changed files
with
197 additions
and
9 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
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,92 @@ | ||
import { | ||
Button, | ||
Card, | ||
CardBody, | ||
CardHeader, | ||
Divider, | ||
Link, | ||
Modal, | ||
ModalBody, | ||
ModalContent, | ||
ModalFooter, | ||
ModalHeader, | ||
Tooltip, | ||
} from '@nextui-org/react'; | ||
import clsx from 'clsx'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import { useDetailedEnrolledCourses } from '../data/enrolled-courses'; | ||
import { useExportCalendar } from '../helpers/export-calendar'; | ||
|
||
type ReadyModalProps = { | ||
isOpen: boolean; | ||
onOpenChange: (isOpen: boolean) => void; | ||
}; | ||
export const EnrolmentModal = ({ isOpen, onOpenChange }: ReadyModalProps) => { | ||
const { t } = useTranslation(); | ||
const { copyText } = useExportCalendar(); | ||
|
||
const enrolledCourses = useDetailedEnrolledCourses(); | ||
const isOnlyCourse = enrolledCourses.length === 1; | ||
|
||
return ( | ||
<Modal | ||
isOpen={isOpen} | ||
onOpenChange={onOpenChange} | ||
size={isOnlyCourse ? 'xs' : '2xl'} | ||
> | ||
<ModalContent> | ||
<ModalHeader className="flex-col"> | ||
<div>{t('calendar.end-actions.ready')}</div> | ||
<div className="text-sm font-normal"> | ||
{t('calendar.end-actions.enrolment-instruction')} | ||
</div> | ||
</ModalHeader> | ||
<ModalBody className={clsx(!isOnlyCourse && 'grid grid-cols-2')}> | ||
{enrolledCourses.map((c) => ( | ||
<Card key={c.id}> | ||
<CardHeader className="flex-col text-center"> | ||
<p className="text-lg font-black"> | ||
{c.name.subject} {c.name.code} | ||
</p> | ||
<p className="text-sm">{c.name.title}</p> | ||
</CardHeader> | ||
<Divider /> | ||
<CardBody className="grid grid-cols-2 items-center justify-center gap-2"> | ||
{c.classes.map((cls) => ( | ||
<div | ||
key={cls.typeId} | ||
className="rounded-lg border *:p-1 *:text-center" | ||
> | ||
<div className="border-b font-bold">{cls.type}</div> | ||
<div>{cls.classNumber}</div> | ||
</div> | ||
))} | ||
</CardBody> | ||
</Card> | ||
))} | ||
</ModalBody> | ||
<ModalFooter className="justify-between"> | ||
<Tooltip content={t('calendar.end-actions.copy')} size="sm"> | ||
<Button | ||
isIconOnly | ||
className="text-xl" | ||
onPress={copyText} | ||
variant="flat" | ||
> | ||
📋 | ||
</Button> | ||
</Tooltip> | ||
<Button | ||
href="https://access.adelaide.edu.au/" | ||
as={Link} | ||
showAnchorIcon | ||
target="_blank" | ||
> | ||
Access Adelaide | ||
</Button> | ||
</ModalFooter> | ||
</ModalContent> | ||
</Modal> | ||
); | ||
}; |
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
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,24 @@ | ||
import { useTranslation } from 'react-i18next'; | ||
import { toast } from 'sonner'; | ||
|
||
import { useDetailedEnrolledCourses } from '../data/enrolled-courses'; | ||
|
||
export const useExportCalendar = () => { | ||
const { t } = useTranslation(); | ||
|
||
const enrolledCourses = useDetailedEnrolledCourses(); | ||
const copyText = async () => { | ||
const res = enrolledCourses.map((c) => ({ | ||
name: c.name.title + '\n' + c.name.subject + ' ' + c.name.code, | ||
classes: c.classes | ||
.map(({ type, classNumber }) => type + ': ' + classNumber) | ||
.join('\n'), | ||
})); | ||
const resStr = res.map((d) => d.name + '\n\n' + d.classes).join('\n\n'); | ||
const advertisement = | ||
'Planned with MyTimetable\nhttps://mytimetable.csclub.org.au/'; | ||
await navigator.clipboard.writeText(resStr + '\n\n\n' + advertisement); | ||
toast.success(t('calendar.end-actions.copy-success')); | ||
}; | ||
return { copyText }; | ||
}; |
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
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