Skip to content

Commit bfa064c

Browse files
committed
Notifications
1 parent b05f108 commit bfa064c

File tree

5 files changed

+52
-9
lines changed

5 files changed

+52
-9
lines changed

src/components/SettingsModal/SettingsModal.tsx

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
import React, { useCallback, useState } from 'react';
2-
import { Form, Modal, Select, Space, TimePicker } from 'antd';
2+
import {
3+
Checkbox,
4+
Divider,
5+
Form,
6+
Modal,
7+
Select,
8+
Space,
9+
TimePicker,
10+
} from 'antd';
11+
import { CheckboxChangeEvent } from 'antd/lib/checkbox';
312
import { observer } from 'mobx-react';
413
// eslint-disable-next-line import/named
514
import moment, { Moment } from 'moment';
@@ -24,6 +33,9 @@ const SettingsModal: React.VFC<ISettingsModalProps> = observer(
2433
const [showNewProfilePopover, setShowNewProfilePopover] = useState<boolean>(
2534
false
2635
);
36+
const [showNotifications, setShowNotifications] = useState<boolean>(
37+
settings.showNotifications
38+
);
2739
const [profile, setProfile] = useState<string>(settings.currentProfile);
2840
const [workingHours, setWorkingHours] = useState<Moment | null>(
2941
moment(settings.numberOfWorkingHours).utcOffset(0)
@@ -35,9 +47,10 @@ const SettingsModal: React.VFC<ISettingsModalProps> = observer(
3547
numberOfWorkingHours: workingHours
3648
? timeToMs(workingHours?.toDate())
3749
: DEFAULT_SETTINGS.numberOfWorkingHours,
50+
showNotifications,
3851
});
3952
onClose();
40-
}, [profile, workingHours, onClose]);
53+
}, [profile, workingHours, showNotifications, onClose]);
4154

4255
const handleChangeProfile = useCallback((selected: string) => {
4356
setProfile(selected);
@@ -53,6 +66,10 @@ const SettingsModal: React.VFC<ISettingsModalProps> = observer(
5366
[]
5467
);
5568

69+
const handleChangeNotifications = useCallback((e: CheckboxChangeEvent) => {
70+
setShowNotifications(e.target.checked);
71+
}, []);
72+
5673
return (
5774
<Modal
5875
title="Settings"
@@ -81,7 +98,8 @@ const SettingsModal: React.VFC<ISettingsModalProps> = observer(
8198
/>
8299
</Space>
83100
</Form.Item>
84-
<Form.Item label="Number of working hours">
101+
<Divider />
102+
<Form.Item label="Number of working hours" labelCol={{ span: 10 }}>
85103
<TimePicker
86104
value={workingHours}
87105
onChange={(value) => setWorkingHours(value)}
@@ -91,6 +109,12 @@ const SettingsModal: React.VFC<ISettingsModalProps> = observer(
91109
allowClear={false}
92110
/>
93111
</Form.Item>
112+
<Form.Item label="Notifications" labelCol={{ span: 10 }}>
113+
<Checkbox
114+
checked={showNotifications}
115+
onChange={handleChangeNotifications}
116+
/>
117+
</Form.Item>
94118
</Modal>
95119
);
96120
}

src/modules/settings/SettingsStore.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,15 @@ export default class SettingsStore {
2020
}
2121

2222
setSettings(newSettings: ISettings) {
23-
const { currentProfile, numberOfWorkingHours } = newSettings;
23+
const {
24+
currentProfile,
25+
numberOfWorkingHours,
26+
showNotifications,
27+
} = newSettings;
28+
2429
this.settings.numberOfWorkingHours = numberOfWorkingHours;
30+
this.settings.showNotifications = showNotifications;
31+
this.rootStore.tasksStore.removeReminder();
2532
this.setActiveProfile(currentProfile);
2633
this.service.save(this.settings);
2734
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export interface ISettings {
22
currentProfile: string;
33
numberOfWorkingHours: number;
4+
showNotifications: boolean;
45
}

src/modules/settings/models/SettingsModel.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ export const DEFAULT_SETTINGS = {
66
profiles: ['profile1'],
77
numberOfWorkingHours: 8 * 60 * 60 * 1000,
88
isFirstLoad: true,
9+
showNotifications: true,
910
};
1011

1112
export default class SettingsModel extends AbstractModel {
1213
currentProfile: string = DEFAULT_SETTINGS.currentProfile;
1314
profiles: string[] = DEFAULT_SETTINGS.profiles;
1415
numberOfWorkingHours: number = DEFAULT_SETTINGS.numberOfWorkingHours;
1516
isFirstLoad: boolean = DEFAULT_SETTINGS.isFirstLoad;
16-
// TODO showNotifications
17+
showNotifications: boolean = DEFAULT_SETTINGS.showNotifications;
1718

1819
constructor(data: any) {
1920
super();
@@ -23,6 +24,7 @@ export default class SettingsModel extends AbstractModel {
2324
profiles: observable,
2425
numberOfWorkingHours: observable,
2526
isFirstLoad: observable,
27+
showNotifications: observable,
2628
});
2729
}
2830
}

src/modules/tasks/TaskStore.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,15 @@ export default class TaskStore {
191191
}
192192

193193
private setupReminder(task?: TaskModel) {
194-
if (this.interval !== undefined) {
195-
clearInterval(this.interval);
194+
BadgeService.setBadge(!!task);
195+
196+
if (!this.rootStore.settingsStore.settings.showNotifications) {
197+
return;
196198
}
199+
200+
this.removeReminder();
201+
197202
if (task) {
198-
BadgeService.setBadge(true);
199203
console.log('Setup: Task in progress');
200204
this.interval = setInterval(() => {
201205
console.log('Task in progress');
@@ -204,7 +208,6 @@ export default class TaskStore {
204208
});
205209
}, 40 * 60 * 1000);
206210
} else {
207-
BadgeService.setBadge(false);
208211
console.log('Setup: No tasks in progress');
209212
this.interval = setInterval(() => {
210213
console.log('No tasks in progress');
@@ -214,4 +217,10 @@ export default class TaskStore {
214217
}, 15 * 60 * 1000);
215218
}
216219
}
220+
221+
removeReminder() {
222+
if (this.interval !== undefined) {
223+
clearInterval(this.interval);
224+
}
225+
}
217226
}

0 commit comments

Comments
 (0)