import { createSlice , PayloadAction } from "@reduxjs/toolkit" ; import type { RootState } from '../store' ; import { connect , ConnectedProps } from 'react-redux' ; interface ConnectivityState { isLoading : boolean ; server : string ; } const initialState = { isLoading : false , server : "" , } ; export const connectivitySlice = createSlice ( { name : "connectivity" , initialState , reducers : { setServer : ( state , action ) => { state . server = action . payload ; } , setIsLoading : ( state , action ) => { state . isLoading = action . payload ; } } } ) ; const mapState = ( state ) => ( { isLoading : state . connectivity . isLoading } ) ; const mapDispatch = { toggleLoading : ( ) => ( { type : "TOGGLE_IS_LOADING" } ) } ; export const connector = connect ( mapState , mapDispatch ) ; type PropsFromRedux = ConnectedProps < typeof connector > ; export const { setServer , setIsLoading } = connectivitySlice . actions ; export const getServer = ( state ) => state . connectivity . server ; export type { PropsFromRedux } ; export default connectivitySlice . reducer ;