-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (42 loc) · 1.31 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const storageKeys = {
publicHolidays: 'phs',
weekends: 'wknds',
numberOfForcedLeaves: 'nofl',
startOfWeek: 'sow',
};
const saveToStorage = (key) => (val) => {
return localStorage.setItem(key, val);
};
const getItemWithDefault = (defaultValue) => (key) => {
if (localStorage.getItem(key)) {
return JSON.parse(localStorage.getItem(key));
}
return defaultValue;
};
const defaultPH = ['2021-01-26', '2021-10-02', '2021-12-25', '2021-08-15'];
const app = Elm.Main.init({
node: document.getElementById('app'),
flags: {
year: new Date().getFullYear(),
initPublicHolidays: getItemWithDefault(defaultPH)(
storageKeys.publicHolidays
),
numberOfForcedLeaves: getItemWithDefault(1)(
storageKeys.numberOfForcedLeaves
),
weekendDays: getItemWithDefault(['Sun', 'Sat'])(storageKeys.weekends),
startOfWeek: getItemWithDefault('Sun')(storageKeys.startOfWeek),
},
});
app.ports.savePhToStorage.subscribe((val) =>
saveToStorage(storageKeys.publicHolidays)(val)
);
app.ports.saveNumberOfForcedLeavesToStorage.subscribe((val) =>
saveToStorage(storageKeys.numberOfForcedLeaves)(val)
);
app.ports.saveWeekendDaysToStorage.subscribe((val) =>
saveToStorage(storageKeys.weekends)(val)
);
app.ports.saveStartOfWeekToStorage.subscribe((val) =>
saveToStorage(storageKeys.startOfWeek)(val)
);