From eaba4d56f2910af1fa7032a495d03624a288dcf0 Mon Sep 17 00:00:00 2001 From: Lorraxs Date: Mon, 11 Dec 2023 23:41:33 +0700 Subject: [PATCH] Add hooks --- web/src/App.tsx | 22 ++++++++++++++++- web/src/components/AppActionHook.tsx | 36 ++++++++++++++++++++++++++++ web/src/store/index.ts | 2 ++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 web/src/components/AppActionHook.tsx diff --git a/web/src/App.tsx b/web/src/App.tsx index 27cbd71..4cba465 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -1,9 +1,10 @@ import React from 'react'; import { Provider, useSelector } from 'react-redux'; -import { RootState, store } from './store'; +import { AppActions, RootState, store } from './store'; import { ToastContainer } from 'react-toastify'; import { Box } from 'lr-components'; import { NextUIProvider } from '@nextui-org/react'; +import AppActionHook from './components/AppActionHook'; function App() { const show = useSelector((state: RootState) => state.state.show); @@ -11,6 +12,25 @@ function App() { show && ( + + {Object.keys(AppActions).map((action) => { + return ( + + ); + })} + (); + 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 && ( + + {props.action} + + ) + ); +} + +export default AppActionHook; diff --git a/web/src/store/index.ts b/web/src/store/index.ts index d848917..32ea123 100644 --- a/web/src/store/index.ts +++ b/web/src/store/index.ts @@ -4,6 +4,8 @@ export const store = configureStore({ reducer: {}, }); +export const AppActions = {}; + // Infer the `RootState` and `AppDispatch` types from the store itself export type RootState = ReturnType; // Inferred type: {posts: PostsState, comments: CommentsState, users: UsersState}