This commit is contained in:
Lorraxs 2023-12-26 22:48:59 +07:00
parent 17247bea67
commit 9a64a0d00f
4 changed files with 63 additions and 37 deletions

View File

@ -1,6 +1,6 @@
import React, { useEffect } from 'react'; import React, { useEffect } from 'react';
import { Provider, useSelector } from 'react-redux'; import { useSelector } from 'react-redux';
import { AppActions, RootState, store } from './store'; import { AppActions, RootState } from './store';
import { ToastContainer } from 'react-toastify'; import { ToastContainer } from 'react-toastify';
import { Box } from 'lr-components'; import { Box } from 'lr-components';
import { NextUIProvider } from '@nextui-org/react'; import { NextUIProvider } from '@nextui-org/react';
@ -9,7 +9,7 @@ import { isEnvBrowser } from './utils/misc';
import { fetchNui } from './utils/fetchNui'; import { fetchNui } from './utils/fetchNui';
function App() { function App() {
const show = useSelector((state: RootState) => state.state.show); const show = useSelector((state: RootState) => state.main.show);
useEffect(() => { useEffect(() => {
if (!isEnvBrowser()) { if (!isEnvBrowser()) {
setTimeout(() => { setTimeout(() => {
@ -20,7 +20,6 @@ function App() {
return ( return (
show && ( show && (
<NextUIProvider> <NextUIProvider>
<Provider store={store}>
<Box <Box
display='flex' display='flex'
position='absolute' position='absolute'
@ -51,7 +50,6 @@ function App() {
></Box> ></Box>
<ToastContainer pauseOnFocusLoss={false} hideProgressBar={true} /> <ToastContainer pauseOnFocusLoss={false} hideProgressBar={true} />
</Provider>
</NextUIProvider> </NextUIProvider>
) )
); );

View File

@ -2,9 +2,13 @@ import React from 'react';
import ReactDOM from 'react-dom/client'; import ReactDOM from 'react-dom/client';
import App from './App'; import App from './App';
import './index.css'; import './index.css';
import { Provider } from 'react-redux';
import { store } from './store';
ReactDOM.createRoot(document.getElementById('root')!).render( ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode> <React.StrictMode>
<Provider store={store}>
<App /> <App />
</Provider>
</React.StrictMode> </React.StrictMode>
); );

View File

@ -1,10 +1,11 @@
import { configureStore } from '@reduxjs/toolkit'; import { configureStore } from '@reduxjs/toolkit';
import mainSlice from './main';
export const store = configureStore({ 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 // Infer the `RootState` and `AppDispatch` types from the store itself
export type RootState = ReturnType<typeof store.getState>; export type RootState = ReturnType<typeof store.getState>;

View File

@ -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;