diff --git a/app/actions/server.js b/app/actions/server.js deleted file mode 100644 index fea23945..00000000 --- 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 00000000..f635e412 --- /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 e95763e2..2ba1c7e0 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 14c7bbfd..906fe414 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 {