-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1522 from vinaybadgujar102/focus_mode
Focus mode
- Loading branch information
Showing
9 changed files
with
224 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import { useRecoilValue } from "recoil"; | ||
import { darkModeState, currentScheduledTask, focusTaskTitle } from "@src/store"; | ||
import { Progress } from "antd"; | ||
|
||
import "./focus.scss"; | ||
import { formatTimeDisplay } from "@src/utils"; | ||
|
||
export const Focus = () => { | ||
const darkModeStatus = useRecoilValue(darkModeState); | ||
|
||
const [initialTime, setInitialTime] = useState(25 * 60); | ||
const [time, setTime] = useState<number>(initialTime); | ||
const [isTimerActive, setIsTimerActive] = useState<boolean>(false); | ||
const [editMode, setEditMode] = useState<boolean>(false); | ||
const [userEnteredTime, setUserEnteredTime] = useState<string>(""); | ||
const taskTitle = useRecoilValue(focusTaskTitle); | ||
const isActiveTitle = useRecoilValue(currentScheduledTask); | ||
|
||
useEffect(() => { | ||
let interval; | ||
if (isTimerActive && time > 0) { | ||
interval = setInterval(() => { | ||
setTime((prevTime) => prevTime - 1); | ||
}, 1000); | ||
} else if (!isTimerActive && time !== 0) { | ||
clearInterval(interval!); | ||
} | ||
return () => clearInterval(interval!); | ||
}, [isTimerActive, time]); | ||
|
||
const toggle = () => { | ||
setIsTimerActive(!isTimerActive); | ||
}; | ||
const reset = () => { | ||
const resetTime = initialTime; | ||
setTime(resetTime); | ||
setIsTimerActive(false); | ||
}; | ||
|
||
const percentage = ((initialTime - time) / initialTime) * 100; | ||
const { minutes, seconds } = formatTimeDisplay(time); | ||
|
||
const handleEditClick = () => { | ||
setEditMode(!editMode); | ||
}; | ||
|
||
const handleSaveClick = () => { | ||
const newTimeInSeconds = parseInt(userEnteredTime, 10) * 60; | ||
if (!Number.isNaN(newTimeInSeconds)) { | ||
setInitialTime(newTimeInSeconds); | ||
setTime(newTimeInSeconds); | ||
setEditMode(false); | ||
} else setEditMode(false); | ||
}; | ||
|
||
return ( | ||
<div className="focus"> | ||
<h6>{isActiveTitle === "" ? taskTitle : isActiveTitle}</h6> | ||
<Progress | ||
className={`progress-${darkModeStatus ? "dark" : ""}`} | ||
size={200} | ||
strokeColor="var(--icon-grad-2)" | ||
trailColor={darkModeStatus ? "#7e7e7e" : "var(--secondary-background)"} | ||
type="circle" | ||
percent={percentage} | ||
success={{ percent: 0, strokeColor: darkModeStatus ? "white" : "black" }} | ||
format={() => { | ||
if (minutes >= 1) { | ||
return `${minutes} min`; | ||
} | ||
return `${seconds} sec`; | ||
}} | ||
/> | ||
{editMode ? ( | ||
<div style={{ display: "flex", flexDirection: "column", alignItems: "center" }}> | ||
<input | ||
className="default-input" | ||
style={{ textAlign: "center", maxWidth: 100 }} | ||
placeholder="minutes" | ||
value={userEnteredTime} | ||
onChange={(e) => setUserEnteredTime(e.target.value)} | ||
/> | ||
<button className="action-btn" type="button" onClick={handleSaveClick}> | ||
Save | ||
</button> | ||
</div> | ||
) : ( | ||
<div style={{ display: "flex", gap: "10px" }}> | ||
<button className="action-btn" type="button" onClick={toggle}> | ||
{isTimerActive ? "Pause" : "Start"} | ||
</button> | ||
<button className="action-btn" type="button" onClick={reset}> | ||
Reset | ||
</button> | ||
{time === initialTime && !isTimerActive && ( | ||
<button className="action-btn" type="button" onClick={handleEditClick}> | ||
Edit Time | ||
</button> | ||
)} | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
.focus { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
margin-top: 20px; | ||
gap: 25px; | ||
} | ||
|
||
.timer { | ||
font-size: 2em; | ||
color: #333; | ||
width: 200px; | ||
height: 200px; | ||
border-radius: 50%; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
background-color: #fff; | ||
position: relative; | ||
|
||
.timer-fill { | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
border-radius: 50%; | ||
background-color: #333; | ||
transform-origin: left center; | ||
transform: scaleX(0); /* Initial width of 0 */ | ||
transition: transform 1s linear; | ||
} | ||
|
||
.timer-text { | ||
z-index: 1; | ||
} | ||
} | ||
|
||
.start-button { | ||
margin-top: 2em; | ||
padding: 1em 2em; | ||
font-size: 1em; | ||
color: #fff; | ||
background-color: #007bff; | ||
border: none; | ||
border-radius: 5px; | ||
cursor: pointer; | ||
|
||
&:hover { | ||
background-color: #0056b3; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,3 +81,11 @@ | |
color: white !important; | ||
} | ||
} | ||
|
||
/*ProgressBar*/ | ||
.progress-dark { | ||
.ant-progress-text { | ||
color: white!important; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30fadc9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
zinzen – ./
zinzen-git-main-tijlleenders.vercel.app
zinzen-tijlleenders.vercel.app
zinzen.vercel.app