-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
573 additions
and
502 deletions.
There are no files selected for viewing
100 changes: 53 additions & 47 deletions
100
src/components/devfest-triangulo-2023/countdown/countdown-timer.tsx
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 |
---|---|---|
@@ -1,54 +1,60 @@ | ||
import styles from "./CountdownTimer.module.css"; | ||
|
||
import React, { useState, useEffect } from 'react'; | ||
import React, { useState, useEffect } from "react"; | ||
import { changeTimeZone, calcDateDistance } from "helpers/date"; | ||
|
||
import configValues from "helpers/config"; | ||
|
||
|
||
const DATE_DISTANCE_LABELS: Record<string, string> = { | ||
days: 'dias', | ||
hours: 'horas', | ||
minutes: 'minutos', | ||
seconds: 'segundos', | ||
} | ||
const CountdownTimer: React.FC = ({ }) => { | ||
|
||
const [_dateDistance, _setDateDistance] = useState({ | ||
distance: 0, | ||
days: 0, | ||
hours: 0, | ||
minutes: 0, | ||
seconds: 0 | ||
} as Record<string, number>); | ||
|
||
useEffect(() => { | ||
const _interval = setInterval(function () { | ||
const _result = calcDateDistance(changeTimeZone(configValues.eventDate, 'America/Sao_Paulo')); | ||
|
||
if (_result.distance < 0) { | ||
clearInterval(_interval) | ||
return | ||
} | ||
|
||
_setDateDistance(_result); | ||
}, 1000); | ||
|
||
return () => { | ||
clearInterval(_interval) | ||
} | ||
}, []) | ||
|
||
return (<section className={styles.Counter}> | ||
<ul className={styles.CounterList}> | ||
{Object.keys(DATE_DISTANCE_LABELS).map(key => ( | ||
<li className={styles.CounterListItem} key={key}> | ||
<span className={`${styles.CounterListItem__time}`}>{_dateDistance[key]}</span> | ||
{DATE_DISTANCE_LABELS[key]} | ||
</li> | ||
))} | ||
</ul> | ||
</section>); | ||
} | ||
|
||
export default CountdownTimer; | ||
days: "dias", | ||
hours: "horas", | ||
minutes: "minutos", | ||
seconds: "segundos", | ||
}; | ||
const CountdownTimer: React.FC = ({}) => { | ||
const [_dateDistance, _setDateDistance] = useState({ | ||
distance: 0, | ||
days: 0, | ||
hours: 0, | ||
minutes: 0, | ||
seconds: 0, | ||
} as Record<string, number>); | ||
|
||
useEffect(() => { | ||
const _interval = setInterval(function () { | ||
const now = new Date(); | ||
const _result = calcDateDistance({ | ||
initialDate: now, | ||
endDate: changeTimeZone(configValues.eventDate, "America/Sao_Paulo"), | ||
}); | ||
|
||
if (_result.distance < 0) { | ||
clearInterval(_interval); | ||
return; | ||
} | ||
|
||
_setDateDistance(_result); | ||
}, 1000); | ||
|
||
return () => { | ||
clearInterval(_interval); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<section className={styles.Counter}> | ||
<ul className={styles.CounterList}> | ||
{Object.keys(DATE_DISTANCE_LABELS).map((key) => ( | ||
<li className={styles.CounterListItem} key={key}> | ||
<span className={`${styles.CounterListItem__time}`}> | ||
{_dateDistance[key]} | ||
</span> | ||
{DATE_DISTANCE_LABELS[key]} | ||
</li> | ||
))} | ||
</ul> | ||
</section> | ||
); | ||
}; | ||
|
||
export default CountdownTimer; |
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.