Skip to content

Commit

Permalink
Add hidden contest entries option.
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmacdonald committed Oct 25, 2023
1 parent 5de6e99 commit ebcda64
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 104 deletions.
1 change: 1 addition & 0 deletions frontend/src/api/contests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface Contest extends DateRange {
title: string;
description: string;
public: boolean;
hide_submissions: boolean;
max_submissions: number;
media_types: string;
deleted: boolean;
Expand Down
66 changes: 33 additions & 33 deletions frontend/src/component/LazyTable.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import { TableFooter, TablePagination, TableSortLabel } from '@mui/material';
import Stack from '@mui/material/Stack';
import Table from '@mui/material/Table';
import TableBody from '@mui/material/TableBody';
import TableCell from '@mui/material/TableCell';
Expand All @@ -18,17 +17,17 @@ export interface LazyTableProps<T> {
onSortOrderChanged: (order: Order) => void;
sortOrder: Order;
rows: T[];
showPager: boolean;
showPager?: boolean;
onRowsPerPagerChange?: React.ChangeEventHandler<
HTMLTextAreaElement | HTMLInputElement
>;
onPageChange?: (
event: React.MouseEvent<HTMLButtonElement> | null,
page: number
) => void;
page: number;
count: number;
rowsPerPage: RowsPerPage;
page?: number;
count?: number;
rowsPerPage?: RowsPerPage;
}

export interface TableBodyRows<T> {
Expand Down Expand Up @@ -89,16 +88,14 @@ export interface LazyTableHeaderProps<T> {
order: Order;
}

export const LazyTableHeader = <T,>(
{
columns,
bgColor,
sortColumn,
order,
onSortColumnChanged,
onSortOrderChanged
}: LazyTableHeaderProps<T>
) => {
export const LazyTableHeader = <T,>({
columns,
bgColor,
sortColumn,
order,
onSortColumnChanged,
onSortOrderChanged
}: LazyTableHeaderProps<T>) => {
return (
<TableHead>
<TableRow>
Expand Down Expand Up @@ -173,22 +170,20 @@ export const LazyTableHeader = <T,>(
);
};

export const LazyTable = <T,>(
{
columns,
sortOrder,
sortColumn,
rows,
onSortColumnChanged,
onSortOrderChanged,
onRowsPerPagerChange,
onPageChange,
showPager,
page,
count,
rowsPerPage
}: LazyTableProps<T>
) => {
export const LazyTable = <T,>({
columns,
sortOrder,
sortColumn,
rows,
onSortColumnChanged,
onSortOrderChanged,
onRowsPerPagerChange,
onPageChange,
showPager,
page,
count,
rowsPerPage
}: LazyTableProps<T>) => {
const theme = useTheme();

return (
Expand All @@ -203,10 +198,13 @@ export const LazyTable = <T,>(
onSortOrderChanged={onSortOrderChanged}
/>
<LazyTableBody rows={rows} columns={columns} />
{showPager && (
{showPager &&
page != undefined &&
count != undefined &&
rowsPerPage != undefined &&
onPageChange != undefined ? (
<TableFooter>
<TableRow>
{/*{showPager && <Stack direction={'row-reverse'}></Stack>}*/}
<TablePagination
page={page}
count={count}
Expand All @@ -218,6 +216,8 @@ export const LazyTable = <T,>(
/>
</TableRow>
</TableFooter>
) : (
<></>
)}
</Table>
</TableContainer>
Expand Down
22 changes: 10 additions & 12 deletions frontend/src/component/LazyTableSimple.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,15 @@ interface LazyTableSimpleProps<T> {
* Provides a slightly higher level "managed" table that can be used for simple use cases. If advanced filtering
* is required, you should use the LazyTable directly for more control.
*/
export const LazyTableSimple = <T,>(
{
fetchData,
columns,
defaultSortColumn,
defaultSortDir = 'desc',
paged = false,
showPager = true,
defaultRowsPerPage = RowsPerPage.TwentyFive
}: LazyTableSimpleProps<T>
) => {
export const LazyTableSimple = <T,>({
fetchData,
columns,
defaultSortColumn,
defaultSortDir = 'desc',
paged = false,
showPager = true,
defaultRowsPerPage = RowsPerPage.TwentyFive
}: LazyTableSimpleProps<T>) => {
const [data, setData] = useState<T[]>([]);
const [count, setCount] = useState(0);
const [loading, setLoading] = useState(false);
Expand Down Expand Up @@ -88,7 +86,7 @@ export const LazyTableSimple = <T,>(
);

const onPagerRowsChange = useCallback(
() => (_, newPage: number) => {
() => (_: never, newPage: number) => {
setPage(newPage);
},
[]
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/component/MapUsageContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const MapUseChart = ({ details }: MapUseChartProps) => {
<PieChart
height={600}
width={600}
legend={{ hidden: true }}
slotProps={{ legend: { hidden: true } }}
series={[
{
data: details,
Expand Down
36 changes: 35 additions & 1 deletion frontend/src/component/modal/ContestEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ interface ContestEditorFormValues {
contest_id: string;
title: string;
description: string;
hide_submissions: boolean;
public: boolean;
date_start: Date;
date_end: Date;
Expand All @@ -62,6 +63,7 @@ const validationSchema = yup.object({
max_submissions: numberValidator('Submissions'),
media_types: mimeTypesValidator(),
voting: boolDefinedValidator('Voting'),
hide_submissions: boolDefinedValidator('Hide Submissions'),
down_votes: boolDefinedValidator('Down votes'),
min_permission_level: permissionValidator()
});
Expand All @@ -88,6 +90,7 @@ export const ContestEditor = NiceModal.create(
public: contest?.public ?? false,
date_start: contest?.date_start ?? defaultStartDate,
date_end: contest?.date_end ?? defaultEndDate,
hide_submissions: contest?.hide_submissions ?? false,
max_submissions: contest?.max_submissions ?? 1,
media_types: contest?.media_types ?? '',
voting: contest?.voting ?? false,
Expand All @@ -110,6 +113,7 @@ export const ContestEditor = NiceModal.create(
date_start: values.date_start,
date_end: values.date_end,
description: values.description,
hide_submissions: values.hide_submissions,
title: values.title,
voting: values.voting,
down_votes: values.down_votes,
Expand Down Expand Up @@ -177,7 +181,11 @@ export const ContestEditor = NiceModal.create(
fullWidth
isReadOnly={false}
/>

<HideSubmissionsField
formik={formik}
fullWidth
isReadOnly={false}
/>
<MaxSubmissionsField
formik={formik}
fullWidth
Expand Down Expand Up @@ -372,6 +380,32 @@ const PublicField = ({
);
};

interface HideSubmissionsFieldInputValue {
hide_submissions: boolean;
}

const HideSubmissionsField = ({
formik,
isReadOnly
}: BaseFormikInputProps<HideSubmissionsFieldInputValue>) => {
return (
<FormGroup>
<FormControlLabel
control={
<Checkbox
id={'hide_submissions-cb'}
disabled={isReadOnly ?? false}
value={formik.values.hide_submissions}
onChange={formik.handleChange}
onBlur={formik.handleBlur}
/>
}
label="Hide Submissions"
/>
</FormGroup>
);
};

interface VotingInputValue {
voting: boolean;
}
Expand Down
1 change: 1 addition & 0 deletions frontend/src/page/ContestListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const ContestListPage = () => {
<Grid xs={12}>
<LazyTableSimple<Contest>
fetchData={apiContests}
showPager={true}
columns={[
{
sortKey: 'title',
Expand Down
94 changes: 54 additions & 40 deletions frontend/src/page/ContestPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,50 +133,64 @@ export const ContestPage = () => {
</Stack>
</ContainerWithHeader>
</Grid>
<Grid xs={12}>
<Stack spacing={2}>
{entries.map((value) => {
return (
<Stack key={value.contest_entry_id}>
<Paper elevation={2}>
<Stack direction={'row'}>
<Avatar
alt={value.personaname}
src={`https://avatars.akamai.steamstatic.com/${defaultAvatarHash}.jpg`}
variant={'square'}
sx={{
height: '128px',
width: '128px',
padding: 2
}}
/>
{contest.hide_submissions ? (
<Grid xs={12}>
<Paper>
<Typography
variant={'subtitle1'}
align={'center'}
padding={4}
>
Entries are hidden until contest has expired.
</Typography>
</Paper>
</Grid>
) : (
<Grid xs={12}>
<Stack spacing={2}>
{entries.map((value) => {
return (
<Stack key={value.contest_entry_id}>
<Paper elevation={2}>
<Stack direction={'row'}>
<Avatar
alt={value.personaname}
src={`https://avatars.akamai.steamstatic.com/${defaultAvatarHash}.jpg`}
variant={'square'}
sx={{
height: '128px',
width: '128px',
padding: 2
}}
/>

<Grid container>
<Grid xs={8} padding={2}>
<Typography
variant={'body1'}
>
{value.description}
</Typography>
<Grid container>
<Grid xs={8} padding={2}>
<Typography
variant={'body1'}
>
{value.description}
</Typography>
</Grid>
</Grid>
</Grid>
</Stack>
</Paper>
<Stack direction={'row'}>
<ButtonGroup fullWidth>
<IconButton color={'success'}>
<ThumbUpIcon />
</IconButton>
<IconButton color={'error'}>
<ThumbDownIcon />
</IconButton>
</ButtonGroup>
</Stack>
</Paper>
<Stack direction={'row'}>
<ButtonGroup fullWidth>
<IconButton color={'success'}>
<ThumbUpIcon />
</IconButton>
<IconButton color={'error'}>
<ThumbDownIcon />
</IconButton>
</ButtonGroup>
</Stack>
</Stack>
);
})}
</Stack>
</Grid>
);
})}
</Stack>
</Grid>
)}
</Grid>
)
);
Expand Down
2 changes: 2 additions & 0 deletions internal/app/http_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,8 @@ func authMiddleware(app *App, level consts.Privilege) gin.HandlerFunc {
BanID: bannedPerson.Ban.BanID,
}
ctx.Set(ctxKeyUserProfile, profile)
} else {
ctx.Set(ctxKeyUserProfile, userProfile{PermissionLevel: consts.PGuest, Name: "Guest"})
}

ctx.Next()
Expand Down
Loading

0 comments on commit ebcda64

Please sign in to comment.