From e13671f885c7b16257f6b15aeaff3b3c68082438 Mon Sep 17 00:00:00 2001 From: Mateusz Tylka Date: Tue, 4 Apr 2023 10:51:20 +0200 Subject: [PATCH] refactor: CHALLENGE_SECTIONS ENUM --- .env | 2 +- src/App.js | 15 +- .../specific_challenge/Challenge.js | 14 +- .../DesktopChallengeMenu.js | 1 + src/components/specific_challenge/Readme.js | 218 ++++++++---------- src/utils/globals.js | 10 + 6 files changed, 124 insertions(+), 136 deletions(-) diff --git a/.env b/.env index 9a7fd9a..be54f10 100644 --- a/.env +++ b/.env @@ -2,4 +2,4 @@ REACT_APP_KC_URL=https://auth-dev.csi.wmi.amu.edu.pl/ REACT_APP_KC_REALM=gonito-dev REACT_APP_KC_CLIENT_ID=gonito-dev-localhost -REACT_APP_API=https://gonito-back-dev.csi.wmi.amu.edu.pl/api \ No newline at end of file +REACT_APP_API=https://gonito.net/api \ No newline at end of file diff --git a/src/App.js b/src/App.js index 0016df7..b0eb553 100644 --- a/src/App.js +++ b/src/App.js @@ -11,6 +11,7 @@ import { POLICY_PRIVACY_PAGE, LOGIN_REQUIRED_PAGES, ROOT_URL, + CHALLENGE_SECTIONS, } from './utils/globals'; import KeyCloakService from './services/KeyCloakService'; import React from 'react'; @@ -121,36 +122,36 @@ const App = () => { } + element={} /> } + element={} /> } + element={} /> } + element={} /> } /> } + element={} /> } + element={} /> } /> { const sectionRender = () => { switch (props.section) { - case 0: + case CHALLENGE_SECTIONS.LEADERBOARD: return ( { user={user} /> ); - case 1: + case CHALLENGE_SECTIONS.ALL_ENTRIES: return ( ); - case 2: + case CHALLENGE_SECTIONS.README: return ( { deadline={challenge.deadline} /> ); - case 3: + case CHALLENGE_SECTIONS.HOW_TO: return ( { user={user} /> ); - case 4: + case CHALLENGE_SECTIONS.MY_ENTRIES: return ; - case 5: + case CHALLENGE_SECTIONS.SUBMIT: return ; default: return ( diff --git a/src/components/specific_challenge/DesktopChallengeMenu.js b/src/components/specific_challenge/DesktopChallengeMenu.js index 3db9579..44dc769 100644 --- a/src/components/specific_challenge/DesktopChallengeMenu.js +++ b/src/components/specific_challenge/DesktopChallengeMenu.js @@ -27,6 +27,7 @@ const Option = styled(FlexColumn)` cursor: pointer; background-color: ${({ theme, active }) => active ? theme.colors.green05 : theme.colors.white}; + text-decoration: none; * { cursor: pointer; diff --git a/src/components/specific_challenge/Readme.js b/src/components/specific_challenge/Readme.js index 70b54f4..cac39d9 100644 --- a/src/components/specific_challenge/Readme.js +++ b/src/components/specific_challenge/Readme.js @@ -1,10 +1,9 @@ import React from 'react'; -import {FlexColumn} from '../../utils/containers'; -import {Body, H2} from '../../utils/fonts'; +import { FlexColumn } from '../../utils/containers'; +import { Body, H2 } from '../../utils/fonts'; import Media from 'react-media'; import theme from '../../utils/theme'; import getChallengeFullDescription from '../../api/getChallengeFullDescription'; -// import {markdown} from 'markdown'; import styled from 'styled-components'; import InfoList from '../generic/InfoList'; import Loading from '../generic/Loading'; @@ -29,7 +28,7 @@ const ReadmeStyle = styled(Body)` line-height: 22px; margin: 24px 0; - @media (min-width: ${({theme}) => theme.overMobile}) { + @media (min-width: ${({ theme }) => theme.overMobile}) { font-size: 22px; line-height: 26px; } @@ -41,7 +40,7 @@ const ReadmeStyle = styled(Body)` font-size: 14px; line-height: 20px; - @media (min-width: ${({theme}) => theme.overMobile}) { + @media (min-width: ${({ theme }) => theme.overMobile}) { font-weight: 400; font-size: 16px; line-height: 22px; @@ -53,10 +52,10 @@ const ReadmeStyle = styled(Body)` font-weight: 400; font-size: 14px; line-height: 20px; - color: ${({theme}) => theme.colors.dark}; + color: ${({ theme }) => theme.colors.dark}; text-decoration: none; - @media (min-width: ${({theme}) => theme.overMobile}) { + @media (min-width: ${({ theme }) => theme.overMobile}) { font-size: 16px; line-height: 22px; font-weight: 500; @@ -65,127 +64,104 @@ const ReadmeStyle = styled(Body)` `; const Readme = (props) => { - const [fullDescription, setFullDescription] = React.useState(''); - const [loading, setLoading] = React.useState(true); + const [fullDescription, setFullDescription] = React.useState(''); + const [loading, setLoading] = React.useState(true); - React.useEffect(() => { - getChallengeFullDescription(setFullDescription, setLoading, props.challengeName); - }, [props.challengeName]); - - const parseMarkdownResponse = (response) => { - let result = marked.parse(response); - let regex = /

/g; - result = result.replace(regex, '

'); - regex = /

/g; - result = result.replace(regex, '

'); - regex = /

/g; - result = result.replace(regex, '

'); - return result; - }; - - const mobileRender = () => { - return ( - - -

- Info -

- -
- - {/*

- Description -

*/} - -
- {/* -

- Baseline -

- - - In metus ex, venenatis quis risus eget, sodales venenatis nibh. Sed ullamcorper leo non nunc - euismod, id faucibus justo finibus. Nullam malesuada eros quam, eu lobortis leo feugiat non. - - - See notebook  - - here. - - - -
*/} -
- ); - }; - - const desktopRender = () => { - return ( - - -

- Info -

- -
- - {/*

- Description -

*/} - -
- {/* -

- Baseline -

- - - In metus ex, venenatis quis risus eget, sodales venenatis nibh. Sed ullamcorper leo non nunc - euismod, id faucibus justo finibus. Nullam malesuada eros quam, eu lobortis leo feugiat non. - - - See notebook  - - here. - - - -
*/} -
- ); - }; - - return ( - <> - - {!loading ? mobileRender() : } - - - {!loading ? desktopRender() : } - - + React.useEffect(() => { + getChallengeFullDescription( + setFullDescription, + setLoading, + props.challengeName ); + }, [props.challengeName]); + + const parseMarkdownResponse = (response) => { + let result = marked.parse(response); + let regex = /

/g; + result = result.replace(regex, '

'); + regex = /

/g; + result = result.replace(regex, '

'); + regex = /

/g; + result = result.replace(regex, '

'); + return result; + }; + + const mobileRender = () => { + return ( + + +

Info

+ +
+ + + +
+ ); + }; + + const desktopRender = () => { + return ( + + +

Info

+ +
+ + + +
+ ); + }; + + return ( + <> + + {!loading ? mobileRender() : } + + + {!loading ? desktopRender() : } + + + ); }; MiniChallenge.propTypes = { - challengeName: PropsTypes.string, - description: PropsTypes.string, + challengeName: PropsTypes.string, + description: PropsTypes.string, }; MiniChallenge.defaultProps = { - challengeName: '', - description: '', + challengeName: '', + description: '', }; -export default Readme; \ No newline at end of file +export default Readme; diff --git a/src/utils/globals.js b/src/utils/globals.js index a885d87..a408516 100644 --- a/src/utils/globals.js +++ b/src/utils/globals.js @@ -18,6 +18,15 @@ const ROOT_URL = window.location.origin; const LOGIN_REQUIRED_PAGES = ['myentries', 'submit']; +const CHALLENGE_SECTIONS = { + LEADERBOARD: 0, + ALL_ENTRIES: 1, + README: 2, + HOW_TO: 3, + MY_ENTRIES: 4, + SUBMIT: 5, +}; + const MINI_DESCRIPTION_RENDER = (description) => { if (description) { if (description.length <= MINI_DESCRIPTION_LENGTH) return description; @@ -86,6 +95,7 @@ export { POLICY_PRIVACY_PAGE, ROOT_URL, LOGIN_REQUIRED_PAGES, + CHALLENGE_SECTIONS, MINI_DESCRIPTION_RENDER, RENDER_ICO, CALC_PAGES,