Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | 20x 9x 20x 12x 10x 10x 12x 8x 4x 62x 62x 62x 10x 10x 7x 7x 10x 10x 62x 6x | 'use client'
import {StrictMode, useReducer, useState} from 'react'
import {Resources} from './resources'
import {Building} from './building'
import {type InfoDrawerActions, InfoDrawerContext, InfoDrawerSetter, InfoDrawerState} from './infoDrawer'
import {EditorTerm, EditorTermSetter} from './termEditor'
import {Content} from './content'
import {showTableTerm} from './table'
let resizeAnimationFrame = -1
function dispatchResize() {
window.dispatchEvent(new Event('resize'))
}
const manageInfoDrawerState = (state: InfoDrawerState[], action: InfoDrawerActions) => {
if (action.type === 'reset' || !state.length) {
cancelAnimationFrame(resizeAnimationFrame)
resizeAnimationFrame = requestAnimationFrame(dispatchResize)
}
switch (action.type) {
case 'add':
return state.length && state[0].value === action.state.value ? [...state] : [action.state, ...state]
case 'back':
return [...state].splice(1, state.length)
default:
return []
}
}
export default function Home() {
const [infoDrawerState, updateInfoDrawerState] = useReducer(manageInfoDrawerState, [])
const [editorTerm, setEditorTerm] = useState('')
const updateEditorTerm = (term: string, fromGraph?: boolean) => {
requestAnimationFrame(() => {
if ((!editorTerm && !fromGraph) || !term) {
cancelAnimationFrame(resizeAnimationFrame)
resizeAnimationFrame = requestAnimationFrame(dispatchResize)
}
showTableTerm(term)
setEditorTerm(term)
})
}
return (
<StrictMode>
<Resources>
<Building>
<InfoDrawerContext.Provider value={infoDrawerState}>
<InfoDrawerSetter.Provider
value={(action: InfoDrawerActions) => requestAnimationFrame(() => updateInfoDrawerState(action))}
>
<EditorTerm.Provider value={editorTerm}>
<EditorTermSetter.Provider value={updateEditorTerm}>
<Content />
</EditorTermSetter.Provider>
</EditorTerm.Provider>
</InfoDrawerSetter.Provider>
</InfoDrawerContext.Provider>
</Building>
</Resources>
</StrictMode>
)
}
|