import { Fragment, useContext, useEffect, useRef, useState } from "react" import { useRouter } from "next/router" import { Event, getAllLocalStorageItems, getRefValue, getRefValues, isTrue, preventDefault, refs, spreadArraysOrObjects, uploadFiles, useEventLoop } from "/utils/state" import { ColorModeContext, EventLoopContext, initialEvents, StateContext } from "/utils/context.js" import "focus-visible/dist/focus-visible" import { Modal, ModalBody, ModalContent, ModalHeader, ModalOverlay, Text } from "@chakra-ui/react" import { getEventURL } from "/utils/state.js" import Error from "next/error" import { useClientSideRouting } from "/utils/client_side_routing" import NextHead from "next/head" export default function Component() { const state = useContext(StateContext) const router = useRouter() const [ colorMode, toggleColorMode ] = useContext(ColorModeContext) const focusRef = useRef(); // Main event loop. const [addEvents, connectError] = useContext(EventLoopContext) // Set focus to the specified element. useEffect(() => { if (focusRef.current) { focusRef.current.focus(); } }) // Route after the initial page hydration. useEffect(() => { const change_complete = () => addEvents(initialEvents()) router.events.on('routeChangeComplete', change_complete) return () => { router.events.off('routeChangeComplete', change_complete) } }, [router]) const routeNotFound = useClientSideRouting() return ( {isTrue(connectError !== null) ? ( {`Connection Error`} {`Cannot connect to server: `} {(connectError !== null) ? connectError.message : ''} {`. Check if server is reachable at `} {getEventURL().href} ) : ( )} {isTrue(routeNotFound) ? ( ) : ( )} {`404 - Not Found`} ) }