-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.tsx
117 lines (109 loc) · 2.81 KB
/
main.tsx
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
110
111
112
113
114
115
116
117
import 'regenerator-runtime/runtime'
import React from 'react'
import ReactDOM from 'react-dom'
import { Provider } from 'react-redux'
import { createStore, Reducer } from 'redux'
import { install } from 'redux-loop'
import App from '~components/App'
import { ActionType, State } from '~singletons/interfaces'
import reducer from '~singletons/reducer'
import {
getSavedSpace,
getSpace,
clearSavedSpace,
DEFAULT_LOCATION,
} from '~singletons/space'
import { calculateState } from '~singletons/state'
{
// TODO TEMP
// allow flushing cached position with #reset hash
const hash = window.location.hash
const RESET = '#reset'
if (hash === RESET) {
clearSavedSpace()
window.location.href = window.location.href.slice(0, -RESET.length)
}
}
const space = getSavedSpace()
const store = createStore(
(reducer as unknown) as Reducer<State>,
calculateState({ ms: Date.now(), space }),
install(),
)
ReactDOM.render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById('root'),
)
if (!space) {
// request user device geolocation if not already set
getSpace()
.then((s) => store.dispatch({ type: ActionType.Space, space: s }))
.catch((e) => {
alert(e.message + ', using default location (Seattle)')
store.dispatch({ type: ActionType.Space, space: DEFAULT_LOCATION })
})
}
// update time every second
setInterval(
() =>
store.dispatch({
type: ActionType.Time,
ms: Date.now() + store.getState().nudge,
}),
1000,
)
// // shift time with arrow keys
// window.addEventListener('keydown', (e) => {
// let direction: NudgeDirection
// let duration: NudgeDuration
// switch (e.key) {
// case 'm': {
// direction = NudgeDirection.Forward
// duration = NudgeDuration.Minute
// break
// }
// case 'M': {
// direction = NudgeDirection.Backward
// duration = NudgeDuration.Minute
// break
// }
// case 'h': {
// direction = NudgeDirection.Forward
// duration = NudgeDuration.Hour
// break
// }
// case 'H': {
// direction = NudgeDirection.Backward
// duration = NudgeDuration.Hour
// break
// }
// case 'd': {
// direction = NudgeDirection.Forward
// duration = NudgeDuration.Day
// break
// }
// case 'D': {
// direction = NudgeDirection.Backward
// duration = NudgeDuration.Day
// break
// }
// case 'w': {
// direction = NudgeDirection.Forward
// duration = NudgeDuration.Week
// break
// }
// case 'W': {
// direction = NudgeDirection.Backward
// duration = NudgeDuration.Week
// break
// }
// default: {
// return
// }
// }
// e.preventDefault()
// e.stopPropagation()
// store.dispatch({ type: ActionType.Nudge, direction, duration })
// })