-
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.
improved BarChart, added Clock and Timer
- Loading branch information
Showing
12 changed files
with
209 additions
and
69 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,36 @@ | ||
import React from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { useTime } from "react-timer-hook"; | ||
import { | ||
TRANSLATION_KEYS, | ||
TRANSLATION_ROOT_KEYS, | ||
} from "../../constants/translationConst"; | ||
import { getTranslationPath } from "../../utils/translationUtils"; | ||
import { Item } from "../SquareGrid/SquareGrid"; | ||
import styles from "./Clock.module.css"; | ||
import zeroFill from "zero-fill"; | ||
|
||
const { COMMON } = TRANSLATION_ROOT_KEYS; | ||
const { current: current_T, time: time_T } = TRANSLATION_KEYS[COMMON]; | ||
|
||
const getTPath = (...args) => getTranslationPath(COMMON, ...args); | ||
|
||
const Clock = props => { | ||
const { t } = useTranslation(); | ||
const { minutes, hours } = useTime({}); | ||
|
||
return ( | ||
<Item className={styles.clock}> | ||
<p>{t(getTPath(current_T))}</p> | ||
<p>{t(getTPath(time_T))}</p> | ||
<p> | ||
<b>{`${zeroFill(2, hours)}:${zeroFill(2, minutes)}`}</b> | ||
</p> | ||
</Item> | ||
); | ||
}; | ||
|
||
Clock.propTypes = {}; | ||
Clock.defaultProps = {}; | ||
|
||
export default Clock; |
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,19 @@ | ||
.clock { | ||
display: flex; | ||
flex-direction: column; | ||
flex-wrap: nowrap; | ||
align-content: center; | ||
justify-content: space-between; | ||
align-items: center; | ||
font-size: calc((100vh - 50px) / 14); | ||
text-align: center; | ||
} | ||
|
||
.clock p { | ||
margin: 0; | ||
} | ||
|
||
.clock p b { | ||
font-size: calc((100vh - 50px) / 10); | ||
margin: 0; | ||
} |
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,71 @@ | ||
import PropTypes from "prop-types"; | ||
import React, { useState } from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { useStopwatch, useTimer } from "react-timer-hook"; | ||
import zeroFill from "zero-fill"; | ||
import { | ||
TRANSLATION_KEYS, | ||
TRANSLATION_ROOT_KEYS, | ||
} from "../../constants/translationConst"; | ||
import { getTranslationPath } from "../../utils/translationUtils"; | ||
import { Item } from "../SquareGrid/SquareGrid"; | ||
import styles from "./Timer.module.css"; | ||
|
||
const { COMMON } = TRANSLATION_ROOT_KEYS; | ||
const { | ||
remaining: remaining_T, | ||
elapsed: elapsed_T, | ||
time: time_T, | ||
} = TRANSLATION_KEYS[COMMON]; | ||
|
||
const getTPath = (...args) => getTranslationPath(COMMON, ...args); | ||
|
||
const TIMER_TYPES = { REMAIN: "REMAIN", ELAPSE: "ELAPSE" }; | ||
|
||
const Timer = props => { | ||
const { expiryTimestamp } = props; | ||
|
||
const [type, setType] = useState(TIMER_TYPES.REMAIN); | ||
const { t } = useTranslation(); | ||
const { seconds: seconds_E, minutes: minutes_E } = useStopwatch({ | ||
autoStart: true, | ||
}); | ||
const { seconds: seconds_R, minutes: minutes_R } = useTimer({ | ||
expiryTimestamp, | ||
}); | ||
|
||
const onClick = () => { | ||
switch (type) { | ||
case TIMER_TYPES.REMAIN: | ||
setType(TIMER_TYPES.ELAPSE); | ||
break; | ||
|
||
case TIMER_TYPES.ELAPSE: | ||
setType(TIMER_TYPES.REMAIN); | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
}; | ||
|
||
return ( | ||
<Item className={styles.timer} onClick={onClick}> | ||
<p> | ||
{t(getTPath(type === TIMER_TYPES.REMAIN ? remaining_T : elapsed_T))} | ||
</p> | ||
<p>{t(getTPath(time_T))}</p> | ||
<p> | ||
<b> | ||
{type === TIMER_TYPES.REMAIN | ||
? `${zeroFill(2, minutes_R)}:${zeroFill(2, seconds_R)}` | ||
: `${zeroFill(2, minutes_E)}:${zeroFill(2, seconds_E)}`} | ||
</b> | ||
</p> | ||
</Item> | ||
); | ||
}; | ||
|
||
Timer.propTypes = { expiryTimestamp: PropTypes.instanceOf(Date) }; | ||
|
||
export default Timer; |
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,19 @@ | ||
.timer { | ||
display: flex; | ||
flex-direction: column; | ||
flex-wrap: nowrap; | ||
align-content: center; | ||
justify-content: space-between; | ||
align-items: center; | ||
font-size: calc((100vh - 50px) / 14); | ||
text-align: center; | ||
} | ||
|
||
.timer p { | ||
margin: 0; | ||
} | ||
|
||
.timer p b { | ||
font-size: calc((100vh - 50px) / 10); | ||
margin: 0; | ||
} |
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
Oops, something went wrong.