-
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.
* remove unused code upload is not in the side panel anymore * removed chcem riesit button * Register dialog when user not registered to semester tries to upload their first solution * LF -> CRLF fix * CRLF fix * Register to semester dialog refactor * Splitting Problem and Problems component to separate files * SemesterAdministration styles
- Loading branch information
1 parent
505ee37
commit 0fe56b1
Showing
9 changed files
with
330 additions
and
284 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
.problem { | ||
padding: 20px; | ||
|
||
.problemTitle { | ||
font-weight: bold; | ||
} | ||
} | ||
|
||
.actions { | ||
margin-top: .5rem; | ||
display: flex; | ||
justify-content: flex-end; | ||
column-gap: 20px; | ||
} | ||
|
||
.imageContainer { | ||
display: grid; | ||
place-items: center; | ||
} | ||
|
||
.image { | ||
width: auto; | ||
height: auto; | ||
min-height: 3rem; | ||
min-width: 3rem; | ||
max-height: 50vh; | ||
margin-top: 1rem; | ||
} |
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,13 @@ | ||
export type Styles = { | ||
actions: string | ||
image: string | ||
imageContainer: string | ||
problem: string | ||
problemTitle: string | ||
} | ||
|
||
export type ClassNames = keyof Styles | ||
|
||
declare const styles: Styles | ||
|
||
export default styles |
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 Image from 'next/image' | ||
import {Dispatch, FC, SetStateAction, useState} from 'react' | ||
|
||
import {Button, Link} from '@/components/Clickable/Clickable' | ||
import {Problem as ProblemType} from '@/types/api/competition' | ||
|
||
import {Latex} from '../Latex/Latex' | ||
import styles from './Problem.module.scss' | ||
import {UploadProblemForm} from './UploadProblemForm' | ||
|
||
export const Problem: FC<{ | ||
problem: ProblemType | ||
setDisplaySideContent: Dispatch< | ||
SetStateAction<{ | ||
type: string | ||
problemId: number | ||
problemNumber: number | ||
problemSubmitted?: boolean | ||
}> | ||
> | ||
registered: boolean | ||
canRegister: boolean | ||
canSubmit: boolean | ||
invalidateSeriesQuery: () => Promise<void> | ||
displayRegisterDialog: () => void | ||
}> = ({ | ||
problem, | ||
registered, | ||
setDisplaySideContent, | ||
canRegister, | ||
canSubmit, | ||
invalidateSeriesQuery, | ||
displayRegisterDialog, | ||
}) => { | ||
const handleDiscussionButtonClick = () => { | ||
setDisplaySideContent((prevState) => { | ||
if (prevState.type === 'discussion' && prevState.problemId === problem.id) { | ||
return {type: '', problemId: -1, problemNumber: -1} | ||
} else { | ||
return {type: 'discussion', problemId: problem.id, problemNumber: problem.order} | ||
} | ||
}) | ||
} | ||
const handleUploadClick = () => { | ||
if (!registered && canRegister) { | ||
displayRegisterDialog() | ||
} else { | ||
setDisplayProblemUploadForm((prevState) => !prevState) | ||
setDisplayActions(false) | ||
} | ||
} | ||
|
||
const [displayProblemUploadForm, setDisplayProblemUploadForm] = useState<boolean>(false) | ||
const [displayActions, setDisplayActions] = useState(true) | ||
|
||
return ( | ||
<div className={styles.problem}> | ||
<h3 className={styles.problemTitle}>{problem.order}. ÚLOHA</h3> | ||
<Latex>{problem.text}</Latex> | ||
{problem.image && ( | ||
<div className={styles.imageContainer}> | ||
<Image | ||
src={problem.image} | ||
alt={`Obrázok - ${problem.order} úloha`} | ||
className={styles.image} | ||
width={800} // These values are overwritten by css | ||
height={800} | ||
/> | ||
</div> | ||
)} | ||
{displayProblemUploadForm && ( | ||
<UploadProblemForm | ||
problemId={problem.id} | ||
setDisplayProblemUploadForm={setDisplayProblemUploadForm} | ||
problemSubmitted={!!problem.submitted} | ||
invalidateSeriesQuery={invalidateSeriesQuery} | ||
setDisplayActions={setDisplayActions} | ||
/> | ||
)} | ||
{displayActions && ( | ||
<div className={styles.actions}> | ||
{problem.solution_pdf && ( | ||
<Link href={problem.solution_pdf} target="_blank"> | ||
vzorové riešenie | ||
</Link> | ||
)} | ||
{registered && ( | ||
<> | ||
<Link | ||
href={`/api/competition/problem/${problem.id}/my-solution`} | ||
target="_blank" | ||
disabled={!problem.submitted} | ||
> | ||
moje riešenie | ||
</Link> | ||
<Link | ||
href={`/api/competition/problem/${problem.id}/corrected-solution`} | ||
target="_blank" | ||
disabled={!problem.submitted?.corrected_solution} | ||
> | ||
opravené riešenie{!!problem.submitted?.corrected_solution && ` (${problem.submitted.score || '?'})`} | ||
</Link> | ||
</> | ||
)} | ||
<Button onClick={handleDiscussionButtonClick}>diskusia ({problem.num_comments}) </Button> | ||
{(registered || canRegister) && ( | ||
<Button onClick={handleUploadClick} disabled={!canSubmit}> | ||
odovzdať | ||
</Button> | ||
)} | ||
</div> | ||
)} | ||
</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
Oops, something went wrong.