-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
59 lines (53 loc) · 2.91 KB
/
App.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
import React, {createContext, ReactElement, SetStateAction, useEffect, useState} from 'react';
import './App.scss';
import {ExplanationWindow} from "./ExplanationWindow";
import {Credits} from "./Credits";
import {IRule} from "./Logic";
import {Header} from "./Header";
import {Input} from "./Input";
import {Table} from "./Table";
export const DEFAULT_DIVIDEND = 676884
export const BackgroundClickedContext = createContext({bgClicked: false, setBgClicked: (v: SetStateAction<boolean>) => {}})
export const ShowExplanationContext = createContext({showExplanation: false, setShowExplanation: (v: SetStateAction<boolean>) => {}})
export const InfoButtonCoordsContext = createContext({infoButtonCoords: {x: -1, y: -1},
setInfoButtonCoords: (v: SetStateAction<{x: number, y: number}>) => {}})
export const ExplainedRuleContext = createContext({rule: {divisor: -1, name: '', divides: [false]}, setRule: (v: SetStateAction<IRule>) => {}})
function App(props: {root?: HTMLElement}): ReactElement {
const [dividend, setDividend] = useState(-1)
const [bgClicked, setBgClicked] = useState(false)
const [showExplanation, setShowExplanation] = useState(false)
const [infoButtonCoordsForRule, setInfoButtonCoordsForRule] = useState({x: -1, y: -1})
const [ruleExplained, setRuleExplained] = useState({divisor: -1, name: '', explanation: '', divides: [false]})
useEffect(() => {
if (props.root) {
props.root.className = showExplanation ? 'overflow-hidden' : ''
}},
[props.root, showExplanation])
return (
<>
<BackgroundClickedContext.Provider value={{bgClicked, setBgClicked}}>
<ShowExplanationContext.Provider value={{showExplanation, setShowExplanation}}>
<InfoButtonCoordsContext.Provider value={{
infoButtonCoords: infoButtonCoordsForRule,
setInfoButtonCoords: setInfoButtonCoordsForRule
}}>
<ExplainedRuleContext.Provider value={{rule: ruleExplained, setRule: setRuleExplained}}>
<div className="app" onClick={(): void => {
setBgClicked(true)
}}>
<Header />
<Input onChange={(n: number): void => setDividend(n)}/>
<Table number={dividend}/>
{<ExplanationWindow show={showExplanation} coords={infoButtonCoordsForRule}
rule={ruleExplained}
dividend={dividend}/>}
<Credits/>
</div>
</ExplainedRuleContext.Provider>
</InfoButtonCoordsContext.Provider>
</ShowExplanationContext.Provider>
</BackgroundClickedContext.Provider>
</>
);
}
export default App;