-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.jsx
64 lines (50 loc) · 2.51 KB
/
main.jsx
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const CONFIGURATION = require('./lib/configs');
const PLUGINS = require('./lib/plugins');
export const refreshFrequency= 1000;
let gaudiTimeTable = {};
export const command = (dispatch) => {
Object.keys(CONFIGURATION).map(primaryBar => {
Object.keys(CONFIGURATION[primaryBar]).map(secondaryBar => {
CONFIGURATION[primaryBar][secondaryBar].map(plugin => {
if (!gaudiTimeTable[plugin] || (new Date(gaudiTimeTable[plugin].getTime() + PLUGINS[plugin].refreshFrequency) <= new Date())) {
PLUGINS[plugin].render().then(output => {
gaudiTimeTable[plugin] = new Date();
return dispatch({output, type: plugin})
}).catch(error => console.log(`🛑Something went wrong ❗: ${error}`))
}
if (!gaudiTimeTable[plugin]) gaudiTimeTable[plugin] = new Date();
})
})
});
}
export const render = ({state}) => {
const PRIMARY_BARS = ["top", "bottom"];
const SECONDARY_BARS = ["left", "middle", "right"];
try {
return <div className="gaudi">
<link rel="stylesheet" type="text/css" href="gaudiBar.widget/lib/fonts/css/fonts.css"></link>
<link rel="stylesheet" type="text/css" href="/gaudiBar.widget/style.css" />
{PRIMARY_BARS.map((primaryBar, index) => {
return <div key={`bar-${primaryBar}-${index}`} className={`gaudi-bar__${primaryBar}`}>
{SECONDARY_BARS.map((secondaryBar) => {
return <div key={`bar-${primaryBar}-${secondaryBar}-${index}`}
className={`gaudi-bar-section gaudi-bar__${primaryBar}-${secondaryBar}`}>
{CONFIGURATION[primaryBar][secondaryBar].map((widget, index) => {
return !!widget ? <div className={`gaudi-bar-section-widget-container plugin-${widget}`} key={`widget-${index}`}>{state[widget]}</div> : null;
})}
</div>
})}
</div>
})}
</div>
} catch (error) {
return <div> 🛑Something went wrong ❗<strong>{String(error)}</strong></div>
}
}
export const updateState = (event, previousState) => {
if (event.error) {
console.error(event.error)
return {...previousState, warning: `We got an error: ${event.error}`}
}
return !!event.type ? { state: {...previousState.state, [event.type]: event.output} } : event;
}