Skip to content
This repository was archived by the owner on Dec 26, 2022. It is now read-only.

Commit c4f1f7d

Browse files
committed
[fix] Fixed high CPU load issue
1 parent 2816382 commit c4f1f7d

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

src/components/ProgressBar.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function ProgressBar() {
2929
}
3030
}, [dayUpdateEveryDay]);
3131

32-
useInterval(shouldDayUpdate);
32+
useInterval(shouldDayUpdate, 1000);
3333

3434
const tasksByProject = useMemo(() => Object.values(tasksStore.tasks), [
3535
tasksStore.tasks,
@@ -43,6 +43,7 @@ function ProgressBar() {
4343

4444
const timeItems = useMemo(() => getTimeItems(tasks, dayUpdateEveryDay), [
4545
tasks,
46+
dayUpdateEveryDay,
4647
]);
4748

4849
const workingTimeStart = useMemo(() => getStartWorkingTime(timeItems), [

src/hooks/UseInterval.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ import { useEffect } from 'react';
22

33
export function useInterval(fn: () => void, intervalMs: number = 1000) {
44
useEffect(() => {
5-
let intervalId = setTimeout(function run() {
6-
fn();
7-
intervalId = setTimeout(run, intervalMs);
8-
}, intervalMs);
9-
return () => clearTimeout(intervalId);
10-
}, [fn]);
5+
const intervalId = setInterval(fn, intervalMs);
6+
return () => clearInterval(intervalId);
7+
}, [fn, intervalMs]);
118
}

src/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "time-tracker",
33
"productName": "TimeTracker",
4-
"version": "1.0.8",
4+
"version": "1.0.9",
55
"description": "Start and stop time, jump between tasks, and add details on how time was spent.",
66
"main": "./main.prod.js",
77
"author": {

0 commit comments

Comments
 (0)