2022-01-20 21:07:11 +00:00
|
|
|
import { TActionServer } from '../actions/server';
|
2017-08-18 21:30:16 +00:00
|
|
|
import { SERVER } from '../actions/actionsTypes';
|
|
|
|
|
2022-01-18 15:59:43 +00:00
|
|
|
export interface IServer {
|
|
|
|
connecting: boolean;
|
|
|
|
connected: boolean;
|
|
|
|
failure: boolean;
|
|
|
|
server: string;
|
|
|
|
version: string | null;
|
|
|
|
loading: boolean;
|
|
|
|
previousServer: string | null;
|
|
|
|
changingServer: boolean;
|
|
|
|
}
|
|
|
|
|
2022-01-19 16:30:45 +00:00
|
|
|
export const initialState: IServer = {
|
2017-09-01 19:42:50 +00:00
|
|
|
connecting: false,
|
|
|
|
connected: false,
|
|
|
|
failure: false,
|
2018-04-24 19:34:03 +00:00
|
|
|
server: '',
|
2019-04-17 17:01:03 +00:00
|
|
|
version: null,
|
2018-08-10 17:26:36 +00:00
|
|
|
loading: true,
|
2021-01-13 14:16:00 +00:00
|
|
|
previousServer: null,
|
|
|
|
changingServer: false
|
2017-09-01 19:42:50 +00:00
|
|
|
};
|
|
|
|
|
2022-01-20 21:07:11 +00:00
|
|
|
export default function server(state = initialState, action: TActionServer): IServer {
|
2017-08-18 21:30:16 +00:00
|
|
|
switch (action.type) {
|
2017-09-01 19:42:50 +00:00
|
|
|
case SERVER.REQUEST:
|
2017-11-13 12:58:35 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2017-09-01 19:42:50 +00:00
|
|
|
connecting: true,
|
2018-08-31 18:13:30 +00:00
|
|
|
failure: false
|
2017-09-01 19:42:50 +00:00
|
|
|
};
|
|
|
|
case SERVER.FAILURE:
|
2017-11-13 12:58:35 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2017-09-01 19:42:50 +00:00
|
|
|
connecting: false,
|
|
|
|
connected: false,
|
2018-08-31 18:13:30 +00:00
|
|
|
failure: true
|
2018-04-24 19:34:03 +00:00
|
|
|
};
|
2018-08-01 19:35:06 +00:00
|
|
|
case SERVER.SELECT_REQUEST:
|
2018-04-24 19:34:03 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
server: action.server,
|
2019-04-17 17:01:03 +00:00
|
|
|
version: action.version,
|
2018-08-10 17:26:36 +00:00
|
|
|
connecting: true,
|
|
|
|
connected: false,
|
2021-01-13 14:16:00 +00:00
|
|
|
loading: true,
|
2022-01-20 21:00:04 +00:00
|
|
|
changingServer: action.changeServer
|
2018-08-01 19:35:06 +00:00
|
|
|
};
|
|
|
|
case SERVER.SELECT_SUCCESS:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
server: action.server,
|
2019-04-17 17:01:03 +00:00
|
|
|
version: action.version,
|
2018-08-10 17:26:36 +00:00
|
|
|
connecting: false,
|
|
|
|
connected: true,
|
2021-01-13 14:16:00 +00:00
|
|
|
loading: false,
|
|
|
|
changingServer: false
|
2018-04-24 19:34:03 +00:00
|
|
|
};
|
2019-06-17 13:57:07 +00:00
|
|
|
case SERVER.SELECT_FAILURE:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
connecting: false,
|
|
|
|
connected: false,
|
2021-01-13 14:16:00 +00:00
|
|
|
loading: false,
|
|
|
|
changingServer: false
|
2019-06-17 13:57:07 +00:00
|
|
|
};
|
2018-08-31 18:13:30 +00:00
|
|
|
case SERVER.INIT_ADD:
|
|
|
|
return {
|
|
|
|
...state,
|
2020-06-15 14:00:46 +00:00
|
|
|
previousServer: action.previousServer
|
2018-08-31 18:13:30 +00:00
|
|
|
};
|
|
|
|
case SERVER.FINISH_ADD:
|
|
|
|
return {
|
|
|
|
...state,
|
2020-06-15 14:00:46 +00:00
|
|
|
previousServer: null
|
2018-08-31 18:13:30 +00:00
|
|
|
};
|
2017-08-18 21:30:16 +00:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|