-
Notifications
You must be signed in to change notification settings - Fork 0
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 #18 from danifromecuador/fix/doing-structure
fix/doing structure
- Loading branch information
Showing
5 changed files
with
127 additions
and
113 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { useState, useRef } from 'react' | ||
import Countdown, { zeroPad } from 'react-countdown' | ||
import { Store } from '../store/store.js' | ||
import './Clock.css' | ||
|
||
export const Clock = () => { | ||
const store = Store() | ||
const text = store.language.current === "english" ? store.language.text().english : store.language.text().spanish | ||
const countdownRef = useRef(null) | ||
const audioStart = new Audio('/start.mp3') | ||
const audioAlarm = new Audio('/clock_alarm.mp3') | ||
const [date] = useState(Date.now() + 900000) | ||
const [textStartBtn, setTextStartBtn] = useState(text.doing.pomodoro.start) | ||
const [viewStartBtn, setViewStartBtn] = useState("") | ||
const [viewPauseBtn, setViewPauseBtn] = useState("hide") | ||
const [viewResetBtn, setViewResetBtn] = useState("hide") | ||
|
||
const rendered = ({ minutes, seconds, completed }) => { | ||
completed && (audioAlarm.play(), handleResetClick(false)) | ||
return <span>{zeroPad(minutes)}:{zeroPad(seconds)}</span> | ||
} | ||
|
||
const handleStartClick = () => { | ||
countdownRef.current && countdownRef.current.getApi().start() | ||
setViewStartBtn("hide") | ||
setViewPauseBtn("") | ||
setViewResetBtn("") | ||
audioStart.play() | ||
} | ||
|
||
const handlePauseClick = () => { | ||
countdownRef.current && countdownRef.current.getApi().pause() | ||
setTextStartBtn(text.doing.pomodoro.continue) | ||
setViewStartBtn("") | ||
setViewPauseBtn("hide") | ||
audioStart.play() | ||
} | ||
|
||
const handleResetClick = (withSound) => { | ||
countdownRef.current && countdownRef.current.getApi().stop() | ||
setTextStartBtn(text.doing.pomodoro.start) | ||
setViewStartBtn("") | ||
setViewPauseBtn("hide") | ||
setViewResetBtn("hide") | ||
// play a sound when reseting but just when user clicks on RESET btn | ||
withSound && audioStart.play() | ||
} | ||
|
||
return ( | ||
<div className="pomodoro sub-container"> | ||
<div className="clock"><Countdown ref={countdownRef} date={date} autoStart={false} renderer={rendered} /></div> | ||
<div className="controls"> | ||
<button className={`${viewStartBtn} start bigBtn`} onClick={handleStartClick}>{textStartBtn}</button> | ||
<button className={`${viewPauseBtn} pause bigBtn`} onClick={handlePauseClick}>{text.doing.pomodoro.pause}</button> | ||
<button className={`${viewResetBtn} reset bigBtn`} onClick={() => handleResetClick(true)}>{text.doing.pomodoro.reset}</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
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,15 @@ | ||
.Doing .motivational { | ||
cursor: pointer; | ||
display: flex; | ||
flex-direction: column; | ||
row-gap: 10px; | ||
} | ||
|
||
.Doing .motivational p:first-of-type { | ||
font-size: 1rem; | ||
font-style: italic; | ||
} | ||
|
||
.Doing .motivational p:last-of-type { | ||
font-size: 0.7rem; | ||
} |
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,46 @@ | ||
import { useEffect, useState } from 'react' | ||
import { Store } from '../store/store.js' | ||
import axios from 'axios' | ||
import './Quote.css' | ||
|
||
export const Quote = () => { | ||
const store = Store() | ||
const [quote, setQuote] = useState("One day, in retrospect, the years of struggle will strike you as the most beautiful") | ||
const [author, setAuthor] = useState("Sigmund Freud") | ||
const [fetchNewQuote, setFetchNewQoute] = useState("") | ||
const catchNewQuote = () => fetchNewQuote == "yes" ? setFetchNewQoute("") : setFetchNewQoute("yes") | ||
|
||
useEffect(() => { | ||
const fetchQuote = async () => { | ||
try { | ||
const response = await axios('https://api.quotable.io/random', { | ||
params: { | ||
tags: 'motivational|success|change|character|future|inspirational', | ||
maxLength: 70, | ||
} | ||
}) | ||
if (store.language.current === "spanish") await translateQuote(response.data.content) | ||
else setQuote(response.data.content) | ||
setAuthor(response.data.author) | ||
} | ||
catch (error) { | ||
setQuote(quote) | ||
setAuthor(author) | ||
console.error("Error fetching the quote: ", error.message) | ||
} | ||
} | ||
fetchQuote() | ||
}, [fetchNewQuote]) | ||
|
||
const translateQuote = async (quote) => { | ||
const quoteTranslated = await axios(`https://api.mymemory.translated.net/get?q=${quote}&langpair=en|es`) | ||
setQuote(quoteTranslated.data.responseData.translatedText) | ||
} | ||
|
||
return ( | ||
<div className="motivational" onClick={catchNewQuote}> | ||
<p>{quote}</p> | ||
<p>{author}</p> | ||
</div> | ||
) | ||
} |