Skip to content

Commit 989dccc

Browse files
committed
feat(settings): make fetch interval user configurable
Signed-off-by: Adam Setch <[email protected]>
1 parent 753b402 commit 989dccc

File tree

1 file changed

+36
-16
lines changed

1 file changed

+36
-16
lines changed

src/renderer/components/settings/NotificationSettings.tsx

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { type FC, type MouseEvent, useContext } from 'react';
1+
import {
2+
type FC,
3+
type MouseEvent,
4+
useContext,
5+
useEffect,
6+
useState,
7+
} from 'react';
28

39
import {
410
BellIcon,
@@ -29,6 +35,13 @@ import { Title } from '../primitives/Title';
2935

3036
export const NotificationSettings: FC = () => {
3137
const { settings, updateSetting } = useContext(AppContext);
38+
const [fetchInterval, setFetchInterval] = useState<number>(
39+
settings.fetchInterval,
40+
);
41+
42+
useEffect(() => {
43+
setFetchInterval(settings.fetchInterval);
44+
}, [settings.fetchInterval]);
3245

3346
return (
3447
<fieldset>
@@ -89,22 +102,24 @@ export const NotificationSettings: FC = () => {
89102
data-testid="settings-fetch-interval-decrease"
90103
icon={DashIcon}
91104
onClick={() => {
92-
updateSetting(
93-
'fetchInterval',
94-
Math.max(
95-
settings.fetchInterval -
96-
Constants.FETCH_NOTIFICATIONS_INTERVAL_STEP_MS,
97-
Constants.MIN_FETCH_NOTIFICATIONS_INTERVAL_MS,
98-
),
105+
const newInterval = Math.max(
106+
fetchInterval -
107+
Constants.FETCH_NOTIFICATIONS_INTERVAL_STEP_MS,
108+
Constants.MIN_FETCH_NOTIFICATIONS_INTERVAL_MS,
99109
);
110+
111+
if (newInterval !== fetchInterval) {
112+
setFetchInterval(newInterval);
113+
updateSetting('fetchInterval', newInterval);
114+
}
100115
}}
101116
size="small"
102117
unsafeDisableTooltip={true}
103118
/>
104119

105120
<Button aria-label="Fetch interval" disabled size="small">
106121
{formatDuration({
107-
minutes: millisecondsToMinutes(settings.fetchInterval),
122+
minutes: millisecondsToMinutes(fetchInterval),
108123
})}
109124
</Button>
110125

@@ -113,14 +128,16 @@ export const NotificationSettings: FC = () => {
113128
data-testid="settings-fetch-interval-increase"
114129
icon={PlusIcon}
115130
onClick={() => {
116-
updateSetting(
117-
'fetchInterval',
118-
Math.min(
119-
settings.fetchInterval +
120-
Constants.FETCH_NOTIFICATIONS_INTERVAL_STEP_MS,
121-
Constants.MAX_FETCH_NOTIFICATIONS_INTERVAL_MS,
122-
),
131+
const newInterval = Math.min(
132+
fetchInterval +
133+
Constants.FETCH_NOTIFICATIONS_INTERVAL_STEP_MS,
134+
Constants.MAX_FETCH_NOTIFICATIONS_INTERVAL_MS,
123135
);
136+
137+
if (newInterval !== fetchInterval) {
138+
setFetchInterval(newInterval);
139+
updateSetting('fetchInterval', newInterval);
140+
}
124141
}}
125142
size="small"
126143
unsafeDisableTooltip={true}
@@ -131,6 +148,9 @@ export const NotificationSettings: FC = () => {
131148
data-testid="settings-fetch-interval-reset"
132149
icon={SyncIcon}
133150
onClick={() => {
151+
setFetchInterval(
152+
Constants.DEFAULT_FETCH_NOTIFICATIONS_INTERVAL_MS,
153+
);
134154
updateSetting(
135155
'fetchInterval',
136156
Constants.DEFAULT_FETCH_NOTIFICATIONS_INTERVAL_MS,

0 commit comments

Comments
 (0)