Skip to content

Commit

Permalink
Show school in results for school contests
Browse files Browse the repository at this point in the history
  • Loading branch information
dblenkus committed Mar 4, 2021
1 parent 3511f07 commit 3717628
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 16 additions & 3 deletions src/views/results/ThemeResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,6 +24,7 @@ interface RouteMatchParams {

const ThemeResults: React.FC = () => {
const [submissionsByAuthor, setSubmissionsByAuthor] = useState<ResultsSubmission[][]>([]);
const [contest, setContest] = useState<Contest | null>(null);
const [redirect, setRedirect] = useState<null | number>(null);
const { contestId, themeId } = useParams<RouteMatchParams>();

Expand All @@ -40,6 +42,14 @@ const ThemeResults: React.FC = () => {
fetch();
}, [themeId]);

useEffect(() => {
const fetchContest = async (): Promise<void> => {
const { data } = await ContestService.getContest(contestId);
setContest(data);
};
fetchContest();
}, [contestId]);

const getAuthor = (submissions: ResultsSubmission[]): ResultsAuthor => submissions[0].author;

const getAuthorReward = (author: ResultsAuthor): string => {
Expand Down Expand Up @@ -88,7 +98,7 @@ const ThemeResults: React.FC = () => {
/>
);

if (!submissionsByAuthor.length) return <LoadingProgress />;
if (!submissionsByAuthor.length || !contest) return <LoadingProgress />;

return (
<>
Expand All @@ -97,6 +107,9 @@ const ThemeResults: React.FC = () => {
<TableBody>
{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 (
<React.Fragment key={author.id}>
<TableRow>
Expand All @@ -105,7 +118,7 @@ const ThemeResults: React.FC = () => {
<b>
{author.last_name}, {author.first_name}
</b>{' '}
({author.country})
({authorDetails})
</Typography>
</TableCell>
<TableCell colSpan={2} align="right">
Expand Down

0 comments on commit 3717628

Please sign in to comment.