mirror of https://github.com/msgbyte/tailchat
feat: 增加网络状态的全局管理
parent
61aefad27a
commit
d55993ca13
@ -0,0 +1,28 @@
|
||||
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
||||
|
||||
export interface GlobalState {
|
||||
/**
|
||||
* 网络状态
|
||||
*/
|
||||
networkStatus: 'initial' | 'connected' | 'reconnecting' | 'disconnected';
|
||||
}
|
||||
|
||||
const initialState: GlobalState = {
|
||||
networkStatus: 'initial',
|
||||
};
|
||||
|
||||
const globalSlice = createSlice({
|
||||
name: 'global',
|
||||
initialState,
|
||||
reducers: {
|
||||
setNetworkStatus(
|
||||
state,
|
||||
action: PayloadAction<GlobalState['networkStatus']>
|
||||
) {
|
||||
state.networkStatus = action.payload;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const globalActions = globalSlice.actions;
|
||||
export const globalReducer = globalSlice.reducer;
|
Loading…
Reference in New Issue