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 { 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 && (
<NextUIProvider>
<Provider store={store}>
<Box
display='flex'
position='absolute'
flexWrap='wrap'
justifyContent='center'
alignItems='center'
flexDirection='column'
width={'50%'}
height={'50%'}
rGap={10}
>
{Object.keys(AppActions).map((action) => {
return (
<AppActionHook
action={action as keyof typeof AppActions}
></AppActionHook>
);
})}
</Box>
<Box
width={'100%'}
height={'100%'}
display='flex'
justifyContent='center'
alignItems='center'
className='prose'
pointerEvents='none'
></Box>
<Box
display='flex'
position='absolute'
flexWrap='wrap'
justifyContent='center'
alignItems='center'
flexDirection='column'
width={'50%'}
height={'50%'}
rGap={10}
>
{Object.keys(AppActions).map((action) => {
return (
<AppActionHook
action={action as keyof typeof AppActions}
></AppActionHook>
);
})}
</Box>
<Box
width={'100%'}
height={'100%'}
display='flex'
justifyContent='center'
alignItems='center'
className='prose'
pointerEvents='none'
></Box>
<ToastContainer pauseOnFocusLoss={false} hideProgressBar={true} />
</Provider>
<ToastContainer pauseOnFocusLoss={false} hideProgressBar={true} />
</NextUIProvider>
)
);

View File

@ -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(
<React.StrictMode>
<App />
<Provider store={store}>
<App />
</Provider>
</React.StrictMode>
);

View File

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