From a75d372026c27e4a64f70572b322dc34c5983af9 Mon Sep 17 00:00:00 2001 From: Gerzon Z Date: Tue, 18 Jan 2022 11:59:43 -0400 Subject: [PATCH] Migrate redux server action/reducer to ts --- app/actions/server.js | 60 ------------------ app/actions/server.ts | 90 +++++++++++++++++++++++++++ app/definitions/redux/index.ts | 7 ++- app/reducers/{server.js => server.ts} | 18 +++++- 4 files changed, 110 insertions(+), 65 deletions(-) delete mode 100644 app/actions/server.js create mode 100644 app/actions/server.ts rename app/reducers/{server.js => server.ts} (73%) diff --git a/app/actions/server.js b/app/actions/server.js deleted file mode 100644 index fea239450..000000000 --- a/app/actions/server.js +++ /dev/null @@ -1,60 +0,0 @@ -import { SERVER } from './actionsTypes'; - -export function selectServerRequest(server, version, fetchVersion = true, changeServer = false) { - return { - type: SERVER.SELECT_REQUEST, - server, - version, - fetchVersion, - changeServer - }; -} - -export function selectServerSuccess(server, version) { - return { - type: SERVER.SELECT_SUCCESS, - server, - version - }; -} - -export function selectServerFailure() { - return { - type: SERVER.SELECT_FAILURE - }; -} - -export function serverRequest(server, username = null, fromServerHistory = false) { - return { - type: SERVER.REQUEST, - server, - username, - fromServerHistory - }; -} - -export function serverSuccess() { - return { - type: SERVER.SUCCESS - }; -} - -export function serverFailure(err) { - return { - type: SERVER.FAILURE, - err - }; -} - -export function serverInitAdd(previousServer) { - return { - type: SERVER.INIT_ADD, - previousServer - }; -} - -export function serverFinishAdd() { - return { - type: SERVER.FINISH_ADD - }; -} diff --git a/app/actions/server.ts b/app/actions/server.ts new file mode 100644 index 000000000..f635e412f --- /dev/null +++ b/app/actions/server.ts @@ -0,0 +1,90 @@ +import { Action } from 'redux'; + +import { SERVER } from './actionsTypes'; + +interface ISelectServer extends Action { + server: string; + version?: string; + fetchVersion?: boolean; + changeServer?: boolean; +} + +interface ISelectServerSuccess extends Action { + server: string; + version: string; +} + +interface IServer extends Action { + server: string; + username: string | null; + fromServerHistory: boolean; +} + +interface IServerInit extends Action { + previousServer: string; +} + +interface IServerFailure extends Action { + err: any; +} + +export type TActionServer = ISelectServer & ISelectServerSuccess & IServer & IServerInit & IServerFailure; + +export function selectServerRequest(server: string, version?: string, fetchVersion = true, changeServer = false): ISelectServer { + return { + type: SERVER.SELECT_REQUEST, + server, + version, + fetchVersion, + changeServer + }; +} + +export function selectServerSuccess(server: string, version: string): ISelectServerSuccess { + return { + type: SERVER.SELECT_SUCCESS, + server, + version + }; +} + +export function selectServerFailure(): Action { + return { + type: SERVER.SELECT_FAILURE + }; +} + +export function serverRequest(server: string, username = null, fromServerHistory = false): IServer { + return { + type: SERVER.REQUEST, + server, + username, + fromServerHistory + }; +} + +export function serverSuccess(): Action { + return { + type: SERVER.SUCCESS + }; +} + +export function serverFailure(err: any): IServerFailure { + return { + type: SERVER.FAILURE, + err + }; +} + +export function serverInitAdd(previousServer: string): IServerInit { + return { + type: SERVER.INIT_ADD, + previousServer + }; +} + +export function serverFinishAdd(): Action { + return { + type: SERVER.FINISH_ADD + }; +} diff --git a/app/definitions/redux/index.ts b/app/definitions/redux/index.ts index e95763e29..2ba1c7e08 100644 --- a/app/definitions/redux/index.ts +++ b/app/definitions/redux/index.ts @@ -1,14 +1,17 @@ +// ACTIONS import { TActionSelectedUsers } from '../../actions/selectedUsers'; import { TActionActiveUsers } from '../../actions/activeUsers'; +import { TActionServer } from '../../actions/server'; // REDUCERS import { IActiveUsers } from '../../reducers/activeUsers'; import { ISelectedUsers } from '../../reducers/selectedUsers'; +import { IServer } from '../../reducers/server'; export interface IApplicationState { settings: any; login: any; meteor: any; - server: any; + server: IServer; selectedUsers: ISelectedUsers; createChannel: any; app: any; @@ -28,4 +31,4 @@ export interface IApplicationState { roles: any; } -export type TApplicationActions = TActionActiveUsers & TActionSelectedUsers; +export type TApplicationActions = TActionActiveUsers & TActionSelectedUsers & TActionServer; diff --git a/app/reducers/server.js b/app/reducers/server.ts similarity index 73% rename from app/reducers/server.js rename to app/reducers/server.ts index 14c7bbfdf..906fe4148 100644 --- a/app/reducers/server.js +++ b/app/reducers/server.ts @@ -1,6 +1,18 @@ +import { TApplicationActions } from '../definitions'; import { SERVER } from '../actions/actionsTypes'; -const initialState = { +export interface IServer { + connecting: boolean; + connected: boolean; + failure: boolean; + server: string; + version: string | null; + loading: boolean; + previousServer: string | null; + changingServer: boolean; +} + +const initialState: IServer = { connecting: false, connected: false, failure: false, @@ -11,7 +23,7 @@ const initialState = { changingServer: false }; -export default function server(state = initialState, action) { +export default function server(state = initialState, action: TApplicationActions): IServer { switch (action.type) { case SERVER.REQUEST: return { @@ -34,7 +46,7 @@ export default function server(state = initialState, action) { connecting: true, connected: false, loading: true, - changingServer: action.changeServer + changingServer: action.changeServer! }; case SERVER.SELECT_SUCCESS: return {