-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
65 lines (58 loc) · 2.14 KB
/
Copy pathApp.tsx
File metadata and controls
65 lines (58 loc) · 2.14 KB
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
import React, {useEffect, useState, useContext, useReducer} from "react"
import {Switch, Route, Redirect, useHistory, useLocation} from "react-router-dom"
import Context, {EnableDragContext, MobileContext} from "./Context"
import functions from "./structures/Functions"
import HomePage from "./pages/HomePage"
import "./index.less"
const App: React.FunctionComponent = (props) => {
const [ignored, forceUpdate] = useReducer(x => x + 1, 0)
const [loaded, setLoaded] = useState(false)
const [enableDrag, setEnableDrag] = useState(false)
const [mobile, setMobile] = useState(false)
useEffect(() => {
functions.preventDragging()
fetch("/update")
setTimeout(() => {
setLoaded(true)
}, 100)
}, [])
const history = useHistory()
const location = useLocation()
useEffect(() => {
setTimeout(() => {
if (mobile) {
if (enableDrag) functions.dragScroll(false)
return
}
functions.dragScroll(enableDrag)
}, 100)
}, [enableDrag, mobile, history])
useEffect(() => {
const mobileQuery = (query: any) => {
if (query.matches) {
setMobile(true)
} else {
setMobile(false)
}
}
const media = window.matchMedia("(max-width: 700px)")
media.addEventListener("change", mobileQuery)
mobileQuery(media)
document.documentElement.style.visibility = "visible"
}, [])
return (
<div className={`app ${!loaded ? "stop-transitions" : ""}`}>
<MobileContext.Provider value={{mobile, setMobile}}>
<EnableDragContext.Provider value={{enableDrag, setEnableDrag}}>
<Context>
<Switch>
<Route exact path={["/", "/home"]}><HomePage/></Route>
<Route path="*"><HomePage/></Route>
</Switch>
</Context>
</EnableDragContext.Provider>
</MobileContext.Provider>
</div>
)
}
export default App