From 37176289578ec66718c0664078c66333da73cbec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Domen=20Blenku=C5=A1?= Date: Thu, 4 Mar 2021 22:20:30 +0100 Subject: [PATCH] Show school in results for school contests --- src/types/api.ts | 2 ++ src/views/results/ThemeResults.tsx | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/types/api.ts b/src/types/api.ts index dfdb7fe..46046de 100644 --- a/src/types/api.ts +++ b/src/types/api.ts @@ -31,6 +31,8 @@ export interface ResultsAuthor extends Author { reward: string | null; reward_theme: number | null; country: string | null; + school: string | null; + club: string | null; } export interface Submission extends BaseResource { diff --git a/src/views/results/ThemeResults.tsx b/src/views/results/ThemeResults.tsx index a311856..582c5fc 100644 --- a/src/views/results/ThemeResults.tsx +++ b/src/views/results/ThemeResults.tsx @@ -12,9 +12,10 @@ import { Typography, } from '@material-ui/core'; +import ContestService from '../../services/ContestService'; import LoadingProgress from '../../components/LoadingProgress'; import ResultsThemeService from '../../services/ResultsThemeService'; -import { ResultsAuthor, ResultsSubmission } from '../../types/api'; +import { Contest, ResultsAuthor, ResultsSubmission } from '../../types/api'; interface RouteMatchParams { contestId: string; @@ -23,6 +24,7 @@ interface RouteMatchParams { const ThemeResults: React.FC = () => { const [submissionsByAuthor, setSubmissionsByAuthor] = useState([]); + const [contest, setContest] = useState(null); const [redirect, setRedirect] = useState(null); const { contestId, themeId } = useParams(); @@ -40,6 +42,14 @@ const ThemeResults: React.FC = () => { fetch(); }, [themeId]); + useEffect(() => { + const fetchContest = async (): Promise => { + const { data } = await ContestService.getContest(contestId); + setContest(data); + }; + fetchContest(); + }, [contestId]); + const getAuthor = (submissions: ResultsSubmission[]): ResultsAuthor => submissions[0].author; const getAuthorReward = (author: ResultsAuthor): string => { @@ -88,7 +98,7 @@ const ThemeResults: React.FC = () => { /> ); - if (!submissionsByAuthor.length) return ; + if (!submissionsByAuthor.length || !contest) return ; return ( <> @@ -97,6 +107,9 @@ const ThemeResults: React.FC = () => { {submissionsByAuthor.map((submissions: ResultsSubmission[]) => { const author = getAuthor(submissions); + let authorDetails = `${author.country}`; + if (contest.school_show) authorDetails = `${author.school || '/'}`; + if (author.club) authorDetails += `, klub: ${author.club || '/'}`; return ( @@ -105,7 +118,7 @@ const ThemeResults: React.FC = () => { {author.last_name}, {author.first_name} {' '} - ({author.country}) + ({authorDetails})