2022-07-20 15:01:16 +00:00
|
|
|
import { NetInfoCellularGeneration, NetInfoStateType } from '@react-native-community/netinfo';
|
|
|
|
|
|
|
|
import ReducerRegistry from '../redux/ReducerRegistry';
|
|
|
|
import { assign } from '../redux/functions';
|
2019-08-22 15:08:34 +00:00
|
|
|
|
|
|
|
import { SET_NETWORK_INFO, _STORE_NETWORK_INFO_CLEANUP } from './actionTypes';
|
|
|
|
import { STORE_NAME } from './constants';
|
|
|
|
|
|
|
|
const DEFAULT_STATE = {
|
|
|
|
isOnline: true
|
|
|
|
};
|
|
|
|
|
2022-07-20 15:01:16 +00:00
|
|
|
export interface INetInfoState {
|
|
|
|
_cleanup?: Function;
|
|
|
|
cellularGeneration?: NetInfoCellularGeneration;
|
|
|
|
details?: Object;
|
|
|
|
isOnline?: boolean;
|
|
|
|
networkType?: NetInfoStateType;
|
|
|
|
}
|
|
|
|
|
2019-08-22 15:08:34 +00:00
|
|
|
/**
|
|
|
|
* The base/net-info feature's reducer.
|
|
|
|
*/
|
2022-09-05 09:05:07 +00:00
|
|
|
ReducerRegistry.register<INetInfoState>(STORE_NAME, (state = DEFAULT_STATE, action): INetInfoState => {
|
2019-08-22 15:08:34 +00:00
|
|
|
switch (action.type) {
|
|
|
|
case SET_NETWORK_INFO:
|
|
|
|
return assign(state, {
|
|
|
|
isOnline: action.isOnline,
|
|
|
|
networkType: action.networkType,
|
|
|
|
cellularGeneration: action.cellularGeneration,
|
|
|
|
details: action.details
|
|
|
|
});
|
|
|
|
case _STORE_NETWORK_INFO_CLEANUP:
|
|
|
|
return assign(state, {
|
|
|
|
_cleanup: action.cleanup
|
|
|
|
});
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
});
|