diff --git a/web/src/App.tsx b/web/src/App.tsx index 0d812a6..100e2ab 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -1,6 +1,6 @@ import React, { useEffect } from 'react'; -import { Provider, useSelector } from 'react-redux'; -import { AppActions, RootState, store } from './store'; +import { useSelector } from 'react-redux'; +import { AppActions, RootState } from './store'; import { ToastContainer } from 'react-toastify'; import { Box } from 'lr-components'; import { NextUIProvider } from '@nextui-org/react'; @@ -9,7 +9,7 @@ import { isEnvBrowser } from './utils/misc'; import { fetchNui } from './utils/fetchNui'; function App() { - const show = useSelector((state: RootState) => state.state.show); + const show = useSelector((state: RootState) => state.main.show); useEffect(() => { if (!isEnvBrowser()) { setTimeout(() => { @@ -20,38 +20,36 @@ function App() { return ( show && ( - - - {Object.keys(AppActions).map((action) => { - return ( - - ); - })} - - + + {Object.keys(AppActions).map((action) => { + return ( + + ); + })} + + - - + ) ); diff --git a/web/src/main.tsx b/web/src/main.tsx index 2339d59..d8ab69d 100644 --- a/web/src/main.tsx +++ b/web/src/main.tsx @@ -2,9 +2,13 @@ import React from 'react'; import ReactDOM from 'react-dom/client'; import App from './App'; import './index.css'; +import { Provider } from 'react-redux'; +import { store } from './store'; ReactDOM.createRoot(document.getElementById('root')!).render( - + + + ); diff --git a/web/src/store/index.ts b/web/src/store/index.ts index 32ea123..7d16366 100644 --- a/web/src/store/index.ts +++ b/web/src/store/index.ts @@ -1,10 +1,11 @@ import { configureStore } from '@reduxjs/toolkit'; +import mainSlice from './main'; export const store = configureStore({ - reducer: {}, + reducer: { main: mainSlice.reducer }, }); -export const AppActions = {}; +export const AppActions = { ...mainSlice.actions }; // Infer the `RootState` and `AppDispatch` types from the store itself export type RootState = ReturnType; diff --git a/web/src/store/main/index.ts b/web/src/store/main/index.ts new file mode 100644 index 0000000..553b09b --- /dev/null +++ b/web/src/store/main/index.ts @@ -0,0 +1,23 @@ +import { createSlice } from '@reduxjs/toolkit'; + +interface InitialState { + show: boolean; +} + +const initialState: InitialState = { + show: false, +}; + +const mainSlice = createSlice({ + name: 'main', + initialState, + reducers: { + toggleShow(state) { + state.show = !state.show; + }, + }, +}); + +export const { toggleShow } = mainSlice.actions; + +export default mainSlice;