system-copyright-react/src/App.tsx

49 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-03-11 19:13:42 +08:00
import Head from './layout/head/Head.tsx';
2024-03-12 18:53:51 +08:00
import Body from './layout/body/Body.tsx';
2024-03-11 19:13:42 +08:00
import Foot from './layout/foot/Foot.tsx';
2024-03-26 21:09:41 +08:00
import {
GlobalContext,
GlobalData,
GlobalDataAction,
GlobalDataActionType,
GlobalDispatchContext
} from "./context/GlobalContext.ts";
import {Reducer, useReducer} from "react";
2024-03-16 23:12:49 +08:00
2024-03-11 19:13:42 +08:00
const App: React.FC = () => {
2024-03-26 21:09:41 +08:00
const globalDataReducer = (state: GlobalData, action: GlobalDataAction) => {
if (action.type == GlobalDataActionType.REFRESH_SELF) {
if(action.user) {
state.user.balance = action.user.balance;
state.user.nickname = action.user.nickname;
state.user.username = action.user.username;
state.user.hasUserInfo = action.user.hasUserInfo;
}
}
return {
...state
}
2024-03-26 11:54:30 +08:00
}
2024-03-26 21:09:41 +08:00
const [globalData, dispatch] = useReducer<Reducer<GlobalData, GlobalDataAction>>(globalDataReducer, {
user: {
balance: '0',
username: '',
nickname: '',
hasUserInfo: false
}
});
2024-03-26 11:54:30 +08:00
2024-03-11 19:13:42 +08:00
return (
2024-03-14 18:33:58 +08:00
<>
2024-03-26 11:54:30 +08:00
<GlobalContext.Provider value={globalData}>
2024-03-26 21:09:41 +08:00
<GlobalDispatchContext.Provider value={dispatch}>
<Head/>
<Body/>
<Foot/>
</GlobalDispatchContext.Provider>
2024-03-26 11:54:30 +08:00
</GlobalContext.Provider>
2024-03-14 18:33:58 +08:00
</>
2024-03-11 19:13:42 +08:00
);
};
export default App;