diff --git a/src/components/ProblemAdministration/ProblemAdministration.tsx b/src/components/ProblemAdministration/ProblemAdministration.tsx index c0fead51..d19937a4 100644 --- a/src/components/ProblemAdministration/ProblemAdministration.tsx +++ b/src/components/ProblemAdministration/ProblemAdministration.tsx @@ -1,4 +1,5 @@ import {FormatAlignJustify, Grading} from '@mui/icons-material' +import {Typography} from '@mui/material' import {useMutation, useQuery} from '@tanstack/react-query' import axios from 'axios' import {useRouter} from 'next/router' @@ -21,7 +22,11 @@ export const ProblemAdministration: FC = () => { const problemId = params && params[0] - const {data: problemData, refetch: refetchProblem} = useQuery({ + const { + data: problemData, + refetch: refetchProblem, + isLoading: problemIsLoading, + } = useQuery({ queryKey: ['competition', 'problem-administration', problemId], queryFn: () => axios.get(`/api/competition/problem-administration/${problemId}`), // router.query.params su v prvom renderi undefined, tak pustime query az so spravnym problemId @@ -48,10 +53,6 @@ export const ProblemAdministration: FC = () => { onSuccess: () => refetchProblem(), }) - const handleSavePoints = async () => { - problemId && uploadPoints(problemId) - } - const updatePoints = (index: number, newPointsInput: string) => { const newPoints = Number.parseInt(newPointsInput) // nevalidny input spravi NaN @@ -89,23 +90,27 @@ export const ProblemAdministration: FC = () => { }, }) - if (permissionsIsLoading) return + if (permissionsIsLoading || problemIsLoading) return if (!hasPermissions) return Nemáš oprávnenie na zobrazenie tejto stránky. + if (problemId === undefined || !problem) + return Nevalidné číslo úlohy (problemId) v URL alebo ju proste nevieme fetchnúť z BE. + + const handleSavePoints = () => uploadPoints(problemId) return (
-

Opravovanie {problem?.order}. úlohy

+

Opravovanie {problem.order}. úlohy

- Späť na semester + Späť na semester
- {problem?.text ?? 'Načítavam...'} + {problem.text ?? 'Načítavam...'}
Vzorové riešenie: - {problem?.solution_pdf ? ( - + {problem.solution_pdf ? ( + ) : ( diff --git a/src/components/PublicationUploader/PublicationUploader.tsx b/src/components/PublicationUploader/PublicationUploader.tsx index 8c959d47..973c3d7b 100644 --- a/src/components/PublicationUploader/PublicationUploader.tsx +++ b/src/components/PublicationUploader/PublicationUploader.tsx @@ -10,7 +10,7 @@ import {FileUploader} from '../FileUploader/FileUploader' interface PublicationUploaderProps { semesterId: string order: number - semesterData: SemesterWithProblems | undefined + semesterData: SemesterWithProblems } export const PublicationUploader: FC = ({semesterId, order, semesterData}) => { @@ -24,7 +24,7 @@ export const PublicationUploader: FC = ({semesterId, o formData.append('order', order.toString()) } - const publication = semesterData?.publication_set.find((publication) => publication.order === order) + const publication = semesterData.publication_set.find((publication) => publication.order === order) return ( diff --git a/src/components/SemesterAdministration/SemesterAdministration.tsx b/src/components/SemesterAdministration/SemesterAdministration.tsx index 329749c1..eab65280 100644 --- a/src/components/SemesterAdministration/SemesterAdministration.tsx +++ b/src/components/SemesterAdministration/SemesterAdministration.tsx @@ -1,4 +1,4 @@ -import {Stack} from '@mui/material' +import {Stack, Typography} from '@mui/material' import {useQuery} from '@tanstack/react-query' import axios from 'axios' import {useRouter} from 'next/router' @@ -31,7 +31,7 @@ export const SemesterAdministration: FC = () => { const {hasPermissions, permissionsIsLoading} = useHasPermissions() - const {data: semesterData} = useQuery({ + const {data: semesterData, isLoading: semesterIsLoading} = useQuery({ queryKey: ['competition', 'semester', semesterId], queryFn: () => axios.get(`/api/competition/semester/${semesterId}`), // router.query.params su v prvom renderi undefined, tak pustime query az so spravnym semesterId @@ -74,16 +74,18 @@ export const SemesterAdministration: FC = () => { ) } - if (permissionsIsLoading) return + if (permissionsIsLoading || semesterIsLoading) return if (!hasPermissions) return Nemáš oprávnenie na zobrazenie tejto stránky. + if (semesterId === undefined || !semester) + return Nevalidný semester (semesterId) v URL alebo ho proste nevieme fetchnúť z BE. return ( <>

- {semester?.year}. ročník ({semester?.school_year}) - {semester?.season_code === 0 ? 'zima' : 'leto'} + {semester.year}. ročník ({semester.school_year}) - {semester.season_code === 0 ? 'zima' : 'leto'}

Administrácia semestra pre opravovateľov. - {semester?.series_set.map((series) => ( + {semester.series_set.map((series) => (

{series.order}. séria

@@ -130,7 +132,7 @@ export const SemesterAdministration: FC = () => {

Nahrávanie časopisov

{[1, 2, 3].map((order) => ( - + ))}