Skip to content

Commit

Permalink
nui bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Thiago Zimmermann committed Apr 29, 2022
1 parent 8127fad commit 3126616
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Hypnonema.NUI/src/components/CurrentTrack/index.tsx
Expand Up @@ -18,9 +18,11 @@ interface CurrentTrackProps {
}

export const CurrentTrack: FC<CurrentTrackProps> = (props) => {
const [startedAt, setStartedAt] = useState<string>(props.startedAt);

const [currentTime, setCurrentTime] = useState<number>(
Math.floor(
(new Date().getTime() - new Date(`${props.startedAt}`).getTime()) / 1000
(new Date().getTime() - new Date(`${startedAt}`).getTime()) / 1000
)
);

Expand All @@ -38,11 +40,18 @@ export const CurrentTrack: FC<CurrentTrackProps> = (props) => {
if (currentTime < props.duration) {
setCurrentTime((currentTime) => currentTime + 1);
} else {
// start from beginning again if repeating
// TODO: find correct way
if (props.repeat) {
setCurrentTime(0);
setStartedAt(new Date().toISOString());
return;
}
setCurrentTime(props.duration);
}
}, 1000);
return () => clearInterval(interval);
}, [currentTime, props.duration, props.isPaused]);
}, [currentTime, props.duration, props.isPaused, props.repeat]);

function valueLabelFormat(value: number) {
return new Date(1000 * value).toISOString().substr(11, 8);
Expand Down

0 comments on commit 3126616

Please sign in to comment.