import * as React from "react"; import { useMemo, useReducer } from "react"; import { ThemeProvider } from "styled-components"; import CardStack from "./compoents/CardStack"; import Container from "./compoents/Container"; import Footer from "./compoents/Footer"; import GlobalStyle from "./compoents/GlobalStyle"; import MenuToggle from "./compoents/MenuToggle"; import Notebook from "./compoents/Notebook"; import Overlay from "./compoents/Overlay"; import SidePanel from "./compoents/SidePanel"; import Dispatch from "./context/Dispatch"; import useFetchWord from "./hooks/useFetchWord"; import useInitDb from "./hooks/useInitDb"; import useNotebook from "./hooks/useNotebook"; import usePlaySound from "./hooks/usePlaySound"; import useUserSettings from "./hooks/useUserSettings"; import reducer from "./reducer"; import { AppState } from "./types"; import theme from "./utils/theme"; const initialState: AppState = { isModalOpen: false, isMenuOpen: false, word: null, notebook: [], nextNotebookAction: "none", userSettings: {}, audio: null, shouldPlay: false, fetchingNext: false, fetchSettings: false, }; const App = () => { let [store, dispatch] = useReducer(reducer, initialState); useInitDb(dispatch); useUserSettings(store.userSettings, store.fetchSettings, dispatch); useFetchWord( store.fetchingNext, store.userSettings.wordLibrary, store.userSettings.autoplaySound, dispatch ); useNotebook( store.nextNotebookAction, store.notebookTarget || store.word, dispatch ); usePlaySound(store.audio, store.shouldPlay, dispatch); let isWordSaved = useMemo( () => store.word && store.notebook.findIndex((i) => store.word.uuid === i.uuid) !== -1, [store.word, store.notebook] ); return ( {store.word && ( )} dispatch({ type: "closeAll" })} />