From 877aeb6b038abda7eec16014f1812b18c89a685b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vikt=C3=B3ria=20Brezinov=C3=A1?= Date: Sun, 10 Dec 2023 13:58:50 +0100 Subject: [PATCH 1/7] change semesterPicker to support admin/opravovanie --- .../SemesterPicker/SemesterPicker.tsx | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/components/SemesterPicker/SemesterPicker.tsx b/src/components/SemesterPicker/SemesterPicker.tsx index 487f6d3e..a7e42b44 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,9 @@ 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' + } else if (displayWholeSemesterOnResults) { pageTitleToSet = semesterTitle } else if (series) { pageTitleToSet = `${semesterTitle}${series?.order ? ` - ${series?.order}. séria` : ''}` @@ -50,9 +52,17 @@ 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) => { + if (page === 'admin/opravovanie') { + return { + id: semester.id, + text: `${semester.year}. ročník - ${semester.season_code === 0 ? 'zimný' : 'letný'} semester`, + link: `/${seminar}/${page}/${semester.id}`, + selected: semester.id === selectedItem.semesterId, + } + } return { id: semester.id, text: `${semester.year}. ročník - ${semester.season_code === 0 ? 'zimný' : 'letný'} semester`, @@ -85,7 +95,7 @@ export const SemesterPicker: FC<{page: 'zadania' | 'vysledky'}> = ({page}) => { return (
- + {page !== 'admin/opravovanie' && }
) From d36d6816c6eaeae27f55baf4a70a4dc59918f8b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vikt=C3=B3ria=20Brezinov=C3=A1?= Date: Sun, 10 Dec 2023 13:59:18 +0100 Subject: [PATCH 2/7] add semesterPicker to administration --- .../SemesterAdministration.module.scss | 5 +++++ .../SemesterAdministration.module.scss.d.ts | 1 + .../SemesterAdministration/SemesterAdministration.tsx | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/src/components/SemesterAdministration/SemesterAdministration.module.scss b/src/components/SemesterAdministration/SemesterAdministration.module.scss index d9476036..c3734551 100644 --- a/src/components/SemesterAdministration/SemesterAdministration.module.scss +++ b/src/components/SemesterAdministration/SemesterAdministration.module.scss @@ -1,3 +1,8 @@ .textarea { width: 100%; +} + +.semesterPicker { + display: flex; + justify-content: flex-end; } \ No newline at end of file diff --git a/src/components/SemesterAdministration/SemesterAdministration.module.scss.d.ts b/src/components/SemesterAdministration/SemesterAdministration.module.scss.d.ts index 09e0f310..2e41f22b 100644 --- a/src/components/SemesterAdministration/SemesterAdministration.module.scss.d.ts +++ b/src/components/SemesterAdministration/SemesterAdministration.module.scss.d.ts @@ -1,5 +1,6 @@ export type Styles = { textarea: string + semesterPicker: SemesterPicker } export type ClassNames = keyof Styles diff --git a/src/components/SemesterAdministration/SemesterAdministration.tsx b/src/components/SemesterAdministration/SemesterAdministration.tsx index 9cf190e1..ed8c7907 100644 --- a/src/components/SemesterAdministration/SemesterAdministration.tsx +++ b/src/components/SemesterAdministration/SemesterAdministration.tsx @@ -6,6 +6,7 @@ import {FC, useState} from 'react' import {Button} from '@/components/Clickable/Button' import {Link} from '@/components/Clickable/Link' +import {SemesterPicker} from '@/components/SemesterPicker/SemesterPicker' import {SemesterWithProblems} from '@/types/api/generated/competition' import {formatDateTime} from '@/utils/formatDate' import {useHasPermissions} from '@/utils/useHasPermissions' @@ -95,6 +96,9 @@ export const SemesterAdministration: FC = () => { return ( <> +
+ +
{semester.year}. ročník ({semester.school_year}) - {semester.season_code === 0 ? 'zima' : 'leto'} From 150ce1be43f50ff4c06328abe0acd13e44757134 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vikt=C3=B3ria=20Brezinov=C3=A1?= Date: Sun, 10 Dec 2023 14:13:06 +0100 Subject: [PATCH 3/7] generate type --- .../SemesterAdministration.module.scss.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/SemesterAdministration/SemesterAdministration.module.scss.d.ts b/src/components/SemesterAdministration/SemesterAdministration.module.scss.d.ts index 2e41f22b..89a00b6c 100644 --- a/src/components/SemesterAdministration/SemesterAdministration.module.scss.d.ts +++ b/src/components/SemesterAdministration/SemesterAdministration.module.scss.d.ts @@ -1,6 +1,6 @@ export type Styles = { + semesterPicker: string textarea: string - semesterPicker: SemesterPicker } export type ClassNames = keyof Styles From 9288783e7a97f6df6dc238dfe3c7d571b2cc150d Mon Sep 17 00:00:00 2001 From: matushl Date: Mon, 11 Dec 2023 01:21:05 +0100 Subject: [PATCH 4/7] Move semester picker into TopGrid --- src/components/PageLayout/TopGrid/TopGrid.tsx | 18 ++++++++++++++---- .../SemesterAdministration.module.scss | 5 ----- .../SemesterAdministration.module.scss.d.ts | 1 - .../SemesterAdministration.tsx | 3 --- 4 files changed, 14 insertions(+), 13 deletions(-) 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/SemesterAdministration/SemesterAdministration.module.scss b/src/components/SemesterAdministration/SemesterAdministration.module.scss index c3734551..f3b6c162 100644 --- a/src/components/SemesterAdministration/SemesterAdministration.module.scss +++ b/src/components/SemesterAdministration/SemesterAdministration.module.scss @@ -1,8 +1,3 @@ .textarea { width: 100%; } - -.semesterPicker { - display: flex; - justify-content: flex-end; -} \ No newline at end of file diff --git a/src/components/SemesterAdministration/SemesterAdministration.module.scss.d.ts b/src/components/SemesterAdministration/SemesterAdministration.module.scss.d.ts index 89a00b6c..09e0f310 100644 --- a/src/components/SemesterAdministration/SemesterAdministration.module.scss.d.ts +++ b/src/components/SemesterAdministration/SemesterAdministration.module.scss.d.ts @@ -1,5 +1,4 @@ export type Styles = { - semesterPicker: string textarea: string } diff --git a/src/components/SemesterAdministration/SemesterAdministration.tsx b/src/components/SemesterAdministration/SemesterAdministration.tsx index ed8c7907..567ce8ba 100644 --- a/src/components/SemesterAdministration/SemesterAdministration.tsx +++ b/src/components/SemesterAdministration/SemesterAdministration.tsx @@ -96,9 +96,6 @@ export const SemesterAdministration: FC = () => { return ( <> -
- -
{semester.year}. ročník ({semester.school_year}) - {semester.season_code === 0 ? 'zima' : 'leto'} From e510f22a61ce851da6f791a8d20aee4ea2d4a65c Mon Sep 17 00:00:00 2001 From: matushl Date: Mon, 11 Dec 2023 14:58:34 +0100 Subject: [PATCH 5/7] Rework url for semester administration --- .../PageLayout/MenuMain/MenuMain.tsx | 2 +- .../PublicationUploader.tsx | 4 +-- .../SemesterAdministration.tsx | 26 ++++++++++--------- .../SemesterPicker/SemesterPicker.tsx | 12 +++------ 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/components/PageLayout/MenuMain/MenuMain.tsx b/src/components/PageLayout/MenuMain/MenuMain.tsx index fac0abe9..73186193 100644 --- a/src/components/PageLayout/MenuMain/MenuMain.tsx +++ b/src/components/PageLayout/MenuMain/MenuMain.tsx @@ -74,7 +74,7 @@ export const MenuMain: FC = () => { {hasPermissions && ( - + )} 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.tsx b/src/components/SemesterAdministration/SemesterAdministration.tsx index 567ce8ba..8fcf0ef4 100644 --- a/src/components/SemesterAdministration/SemesterAdministration.tsx +++ b/src/components/SemesterAdministration/SemesterAdministration.tsx @@ -1,14 +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 {SemesterPicker} from '@/components/SemesterPicker/SemesterPicker' 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' @@ -27,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() @@ -85,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 ( @@ -96,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 a7e42b44..491b4af0 100644 --- a/src/components/SemesterPicker/SemesterPicker.tsx +++ b/src/components/SemesterPicker/SemesterPicker.tsx @@ -43,7 +43,9 @@ export const SemesterPicker: FC<{page: 'zadania' | 'vysledky' | 'admin/opravovan if (semester) { const semesterTitle = `${semester?.year}. ročník - ${semester?.season_code === 0 ? 'zimný' : 'letný'} semester` if (page === 'admin/opravovanie') { - pageTitleToSet = 'Opravovanie' + pageTitleToSet = `Opravovanie - ${semester?.year}/${semester?.season_code === 0 ? 'zima' : 'leto'} (${ + semester?.school_year + })` } else if (displayWholeSemesterOnResults) { pageTitleToSet = semesterTitle } else if (series) { @@ -55,14 +57,6 @@ export const SemesterPicker: FC<{page: 'zadania' | 'vysledky' | 'admin/opravovan }, [displayWholeSemesterOnResults, semester, series, page, setPageTitle]) const dropdownSemesterList = semesterList.map((semester) => { - if (page === 'admin/opravovanie') { - return { - id: semester.id, - text: `${semester.year}. ročník - ${semester.season_code === 0 ? 'zimný' : 'letný'} semester`, - link: `/${seminar}/${page}/${semester.id}`, - selected: semester.id === selectedItem.semesterId, - } - } return { id: semester.id, text: `${semester.year}. ročník - ${semester.season_code === 0 ? 'zimný' : 'letný'} semester`, From 2c016f9c2e4f37be6bfe9565ce92cfabc444bf2a Mon Sep 17 00:00:00 2001 From: matushl Date: Mon, 11 Dec 2023 17:46:48 +0100 Subject: [PATCH 6/7] Fix `Spat na semster` button and change title of ProblemAdministration --- .../ProblemAdministration.module.scss | 13 ------ .../ProblemAdministration.module.scss.d.ts | 2 - .../ProblemAdministration.tsx | 45 +++++++++++++------ .../admin/opravit-ulohu/[[...params]].tsx | 2 +- .../strom/admin/opravovanie/[[...params]].tsx | 2 +- 5 files changed, 33 insertions(+), 31 deletions(-) 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/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 = () => ( - + ) From e418b01c09c40538c1fa25959c17444fea8de996 Mon Sep 17 00:00:00 2001 From: matushl Date: Mon, 11 Dec 2023 17:48:25 +0100 Subject: [PATCH 7/7] fix lint warning --- src/components/PageLayout/MenuMain/MenuMain.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/components/PageLayout/MenuMain/MenuMain.tsx b/src/components/PageLayout/MenuMain/MenuMain.tsx index 73186193..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()