Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / packages / redux-shared-store / settingsHeartbeat / heartbeatHelper.ts
blob73eb09517b57a3b2739151c27d0e5a3716bf22d3
1 import { differenceInDays } from 'date-fns';
3 import { getItem, setItem } from '@proton/shared/lib/helpers/storage';
4 import { ThemeModeSetting } from '@proton/shared/lib/themes/themes';
6 export const formatBooleanForHeartbeat = (setting: boolean | number | undefined) => {
7     if (setting === undefined) {
8         return 'false';
9     }
11     if (setting || setting === 1) {
12         return 'true';
13     }
15     return 'false';
18 export const getThemeMode = (mode?: ThemeModeSetting) => {
19     if (mode === undefined) {
20         return 'light';
21     }
23     switch (mode) {
24         case ThemeModeSetting.Auto:
25             return 'auto';
26         case ThemeModeSetting.Dark:
27             return 'dark';
28         case ThemeModeSetting.Light:
29             return 'light';
30     }
33 export const shouldSendHeartBeat = (settingKey: string) => {
34     const lastHeartBeatTimestamp = getItem(settingKey);
35     if (lastHeartBeatTimestamp) {
36         return differenceInDays(new Date(), new Date(lastHeartBeatTimestamp)) >= 7;
37     }
39     // If no last heartbeat, send a heartbeat immediately
40     return true;
43 export const saveHeartbeatTimestamp = (settingKey: string) => {
44     setItem(settingKey, new Date().getTime().toString());