-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.jsx
109 lines (90 loc) · 2.06 KB
/
index.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// eslint-disable-next-line import/no-unresolved
import React, {css, styled} from 'uebersicht'
export const refreshFrequency = 3600000 // Use ms (every hour)
// NOTE: ⚠ Workaround to hide initial load
export const initialState = {output: false}
export const command = '/opt/homebrew/bin/node --no-warnings ./github/lib/github.js'
export const updateState = (event, prev) => {
if (event.error) {
return {...prev, error: event.error.message}
}
switch (event.type) {
case 'UB/COMMAND_RAN':
try {
return {
items: JSON.parse(event.output) || [],
}
} catch (error) {
return {
items: [],
}
}
default:
return prev
}
}
export const render = ({items, error}) => {
if (error) {
return <Error>Something went wrong</Error>
}
// NOTE: ⚠ Workaround to hide initial load
if (!items) {
return <Loading>loading...</Loading>
}
if (items) {
return (
<Contributions>
{items.map(({color, count}, idx) => (
<div className={day} key={idx} style={{backgroundColor: `${color}`}}>
{count}
</div>
))}
</Contributions>
)
}
}
// Styling...
export const className = css`
font:
normal normal 400 0.96em/1.28 -apple-system,
Helvetica Neue;
@media (prefers-color-scheme: light) {
color: #2f363d;
}
@media (prefers-color-scheme: dark) {
color: #ebebeb;
}
transition: all 1s ease;
left: 0em;
bottom: 0em;
`
export const Error = styled('div')`
color: #9c1c23;
margin: 0 0 0.4em 0.8em;
`
export const Loading = styled('div')`
@media (prefers-color-scheme: light) {
opacity: 0.64;
}
@media (prefers-color-scheme: dark) {
opacity: 0.32;
}
margin: 0 0 0.4em 1em;
`
export const Contributions = styled('div')`
height: 2vh;
width: 100vw;
display: flex;
gap: 2px;
`
export const day = css`
font:
normal normal 400 0.64em 'Monaspace Argon',
ui-monospace,
monospace;
color: #2f363d96;
display: flex;
flex: 1;
justify-content: center;
align-items: center;
`