All files / app page.tsx

97.77% Statements 44/45
90.62% Branches 29/32
100% Functions 14/14
97.05% Lines 33/34

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                  19x 69x 76x   19x 77x 6x 31x   69x 36x 34x 28x 69x 28x 30x 41x       84x 125x 56x 10x 10x 210x 207x 200x 46x 46x 80x 24x 56x 92x 92x     200x 204x             70x              
'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>
  )
}