From 8d1bdafcb123e03f429d6e47f7ac440a4eabb554 Mon Sep 17 00:00:00 2001 From: John Kaster Date: Mon, 8 Nov 2021 20:32:00 +0000 Subject: [PATCH 1/6] feat: lock "Add Project" when judging starts --- .../src/scenes/HomeScene/HomeScene.tsx | 2 +- .../scenes/ProjectsScene/ProjectsScene.tsx | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/hackathon/src/scenes/HomeScene/HomeScene.tsx b/packages/hackathon/src/scenes/HomeScene/HomeScene.tsx index c52d85f36..f7da14e7b 100644 --- a/packages/hackathon/src/scenes/HomeScene/HomeScene.tsx +++ b/packages/hackathon/src/scenes/HomeScene/HomeScene.tsx @@ -53,7 +53,7 @@ export const HomeScene: FC = ({ hacker }) => { diff --git a/packages/hackathon/src/scenes/ProjectsScene/ProjectsScene.tsx b/packages/hackathon/src/scenes/ProjectsScene/ProjectsScene.tsx index e3632c5a9..cb261b59b 100644 --- a/packages/hackathon/src/scenes/ProjectsScene/ProjectsScene.tsx +++ b/packages/hackathon/src/scenes/ProjectsScene/ProjectsScene.tsx @@ -25,7 +25,7 @@ */ import type { FC } from 'react' -import React from 'react' +import React, { useEffect, useState } from 'react' import { useSelector, useDispatch } from 'react-redux' import { useHistory } from 'react-router-dom' import { Button, Space, Heading } from '@looker/components' @@ -50,6 +50,7 @@ export const ProjectsScene: FC = () => { const hackathon = useSelector(getCurrentHackathonState) const isLoading = useSelector(isLoadingState) const history = useHistory() + const [judgingStarted, setJudgingStarted] = useState(true) const handleAdd = () => { history.push(Routes.CREATE_PROJECT) @@ -63,6 +64,16 @@ export const ProjectsScene: FC = () => { if (hackathon) dispatch(lockProjects(false, hackathon._id)) } + useEffect(() => { + if (hackathon) { + setJudgingStarted( + hackathon.judging_starts?.getTime() < new Date().getTime() + ) + } else { + setJudgingStarted(false) + } + }, [hackathon]) + return ( <> @@ -73,7 +84,11 @@ export const ProjectsScene: FC = () => { - <> From 16b7503686da2e6fd81a242f6ef31a6ea0b5f07d Mon Sep 17 00:00:00 2001 From: John Kaster Date: Mon, 8 Nov 2021 21:08:38 +0000 Subject: [PATCH 2/6] refining add project disabling rules --- .../HomeScene/components/agendaUtils.ts | 18 +++++++++++- .../scenes/ProjectsScene/ProjectsScene.tsx | 29 ++++++++++++++----- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/packages/hackathon/src/scenes/HomeScene/components/agendaUtils.ts b/packages/hackathon/src/scenes/HomeScene/components/agendaUtils.ts index 559427a27..ce87d41ac 100644 --- a/packages/hackathon/src/scenes/HomeScene/components/agendaUtils.ts +++ b/packages/hackathon/src/scenes/HomeScene/components/agendaUtils.ts @@ -73,11 +73,27 @@ export const dateLocale = (locale: string) => (locale === 'ja_JP' ? ja : enUS) export const dateString = ( value: AgendaTime, locale: string, - template = 'LLL' + template = 'PPpp' ) => { return format(value, template, { locale: dateLocale(locale) }) } +/** + * Localized, zoned time + * @param value to zone and localize + * @param zone to use + * @param locale to use + * @param template override for dateString() + */ +export const zonedLocaleDate = ( + value: AgendaTime, + zone: string, + locale: string, + template = 'PPpp' +) => { + return dateString(zoneDate(value, zone), locale, template) +} + /** * Display the Month abbreviation and nth day * @param date to display diff --git a/packages/hackathon/src/scenes/ProjectsScene/ProjectsScene.tsx b/packages/hackathon/src/scenes/ProjectsScene/ProjectsScene.tsx index cb261b59b..90a4a1fea 100644 --- a/packages/hackathon/src/scenes/ProjectsScene/ProjectsScene.tsx +++ b/packages/hackathon/src/scenes/ProjectsScene/ProjectsScene.tsx @@ -28,18 +28,20 @@ import type { FC } from 'react' import React, { useEffect, useState } from 'react' import { useSelector, useDispatch } from 'react-redux' import { useHistory } from 'react-router-dom' -import { Button, Space, Heading } from '@looker/components' +import { Button, Space, Heading, Span } from '@looker/components' import { Add } from '@styled-icons/material-outlined/Add' import { Create } from '@styled-icons/material-outlined/Create' import { Lock } from '@styled-icons/material-outlined/Lock' import { lockProjects } from '../../data/projects/actions' import { isLoadingState } from '../../data/common/selectors' import { Loading } from '../../components' -import { Routes } from '../../routes/AppRouter' +import { Routes } from '../../routes' import { getCurrentHackathonState, getHackerState, } from '../../data/hack_session/selectors' +import { canLockProject } from '../../utils' +import { Era, eraColor, zonedLocaleDate } from '../HomeScene/components' import { ProjectList } from './components' interface ProjectSceneProps {} @@ -51,6 +53,7 @@ export const ProjectsScene: FC = () => { const isLoading = useSelector(isLoadingState) const history = useHistory() const [judgingStarted, setJudgingStarted] = useState(true) + const [judgingStarts, setJudgingStarts] = useState('') const handleAdd = () => { history.push(Routes.CREATE_PROJECT) @@ -65,14 +68,21 @@ export const ProjectsScene: FC = () => { } useEffect(() => { - if (hackathon) { - setJudgingStarted( - hackathon.judging_starts?.getTime() < new Date().getTime() + if (hackathon && hacker) { + const started = hackathon.judging_starts?.getTime() < new Date().getTime() + setJudgingStarts( + `Judging start${started ? 'ed' : 's'} ${zonedLocaleDate( + hackathon.judging_starts, + hacker.timezone, + hacker.locale + )}` ) + setJudgingStarted(started) } else { + setJudgingStarts('') setJudgingStarted(false) } - }, [hackathon]) + }, [hackathon, hacker]) return ( <> @@ -84,10 +94,15 @@ export const ProjectsScene: FC = () => { + {judgingStarted && ( + + {judgingStarts} + + )} From 066295be005f5a79419bb0f0841dfcecdb3b1f16 Mon Sep 17 00:00:00 2001 From: John Kaster Date: Mon, 8 Nov 2021 23:21:25 +0000 Subject: [PATCH 3/6] always show judging start time --- packages/hackathon/src/scenes/ProjectsScene/ProjectsScene.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/hackathon/src/scenes/ProjectsScene/ProjectsScene.tsx b/packages/hackathon/src/scenes/ProjectsScene/ProjectsScene.tsx index 90a4a1fea..91f806850 100644 --- a/packages/hackathon/src/scenes/ProjectsScene/ProjectsScene.tsx +++ b/packages/hackathon/src/scenes/ProjectsScene/ProjectsScene.tsx @@ -71,7 +71,7 @@ export const ProjectsScene: FC = () => { if (hackathon && hacker) { const started = hackathon.judging_starts?.getTime() < new Date().getTime() setJudgingStarts( - `Judging start${started ? 'ed' : 's'} ${zonedLocaleDate( + `Judging start${started ? 'ed' : 's'}: ${zonedLocaleDate( hackathon.judging_starts, hacker.timezone, hacker.locale @@ -94,7 +94,7 @@ export const ProjectsScene: FC = () => { - {judgingStarted && ( + {!!judgingStarts && ( {judgingStarts} From e82868b75a8db9d2802543b9b2847085ffea8da5 Mon Sep 17 00:00:00 2001 From: John Kaster Date: Tue, 9 Nov 2021 17:11:46 +0000 Subject: [PATCH 4/6] cleaner project scene courtesy of Jeremy --- .../scenes/ProjectsScene/ProjectsScene.tsx | 41 +++++++++---------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/packages/hackathon/src/scenes/ProjectsScene/ProjectsScene.tsx b/packages/hackathon/src/scenes/ProjectsScene/ProjectsScene.tsx index 91f806850..b316d7816 100644 --- a/packages/hackathon/src/scenes/ProjectsScene/ProjectsScene.tsx +++ b/packages/hackathon/src/scenes/ProjectsScene/ProjectsScene.tsx @@ -25,7 +25,7 @@ */ import type { FC } from 'react' -import React, { useEffect, useState } from 'react' +import React from 'react' import { useSelector, useDispatch } from 'react-redux' import { useHistory } from 'react-router-dom' import { Button, Space, Heading, Span } from '@looker/components' @@ -52,8 +52,6 @@ export const ProjectsScene: FC = () => { const hackathon = useSelector(getCurrentHackathonState) const isLoading = useSelector(isLoadingState) const history = useHistory() - const [judgingStarted, setJudgingStarted] = useState(true) - const [judgingStarts, setJudgingStarts] = useState('') const handleAdd = () => { history.push(Routes.CREATE_PROJECT) @@ -67,22 +65,23 @@ export const ProjectsScene: FC = () => { if (hackathon) dispatch(lockProjects(false, hackathon._id)) } - useEffect(() => { - if (hackathon && hacker) { - const started = hackathon.judging_starts?.getTime() < new Date().getTime() - setJudgingStarts( - `Judging start${started ? 'ed' : 's'}: ${zonedLocaleDate( - hackathon.judging_starts, - hacker.timezone, - hacker.locale - )}` - ) - setJudgingStarted(started) + let judgingStarted = false + let judgingString = '' + if (hackathon && hacker) { + judgingStarted = hackathon.judging_starts?.getTime() < new Date().getTime() + + const dateString = zonedLocaleDate( + hackathon.judging_starts, + hacker.timezone, + hacker.locale + ) + + if (judgingStarted) { + judgingString = `Judging started: ${dateString}` } else { - setJudgingStarts('') - setJudgingStarted(false) + judgingString = `Judging starts: ${dateString}` } - }, [hackathon, hacker]) + } return ( <> @@ -94,11 +93,6 @@ export const ProjectsScene: FC = () => { - {!!judgingStarts && ( - - {judgingStarts} - - )}