Add hooks
This commit is contained in:
parent
b022820e40
commit
eaba4d56f2
|
@ -1,9 +1,10 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Provider, useSelector } from 'react-redux';
|
import { Provider, useSelector } from 'react-redux';
|
||||||
import { RootState, store } from './store';
|
import { AppActions, RootState, store } 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';
|
||||||
|
import AppActionHook from './components/AppActionHook';
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const show = useSelector((state: RootState) => state.state.show);
|
const show = useSelector((state: RootState) => state.state.show);
|
||||||
|
@ -11,6 +12,25 @@ function App() {
|
||||||
show && (
|
show && (
|
||||||
<NextUIProvider>
|
<NextUIProvider>
|
||||||
<Provider store={store}>
|
<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
|
<Box
|
||||||
width={'100%'}
|
width={'100%'}
|
||||||
height={'100%'}
|
height={'100%'}
|
||||||
|
|
36
web/src/components/AppActionHook.tsx
Normal file
36
web/src/components/AppActionHook.tsx
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
import { AppActions, AppDispatch } from '../store';
|
||||||
|
import { useNuiEvent } from '../hooks/useNuiEvent';
|
||||||
|
import { useDispatch } from 'react-redux';
|
||||||
|
import { Box, Text } from 'lr-components';
|
||||||
|
import { isEnvBrowser } from '../utils/misc';
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
action: keyof typeof AppActions;
|
||||||
|
}
|
||||||
|
|
||||||
|
function AppActionHook(props: Props) {
|
||||||
|
const dispatch = useDispatch<AppDispatch>();
|
||||||
|
const isDev = isEnvBrowser();
|
||||||
|
console.log('AppActionHook', props.action);
|
||||||
|
useNuiEvent(props.action, (data) => {
|
||||||
|
//dynamicDispatch(action, data);
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
const a = AppActions[props.action] as any;
|
||||||
|
dispatch(a(data));
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
isDev && (
|
||||||
|
<Box
|
||||||
|
rPadding={5}
|
||||||
|
backgroundColor='#1f1f1f'
|
||||||
|
rBorderRadius={10}
|
||||||
|
opacity={0.5}
|
||||||
|
>
|
||||||
|
<Text>{props.action}</Text>
|
||||||
|
</Box>
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AppActionHook;
|
|
@ -4,6 +4,8 @@ export const store = configureStore({
|
||||||
reducer: {},
|
reducer: {},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const AppActions = {};
|
||||||
|
|
||||||
// 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>;
|
||||||
// Inferred type: {posts: PostsState, comments: CommentsState, users: UsersState}
|
// Inferred type: {posts: PostsState, comments: CommentsState, users: UsersState}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user