Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove i want to participate #174

Merged
merged 8 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/components/Problems/Problem.module.scss
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;
}
13 changes: 13 additions & 0 deletions src/components/Problems/Problem.module.scss.d.ts
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
115 changes: 115 additions & 0 deletions src/components/Problems/Problem.tsx
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>
)
}
45 changes: 0 additions & 45 deletions src/components/Problems/Problems.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,6 @@
margin-left: auto;
}

.problem {
padding: 20px;

.problemTitle {
font-weight: bold;
}
}

.actions {
margin-top: .5rem;
display: flex;
justify-content: flex-end;
column-gap: 20px;
}

.debug {
margin-left: .5rem;
margin-bottom: .5rem;
Expand All @@ -42,34 +27,4 @@
bottom: 2rem;
right: 20px;
width: calc(25vw - 40px);
}

.registerButton {
background-color: black;
color: white;
height: 2rem;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
user-select: none;
text-transform: uppercase;
font-size: .8rem;
font-style: italic;
font-weight: bold;
margin-bottom: 1rem;
}

.imageContainer {
display: grid;
place-items: center;
}

.image {
width: auto;
height: auto;
min-height: 3rem;
min-width: 3rem;
max-height: 50vh;
margin-top: 1rem;
}
6 changes: 0 additions & 6 deletions src/components/Problems/Problems.module.scss.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
export type Styles = {
actions: string
adminSection: string
container: string
debug: string
image: string
imageContainer: string
problem: string
problemTitle: string
registerButton: string
sideContainer: string
}

Expand Down
Loading
Loading