diff --git a/src/components/PageLayout/MenuMain/MenuMain.tsx b/src/components/PageLayout/MenuMain/MenuMain.tsx index fac0abe9..deb6369d 100644 --- a/src/components/PageLayout/MenuMain/MenuMain.tsx +++ b/src/components/PageLayout/MenuMain/MenuMain.tsx @@ -10,7 +10,6 @@ import {CloseButton} from '@/components/CloseButton/CloseButton' import {Loading} from '@/components/Loading/Loading' import Menu from '@/svg/menu.svg' import {MenuItemShort} from '@/types/api/cms' -import {useDataFromURL} from '@/utils/useDataFromURL' import {useHasPermissions} from '@/utils/useHasPermissions' import {useSeminarInfo} from '@/utils/useSeminarInfo' @@ -19,7 +18,6 @@ import styles from './MenuMain.module.scss' export const MenuMain: FC = () => { const {seminar, seminarId} = useSeminarInfo() - const {id} = useDataFromURL() const {hasPermissions} = useHasPermissions() @@ -74,7 +72,7 @@ export const MenuMain: FC = () => { {hasPermissions && ( - + )} diff --git a/src/components/PageLayout/TopGrid/TopGrid.tsx b/src/components/PageLayout/TopGrid/TopGrid.tsx index 6ed9e9e5..c7588de5 100644 --- a/src/components/PageLayout/TopGrid/TopGrid.tsx +++ b/src/components/PageLayout/TopGrid/TopGrid.tsx @@ -2,7 +2,7 @@ import {Stack, Typography} from '@mui/material' import clsx from 'clsx' import Link from 'next/link' import {useRouter} from 'next/router' -import {FC} from 'react' +import {FC, useMemo} from 'react' import {SemesterPicker} from '@/components/SemesterPicker/SemesterPicker' import {PageTitleContainer} from '@/utils/PageTitleContainer' @@ -15,7 +15,17 @@ export const TopGrid: FC = () => { const {seminar} = useSeminarInfo() // z napr. `/matik/zadania(/*)` vytiahne `zadania` - const page = useRouter().pathname.split('/')[2] + const pathname = useRouter().pathname.split('/') + + const semesterPickerPage = useMemo(() => { + if (pathname[2] === 'zadania' || pathname[2] === 'vysledky') { + return pathname[2] + } + if (pathname[2] === 'admin' && pathname[3] === 'opravovanie') { + return 'admin/opravovanie' + } + return undefined + }, [pathname]) const {pageTitle} = PageTitleContainer.useContainer() @@ -42,9 +52,9 @@ export const TopGrid: FC = () => { {pageTitle} - {(page === 'zadania' || page === 'vysledky') && ( + {semesterPickerPage && (
- +
)} diff --git a/src/components/ProblemAdministration/ProblemAdministration.module.scss b/src/components/ProblemAdministration/ProblemAdministration.module.scss index 5ee195ec..95f6bbdc 100644 --- a/src/components/ProblemAdministration/ProblemAdministration.module.scss +++ b/src/components/ProblemAdministration/ProblemAdministration.module.scss @@ -1,16 +1,3 @@ - - -.container { - display: flex; - flex-direction: column; - row-gap: 12px; -} - -.rightButton{ - display: flex; - justify-content: flex-end; -} - .icon { color: black; } diff --git a/src/components/ProblemAdministration/ProblemAdministration.module.scss.d.ts b/src/components/ProblemAdministration/ProblemAdministration.module.scss.d.ts index b4e10a26..5886d69a 100644 --- a/src/components/ProblemAdministration/ProblemAdministration.module.scss.d.ts +++ b/src/components/ProblemAdministration/ProblemAdministration.module.scss.d.ts @@ -1,10 +1,8 @@ export type Styles = { centerCell: string - container: string icon: string iconDisabled: string input: string - rightButton: string row: string table: string tableBody: string diff --git a/src/components/ProblemAdministration/ProblemAdministration.tsx b/src/components/ProblemAdministration/ProblemAdministration.tsx index fb58c232..fd34e535 100644 --- a/src/components/ProblemAdministration/ProblemAdministration.tsx +++ b/src/components/ProblemAdministration/ProblemAdministration.tsx @@ -1,12 +1,13 @@ import {FormatAlignJustify, Grading} from '@mui/icons-material' -import {Typography} from '@mui/material' +import {Stack, Typography} from '@mui/material' import {useMutation, useQuery} from '@tanstack/react-query' import axios from 'axios' import {useRouter} from 'next/router' import React, {FC, useCallback, useEffect, useState} from 'react' import {DropzoneOptions, useDropzone} from 'react-dropzone' -import {ProblemWithSolutions, SolutionAdministration} from '@/types/api/competition' +import {ProblemWithSolutions, SemesterWithProblems, SolutionAdministration} from '@/types/api/competition' +import {PageTitleContainer} from '@/utils/PageTitleContainer' import {useHasPermissions} from '@/utils/useHasPermissions' import {Button} from '../Clickable/Button' @@ -20,6 +21,7 @@ import styles from './ProblemAdministration.module.scss' export const ProblemAdministration: FC = () => { const router = useRouter() const {params} = router.query + const {setPageTitle} = PageTitleContainer.useContainer() const problemId = params && params[0] @@ -35,6 +37,21 @@ export const ProblemAdministration: FC = () => { }) const problem = problemData?.data + const semesterId = problem?.series.semester + 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 + enabled: semesterId !== undefined, + }) + const semester = semesterData?.data + const semesterName = semester?.season_code === 0 ? 'zima' : 'leto' + const semesterUrl = `${semester?.year}/${semesterName}` + + useEffect(() => { + !!problem && !!semester && setPageTitle(`${problem?.order}. úloha - ${semesterUrl} (${semester?.school_year})`) + }, [problem, semester, semesterUrl, setPageTitle]) + const {hasPermissions, permissionsIsLoading} = useHasPermissions() const [solutions, setSolutions] = useState() @@ -91,7 +108,7 @@ export const ProblemAdministration: FC = () => { }, }) - if (permissionsIsLoading || problemIsLoading) return + if (permissionsIsLoading || problemIsLoading || semesterIsLoading) 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. @@ -99,14 +116,14 @@ export const ProblemAdministration: FC = () => { const handleSavePoints = () => uploadPoints(problemId) return ( -
- Opravovanie {problem.order}. úlohy + + + Opravovanie {problem.order}. úlohy -
- + Späť na semester -
+
{problem.text ?? 'Načítavam...'} @@ -129,11 +146,11 @@ export const ProblemAdministration: FC = () => { />
-
+ Stiahnuť riešenia -
+ { text="Vlož opravené riešenia vo formáte zip" /> -
+
Riešiteľ
@@ -207,12 +224,12 @@ export const ProblemAdministration: FC = () => { ))}
-
+ -
+ -
+ ) } diff --git a/src/components/PublicationUploader/PublicationUploader.tsx b/src/components/PublicationUploader/PublicationUploader.tsx index 012e02a2..68c5529a 100644 --- a/src/components/PublicationUploader/PublicationUploader.tsx +++ b/src/components/PublicationUploader/PublicationUploader.tsx @@ -8,7 +8,7 @@ import {Link} from '../Clickable/Link' import {FileUploader} from '../FileUploader/FileUploader' interface PublicationUploaderProps { - semesterId: string + semesterId: number order: number semesterData: SemesterWithProblems } @@ -20,7 +20,7 @@ export const PublicationUploader: FC = ({semesterId, o const appendFormData = (formData: FormData) => { formData.append('publication_type', 'Časopisy') - formData.append('event', semesterId) + formData.append('event', semesterId.toString()) formData.append('order', order.toString()) } diff --git a/src/components/SemesterAdministration/SemesterAdministration.module.scss b/src/components/SemesterAdministration/SemesterAdministration.module.scss index d9476036..f3b6c162 100644 --- a/src/components/SemesterAdministration/SemesterAdministration.module.scss +++ b/src/components/SemesterAdministration/SemesterAdministration.module.scss @@ -1,3 +1,3 @@ .textarea { width: 100%; -} \ No newline at end of file +} diff --git a/src/components/SemesterAdministration/SemesterAdministration.tsx b/src/components/SemesterAdministration/SemesterAdministration.tsx index 9cf190e1..8fcf0ef4 100644 --- a/src/components/SemesterAdministration/SemesterAdministration.tsx +++ b/src/components/SemesterAdministration/SemesterAdministration.tsx @@ -1,13 +1,13 @@ import {Stack, Typography} from '@mui/material' import {useQuery} from '@tanstack/react-query' import axios from 'axios' -import {useRouter} from 'next/router' import {FC, useState} from 'react' import {Button} from '@/components/Clickable/Button' import {Link} from '@/components/Clickable/Link' import {SemesterWithProblems} from '@/types/api/generated/competition' import {formatDateTime} from '@/utils/formatDate' +import {useDataFromURL} from '@/utils/useDataFromURL' import {useHasPermissions} from '@/utils/useHasPermissions' import {Loading} from '../Loading/Loading' @@ -26,10 +26,10 @@ interface PostalCard { } export const SemesterAdministration: FC = () => { - const router = useRouter() - const {params} = router.query - - const semesterId = params && params[0] + const { + id: {semesterId}, + loading: urlDataLoading, + } = useDataFromURL() const {hasPermissions, permissionsIsLoading} = useHasPermissions() @@ -84,8 +84,14 @@ export const SemesterAdministration: FC = () => { ) } - if (permissionsIsLoading || semesterIsLoading) return - if (!hasPermissions) return Nemáš oprávnenie na zobrazenie tejto stránky. + if ( + urlDataLoading.currentSeriesIsLoading || + urlDataLoading.semesterListIsLoading || + permissionsIsLoading || + semesterIsLoading + ) + return + if (!hasPermissions) return Nemáš oprávnenie na zobrazenie tejto stránky. if (semesterId === undefined || !semester) return ( @@ -95,10 +101,7 @@ export const SemesterAdministration: FC = () => { return ( <> - - {semester.year}. ročník ({semester.school_year}) - {semester.season_code === 0 ? 'zima' : 'leto'} - - Administrácia semestra pre opravovateľov. + Administrácia semestra pre opravovateľov. {semester.series_set.map((series) => ( {series.order}. séria diff --git a/src/components/SemesterPicker/SemesterPicker.tsx b/src/components/SemesterPicker/SemesterPicker.tsx index 487f6d3e..491b4af0 100644 --- a/src/components/SemesterPicker/SemesterPicker.tsx +++ b/src/components/SemesterPicker/SemesterPicker.tsx @@ -28,7 +28,7 @@ export interface SemesterListItem { series_set: SeriesListItem[] } -export const SemesterPicker: FC<{page: 'zadania' | 'vysledky'}> = ({page}) => { +export const SemesterPicker: FC<{page: 'zadania' | 'vysledky' | 'admin/opravovanie'}> = ({page}) => { const {seminar} = useSeminarInfo() const {setPageTitle} = PageTitleContainer.useContainer() @@ -42,7 +42,11 @@ export const SemesterPicker: FC<{page: 'zadania' | 'vysledky'}> = ({page}) => { let pageTitleToSet = '' if (semester) { const semesterTitle = `${semester?.year}. ročník - ${semester?.season_code === 0 ? 'zimný' : 'letný'} semester` - if (displayWholeSemesterOnResults) { + if (page === 'admin/opravovanie') { + pageTitleToSet = `Opravovanie - ${semester?.year}/${semester?.season_code === 0 ? 'zima' : 'leto'} (${ + semester?.school_year + })` + } else if (displayWholeSemesterOnResults) { pageTitleToSet = semesterTitle } else if (series) { pageTitleToSet = `${semesterTitle}${series?.order ? ` - ${series?.order}. séria` : ''}` @@ -50,7 +54,7 @@ export const SemesterPicker: FC<{page: 'zadania' | 'vysledky'}> = ({page}) => { } setPageTitle(pageTitleToSet) // `semester` a `series` su nami vytiahnute objekty, tak mozu triggerovat effekt kazdy render. nemalo by vadit - }, [displayWholeSemesterOnResults, semester, series, setPageTitle]) + }, [displayWholeSemesterOnResults, semester, series, page, setPageTitle]) const dropdownSemesterList = semesterList.map((semester) => { return { @@ -85,7 +89,7 @@ export const SemesterPicker: FC<{page: 'zadania' | 'vysledky'}> = ({page}) => { return (
- + {page !== 'admin/opravovanie' && }
) diff --git a/src/pages/strom/admin/opravit-ulohu/[[...params]].tsx b/src/pages/strom/admin/opravit-ulohu/[[...params]].tsx index d2814075..1b3724f4 100644 --- a/src/pages/strom/admin/opravit-ulohu/[[...params]].tsx +++ b/src/pages/strom/admin/opravit-ulohu/[[...params]].tsx @@ -4,7 +4,7 @@ import {PageLayout} from '@/components/PageLayout/PageLayout' import {ProblemAdministration as ProblemAdministrationComponent} from '@/components/ProblemAdministration/ProblemAdministration' const ProblemAdministration: NextPage = () => ( - + ) diff --git a/src/pages/strom/admin/opravovanie/[[...params]].tsx b/src/pages/strom/admin/opravovanie/[[...params]].tsx index 44cd527e..cd9f01a0 100644 --- a/src/pages/strom/admin/opravovanie/[[...params]].tsx +++ b/src/pages/strom/admin/opravovanie/[[...params]].tsx @@ -4,7 +4,7 @@ import {PageLayout} from '@/components/PageLayout/PageLayout' import {SemesterAdministration as SemesterAdministrationComponent} from '@/components/SemesterAdministration/SemesterAdministration' const SemesterAdmnistration: NextPage = () => ( - + )