From c1170dc1a38a5b303eccd6af5b5b0a2570394c61 Mon Sep 17 00:00:00 2001 From: Abdulhakeem Abdulazeez Date: Sat, 20 Apr 2024 17:02:26 +0100 Subject: [PATCH 1/2] feat: track time left in day --- frontend/src/App.js | 29 +++++++++++++++++++++++++++-- frontend/src/tabs/TabPanel.js | 16 ++++++++++------ 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/frontend/src/App.js b/frontend/src/App.js index ce387b3e..43656ad4 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import { useMediaQuery } from 'react-responsive' import './App.css'; import Canvas from './canvas/Canvas.js'; @@ -52,6 +52,31 @@ function App() { setPixelSelectedMode(true); } + const [timeLeftInDay, setTimeLeftInDay] = useState(''); + const startTime = "15:00"; + const [hours, minutes] = startTime.split(":"); + + + useEffect(() => { + const calculateTimeLeft = () => { + const now = new Date(); + const nextDayStart = new Date(now); + nextDayStart.setDate(now.getDate() + 1); + nextDayStart.setUTCHours(parseInt(hours), parseInt(minutes), 0, 0); + + const difference = nextDayStart - now; + const hoursFinal = Math.floor((difference / (1000 * 60 * 60)) % 24); + const minutesFinal = Math.floor((difference / 1000 / 60) % 60); + const secondsFinal = Math.floor((difference / 1000) % 60); + + const formattedTimeLeft = `${hoursFinal.toString().padStart(2, '0')}:${minutesFinal.toString().padStart(2, '0')}:${secondsFinal.toString().padStart(2, '0')}`; + setTimeLeftInDay(formattedTimeLeft); + }; + + const interval = setInterval(calculateTimeLeft, 1000); + return () => clearInterval(interval); + }) + // Tabs const tabs = ['Canvas', 'Quests', 'Vote', 'Templates', 'NFTs', 'Account']; const [activeTab, setActiveTab] = useState(tabs[0]); @@ -66,7 +91,7 @@ function App() { { (!isPortrait ? pixelSelectedMode : pixelSelectedMode && activeTab === tabs[0]) && ( )} - +
diff --git a/frontend/src/tabs/TabPanel.js b/frontend/src/tabs/TabPanel.js index b68f49a1..9d569559 100644 --- a/frontend/src/tabs/TabPanel.js +++ b/frontend/src/tabs/TabPanel.js @@ -9,12 +9,16 @@ import Account from './Account.js'; const TabPanel = props => { return ( -
- { props.activeTab === 'Quests' && } - { props.activeTab === 'Vote' && } - { props.activeTab === 'Templates' && } - { props.activeTab === 'NFTs' && } - { props.activeTab === 'Account' && } +
+ {props.activeTab === "Quests" && ( + + )} + {props.activeTab === "Vote" && ( + + )} + {props.activeTab === "Templates" && } + {props.activeTab === "NFTs" && } + {props.activeTab === "Account" && }
); } From bc75456b09547dd554ae774cf563550d66f8a18a Mon Sep 17 00:00:00 2001 From: Brandon Roberts Date: Mon, 22 Apr 2024 10:19:32 -0500 Subject: [PATCH 2/2] Display time --- frontend/src/tabs/Voting.js | 32 +----------------------------- frontend/src/tabs/quests/Quests.js | 2 +- 2 files changed, 2 insertions(+), 32 deletions(-) diff --git a/frontend/src/tabs/Voting.js b/frontend/src/tabs/Voting.js index 96842f59..8af9adf9 100644 --- a/frontend/src/tabs/Voting.js +++ b/frontend/src/tabs/Voting.js @@ -11,42 +11,12 @@ const Voting = props => { const [votes, setVotes] = useState(colorVotes); const [userVote, setUserVote] = useState(-1); // TODO: Pull from API - const timeTillVote = '05:14:23'; - const [time, setTime] = useState(timeTillVote); - - useEffect(() => { - const interval = setInterval(() => { - setTime(time => { - let timeSplit = time.split(':'); - let hours = parseInt(timeSplit[0]); - let minutes = parseInt(timeSplit[1]); - let seconds = parseInt(timeSplit[2]); - if (seconds === 0) { - if (minutes === 0) { - if (hours === 0) { - return '00:00:00'; - } - hours--; - minutes = 59; - seconds = 59; - } else { - minutes--; - seconds = 59; - } - } else { - seconds--; - } - return `${hours < 10 ? '0' + hours : hours}:${minutes < 10 ? '0' + minutes : minutes}:${seconds < 10 ? '0' + seconds : seconds}`; - }); - }, 1000); - return () => clearInterval(interval); - }, [time]); return (

Color Vote

Vote for a new palette color.

-

Vote closes: {time}

+

Vote closes: {props.timeLeftInDay}

Vote
diff --git a/frontend/src/tabs/quests/Quests.js b/frontend/src/tabs/quests/Quests.js index ca9a1bc6..de29e9ca 100644 --- a/frontend/src/tabs/quests/Quests.js +++ b/frontend/src/tabs/quests/Quests.js @@ -56,7 +56,7 @@ const Quests = props => {

Dailys

-

XX:XX:XX

+

{props.timeLeftInDay}

{dailyQuests.map((quest, index) => (