Skip to content

Commit

Permalink
Fix frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
Akim Mamedov committed Mar 14, 2024
1 parent cb7ab7b commit 4b12dd0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion web/src/components/TimeUntilReduce/TimeUntilReduce.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import DefinitionList from "../DefinitionList/DefinitionList";

const TimeUntilReduce = () => {
const { nextHalvePeriod } = useSelector((state) => state.distributor);
const [timer] = useCountdown(nextHalvePeriod || 0);
const timer = useCountdown(nextHalvePeriod || 0);

return (
<DefinitionList
Expand Down
32 changes: 16 additions & 16 deletions web/src/hooks/useCountdown.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import { intervalToDuration, isPast } from "date-fns";
import { useEffect, useState } from "react";
import { useEffect, useMemo, useState } from "react";

export const useCountdown = (date) => {
const format = ({ months, days, hours, minutes, seconds }) =>
`${months}M ${days}d ${hours}h ${minutes}m ${seconds}s`;
const format = ({ months = 0, days = 0, hours = 0, minutes = 0, seconds = 0 }) =>
`${months}M ${days}d ${hours}h ${minutes}m ${seconds}s`;

const [ended, setEnded] = useState(isPast(date));
export const useCountdown = (date) => {
const [duration, setDuration] = useState(
intervalToDuration({
start: date,
end: Date.now(),
isPast(date) ? {} : intervalToDuration({
start: Date.now(),
end: date,
}),
);
const [formatted, setFormatted] = useState(format(duration));

useEffect(() => {
const timer = setInterval(() => {
if (isPast(date)) {
clearInterval(timer);
return;
}

const intToDur = intervalToDuration({
start: date,
end: Date.now(),
start: Date.now(),
end: date,
});
setDuration(intToDur);
setFormatted(format(intToDur));
setEnded(isPast(date));
}, 1000);

ended && clearInterval(timer);
return () => clearInterval(timer);
}, []);
}, [date]);

return [formatted, duration];
return useMemo(() => format(duration), [duration]);
};
10 changes: 5 additions & 5 deletions web/src/pages/begin-page/begin-page.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
}

.flex-container {
display: flex;
justify-content: space-between;
display: grid;
grid-template-columns: 2fr 1fr;
column-gap: 5%;
}

.flex-container__part-left {
max-width: 715px;
width: 65%;
}

.dashboard {
Expand Down Expand Up @@ -164,11 +164,11 @@

@media screen and (max-width: 803px) {
.flex-container {
flex-direction: column-reverse;
justify-content: flex-start;
grid-template-columns: 1fr;
}

.flex-container__part-left {
order: 2;
max-width: 715px;
width: 100%;
}
Expand Down

0 comments on commit 4b12dd0

Please sign in to comment.