Skip to content

Commit 8cb2119

Browse files
author
Osamah Ahmad
committed
better sectioning on landing
1 parent 52b4630 commit 8cb2119

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

src/pages/Landing.tsx

+16-16
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ const Landing: React.FC<LandingProps> = () => {
1818

1919
const Logo = require('../resources/radiology-interview-prep-logo.png');
2020

21-
const sections = React.useMemo(() => { return ['welcome', 'structure', 'questions', 'method', 'answers'] }, []);
22-
const sectionTitles = { 'welcome': 'Welcome', 'structure': 'Interview Structure', 'questions': 'Example Questions', 'method': 'My Method', 'answers': My Answers' }
21+
const sections = React.useMemo(() => { return ['welcome', 'structure', 'questions', 'method', 'question-bank'] }, []);
22+
const sectionTitles = { [sections[0]]: 'Welcome', [sections[1]]: 'Interview Structure', [sections[2]]: 'Example Questions', [sections[3]]: 'My Method', [sections[4]]: Question Bank' }
2323

2424
// state to track active section
25-
const [activeSection, setActiveSection] = React.useState('welcome');
25+
const [activeSection, setActiveSection] = React.useState(sections[0]);
2626

2727
// set active section when clicked + scroll to bring it into view
2828
const handleSectionClick = (section) => {
2929
setActiveSection(section);
3030
const element = document.getElementsByClassName(section)[0];
31-
if (section === 'welcome')
31+
if (section === sections[0])
3232
document.getElementsByClassName('content')[0].scrollTo({ top: 0, behavior: 'smooth' });
3333
else if (element)
3434
element.scrollIntoView({ behavior: 'smooth' });
@@ -88,7 +88,7 @@ const Landing: React.FC<LandingProps> = () => {
8888
level='h1'
8989
fontSize='inherit'
9090
startDecorator={<img src={Logo} alt="Logo" style={{ width: '2em' }} />}
91-
onClick={() => handleSectionClick('welcome')}
91+
onClick={() => handleSectionClick(sections[0])}
9292
sx={{ cursor: 'pointer' }}
9393
>
9494
Radiology Interview Prep.
@@ -103,9 +103,9 @@ const Landing: React.FC<LandingProps> = () => {
103103
<Menu>
104104
{sections.map(section => {
105105
return <MenuItem
106-
color={section === 'answers' ? 'success' : 'neutral'}
106+
color={section === 'question-bank' ? 'success' : 'neutral'}
107107
onClick={() => handleSectionClick(section)}
108-
sx={activeSection === section ? (section === 'answers' ? activeSuccessMenuItemSx : activeMenuItemSx) : {}}
108+
sx={activeSection === section ? (section === 'question-bank' ? activeSuccessMenuItemSx : activeMenuItemSx) : {}}
109109
>
110110
{sectionTitles[section]}
111111
</MenuItem>
@@ -119,25 +119,25 @@ const Landing: React.FC<LandingProps> = () => {
119119
color='neutral'
120120
onClick={() => handleSectionClick(section)}
121121
sx={[
122-
section === 'answers' ? {
122+
section === 'question-bank' ? {
123123
'&:hover': {
124124
backgroundColor: 'var(--joy-palette-success-outlinedHoverBg)'
125125
},
126126
'&:active': {
127127
backgroundColor: 'var(--joy-palette-success-outlinedActiveBg)'
128128
}
129129
} : {},
130-
activeSection === section ? (section === 'answers' ? activeSuccessButtonSx : activeButtonSx) : {}
130+
activeSection === section ? (section === 'question-bank' ? activeSuccessButtonSx : activeButtonSx) : {}
131131
]}
132132
>
133-
{section === 'answers' ? <Typography level='body-sm' color='success'>{sectionTitles[section]}</Typography> : sectionTitles[section]}
133+
{section === 'question-bank' ? <Typography level='body-sm' color='success'>{sectionTitles[section]}</Typography> : sectionTitles[section]}
134134
</Button>
135135
})}
136136
</ButtonGroup>
137137
</nav>
138138
</header>
139139
<div className='content'>
140-
<div className='welcome'>
140+
<div className={sections[0]}>
141141
<Typography
142142
level='h1'>
143143
Hello from the <Typography
@@ -155,7 +155,7 @@ const Landing: React.FC<LandingProps> = () => {
155155
I've made this site so you can smash yours too. 💪
156156
</Typography>
157157
</div>
158-
<Card className='structure'>
158+
<Card className={sections[1]}>
159159
<Typography level='h2'>Interview Structure</Typography>
160160
<Typography>
161161
<List>
@@ -241,7 +241,7 @@ const Landing: React.FC<LandingProps> = () => {
241241
</List>
242242
</Typography>
243243
</Card>
244-
<Card className='questions'>
244+
<Card className={sections[2]}>
245245
<Typography level='h2'>Example Questions</Typography>
246246
<Card variant='soft' color='warning'>
247247
<Typography level='h3' color='warning'>Prioritisation of Clinical Situations</Typography>
@@ -444,7 +444,7 @@ const Landing: React.FC<LandingProps> = () => {
444444
</Grid>
445445
</Card>
446446
</Card>
447-
<Card className='method'>
447+
<Card className={sections[3]}>
448448
<Typography level='h2'>My Method</Typography>
449449

450450
<Typography>
@@ -525,8 +525,8 @@ const Landing: React.FC<LandingProps> = () => {
525525
</List>
526526
</Typography>
527527
</Card>
528-
<Card className='answers' variant='outlined'>
529-
<Typography level='h2' startDecorator='£' color='success'>My Answers</Typography>
528+
<Card className={sections[4]} variant='outlined'>
529+
<Typography level='h2' color='success'>{sectionTitles[sections[4]]}</Typography>
530530
<Button color='success' sx={{width: 'fit-content'}} onClick={() => navigate(Paths.QuestionBank)}>Access the Question Bank</Button>
531531
{auth && auth.currentUser && <Typography>You're currently signed in as {auth.currentUser.email}. <Link onClick={() => auth.signOut()}>Sign Out</Link>.</Typography>}
532532
</Card>

src/pages/QuestionBank.tsx

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import React, { ReactNode, useEffect, useState } from "react";
1+
import React, { ReactNode, useCallback, useEffect, useState } from "react";
22
import "./QuestionBank.css";
33
import JSZip from "jszip";
44
import { DOMParser } from "@xmldom/xmldom";
55
import useDocumentTitle from "../hooks/useDocumentTitle.ts";
6-
import { Alert, Button, CircularProgress, LinearProgress, Link, Typography } from "@mui/joy";
7-
import { getAuth, onAuthStateChanged, sendEmailVerification } from "firebase/auth";
6+
import { Alert, Button, CircularProgress, Link, Typography } from "@mui/joy";
7+
import { onAuthStateChanged, sendEmailVerification } from "firebase/auth";
88
import { auth } from "../resources/Firebase.js";
99

1010
const str2xml = (str: string) => {
@@ -160,7 +160,7 @@ const QuestionBank: React.FC<QuestionBankProps> = ({ }) => {
160160
/* parse data */
161161
const [paragraphs, setParagraphs] = useState<string[]>([]);
162162

163-
const onFileUpload = async () => {
163+
const onFileUpload = useCallback(async () => {
164164
try {
165165
const response = await fetch('/question-bank.docx');
166166
const blob = await response.blob();
@@ -170,7 +170,11 @@ const QuestionBank: React.FC<QuestionBankProps> = ({ }) => {
170170
} catch (error) {
171171
console.error(error);
172172
}
173-
};
173+
}, []);
174+
175+
useEffect(() => {
176+
onFileUpload();
177+
}, [onFileUpload]);
174178

175179
return (
176180
<div>

0 commit comments

Comments
 (0)