Skip to content

Commit

Permalink
Merge pull request #365 from rissois/voteprompt
Browse files Browse the repository at this point in the history
Accordion display of voting prompt (useful for voting)
  • Loading branch information
heshammourad authored Sep 30, 2024
2 parents a37c639 + c9b4dc9 commit 998b376
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
33 changes: 31 additions & 2 deletions react-ui/src/pages/contest/Contest.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
/**
* Voting and winners
*/

import Accordion from '@material-ui/core/Accordion';
import AccordionDetails from '@material-ui/core/AccordionDetails';
import AccordionSummary from '@material-ui/core/AccordionSummary';
import Box from '@material-ui/core/Box';
import CircularProgress from '@material-ui/core/CircularProgress';
import Typography from '@material-ui/core/Typography';
import { makeStyles } from '@material-ui/core/styles';
import ExpandMore from '@material-ui/icons/ExpandMore';
import clsx from 'clsx';
import { useState, useEffect, useCallback } from 'react';
import { forceCheck } from 'react-lazyload';
Expand All @@ -14,6 +17,7 @@ import { animateScroll } from 'react-scroll';

import {
EntryDescriptionDrawer,
FormattedContent,
PageContainer,
PageWithDrawer,
RedditLogInDialog,
Expand Down Expand Up @@ -46,6 +50,10 @@ const useStyles = makeStyles((theme) => ({
icon: {
color: theme.palette.grey[700],
},
prompt: {
backgroundColor: theme.palette.grey[200],
marginBottom: '20px',
},
}));

function Contest() {
Expand All @@ -60,6 +68,7 @@ function Contest() {
const [selectedCategories, setSelectedCategories] = useState(
state?.selectedCategories ?? [],
);
const [isPromptOpen, setIsPromptOpen] = useState(false);
const [isDrawerOpen, setIsDrawerOpen] = useState(false);
const [drawerEntryId, setDrawerEntryId] = useState(null);

Expand Down Expand Up @@ -93,6 +102,10 @@ function Contest() {
window.location.reload();
}, []);

const togglePromptOpen = useCallback(() => {
setIsPromptOpen((prev) => !prev);
}, []);

const toggleDrawerOpen = useCallback((isOpen) => {
setDrawerEntryId(null);
setIsDrawerOpen(isOpen);
Expand Down Expand Up @@ -166,7 +179,7 @@ function Contest() {
const { headingVariant } = useContestSizing();

const {
categories, isContestMode, name, votingWindowOpen, winners,
categories, isContestMode, name, votingWindowOpen, winners, prompt,
} = contest;

// Prevents display of stale, cached data
Expand Down Expand Up @@ -222,6 +235,22 @@ function Contest() {
>
{name}
</Typography>

<Accordion
className={classes.prompt}
expanded={isPromptOpen}
onChange={togglePromptOpen}
>
<AccordionSummary expandIcon={<ExpandMore />}>
{isPromptOpen ? 'Hide' : 'View'}
{' '}
contest prompt
</AccordionSummary>
<AccordionDetails onClick={togglePromptOpen} style={{ cursor: 'pointer' }}>
<FormattedContent content={prompt} markdown />
</AccordionDetails>
</Accordion>

{votingWindowOpen === false && (
<ContestUnderReview {...{ isValidating, mutate }} />
)}
Expand Down
4 changes: 2 additions & 2 deletions react-ui/src/pages/home/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ function Home() {
, check out
{' '}
<InternalLink to="/contests">older contests</InternalLink>
, or view
the
, or view the
{' '}
<InternalLink to="/hallOfFame">Hall of Fame</InternalLink>
.
</p>
Expand Down
3 changes: 3 additions & 0 deletions server/api/contest.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ exports.get = async ({ params: { id }, username }, res) => {
date,
local_voting,
name,
prompt,
submission_end,
submission_start,
subtext,
Expand All @@ -108,6 +109,7 @@ exports.get = async ({ params: { id }, username }, res) => {
date,
localVoting,
name,
prompt,
submissionEnd,
submissionStart,
subtext,
Expand All @@ -120,6 +122,7 @@ exports.get = async ({ params: { id }, username }, res) => {
isContestMode: false,
localVoting,
name,
prompt,
requestId: uuidv4(),
submissionEnd,
submissionStart,
Expand Down

0 comments on commit 998b376

Please sign in to comment.