mirror of
https://github.com/FranP-code/Pomodoro-Timer-with-Clockify-integration.git
synced 2025-10-12 23:52:30 +00:00
Added random title for Work and Rest periods
This commit is contained in:
@@ -32,7 +32,7 @@
|
|||||||
work correctly both with client-side routing and a non-root public URL.
|
work correctly both with client-side routing and a non-root public URL.
|
||||||
Learn how to configure a non-root public URL by running `npm run build`.
|
Learn how to configure a non-root public URL by running `npm run build`.
|
||||||
-->
|
-->
|
||||||
<title>Pomodoro Timer</title>
|
<title>Clockify Pomodoro Timer</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import React, {useState} from 'react'
|
|||||||
|
|
||||||
import uploadToClockifyTimer from '../Clockify/uploadToClockifyTimer'
|
import uploadToClockifyTimer from '../Clockify/uploadToClockifyTimer'
|
||||||
import getAndFormatCurrentTime from '../Clockify/getAndFormatCurrentTime'
|
import getAndFormatCurrentTime from '../Clockify/getAndFormatCurrentTime'
|
||||||
|
import randomText from '../Misc/randomText'
|
||||||
|
|
||||||
const MainPomodoroTimer = (props) => {
|
const MainPomodoroTimer = (props) => {
|
||||||
|
|
||||||
@@ -230,13 +231,16 @@ const MainPomodoroTimer = (props) => {
|
|||||||
|
|
||||||
if (!weAreInBreakTime) {
|
if (!weAreInBreakTime) {
|
||||||
|
|
||||||
|
|
||||||
getFavicon().href = './img/working favicon.ico'
|
getFavicon().href = './img/working favicon.ico'
|
||||||
|
|
||||||
if (!alreadyCountingStart) {
|
if (!alreadyCountingStart) {
|
||||||
const time = getAndFormatCurrentTime()
|
const time = getAndFormatCurrentTime()
|
||||||
props.setStartTime(time)
|
props.setStartTime(time)
|
||||||
|
|
||||||
setAlreadyCountingStart(true)
|
setAlreadyCountingStart(true)
|
||||||
|
|
||||||
|
document.title = randomText('work')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (minutes === 0 && seconds === 0) {
|
if (minutes === 0 && seconds === 0) {
|
||||||
@@ -275,6 +279,8 @@ const MainPomodoroTimer = (props) => {
|
|||||||
setAlreadyCountingEnd(true)
|
setAlreadyCountingEnd(true)
|
||||||
|
|
||||||
props.setLetsUpload(true)
|
props.setLetsUpload(true)
|
||||||
|
|
||||||
|
document.title = randomText('rest')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -324,6 +330,7 @@ const MainPomodoroTimer = (props) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!props.timerOn) {
|
if (!props.timerOn) {
|
||||||
|
document.title = 'Clockify Pomodoro Timer'
|
||||||
|
|
||||||
getFavicon().href = './img/favicon.ico'
|
getFavicon().href = './img/favicon.ico'
|
||||||
|
|
||||||
@@ -374,7 +381,7 @@ const MainPomodoroTimer = (props) => {
|
|||||||
setAlreadyCountingStart(false)
|
setAlreadyCountingStart(false)
|
||||||
setAlreadyCountingEnd(false)
|
setAlreadyCountingEnd(false)
|
||||||
}
|
}
|
||||||
}, [props.timerOn, minutes, seconds, breakTime, setMinutes, setSeconds, getAndFormatCurrentTime, setAlreadyCountingEnd, setAlreadyCountingStart, alreadyCountingEnd, alreadyCountingStart, props.setEndTime, props.endTime]
|
}, [randomText, props.timerOn, minutes, seconds, breakTime, setMinutes, setSeconds, getAndFormatCurrentTime, setAlreadyCountingEnd, setAlreadyCountingStart, alreadyCountingEnd, alreadyCountingStart, props.setEndTime, props.endTime]
|
||||||
)
|
)
|
||||||
|
|
||||||
const formatMinutes = () => {
|
const formatMinutes = () => {
|
||||||
|
|||||||
42
src/components/Misc/randomText.js
Normal file
42
src/components/Misc/randomText.js
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
const randomText = (typeTimer) => {
|
||||||
|
|
||||||
|
const workPhrases = [
|
||||||
|
`It's time to work`,
|
||||||
|
]
|
||||||
|
|
||||||
|
const restPhrases = [
|
||||||
|
`Rest!, Rest!`,
|
||||||
|
]
|
||||||
|
|
||||||
|
if (typeTimer === 'work') {
|
||||||
|
|
||||||
|
const min = 0
|
||||||
|
const max = workPhrases.length - 1
|
||||||
|
|
||||||
|
const selection = Math.random() * (max - min) + min;
|
||||||
|
|
||||||
|
console.log(workPhrases)
|
||||||
|
console.log(selection)
|
||||||
|
|
||||||
|
return workPhrases[selection]
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeTimer === 'rest') {
|
||||||
|
|
||||||
|
const min = 0
|
||||||
|
const max = restPhrases.length - 1
|
||||||
|
|
||||||
|
const selection = Math.random() * (max - min) + min;
|
||||||
|
|
||||||
|
console.log(restPhrases)
|
||||||
|
console.log(selection)
|
||||||
|
|
||||||
|
return restPhrases[selection]
|
||||||
|
}
|
||||||
|
|
||||||
|
//! CREDITS: https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Global_Objects/Math/random
|
||||||
|
return 'ERROR'
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default randomText
|
||||||
Reference in New Issue
Block a user