Migrate redux server action/reducer to ts
This commit is contained in:
parent
2946c4724e
commit
a75d372026
|
@ -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
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -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
|
||||||
|
};
|
||||||
|
}
|
|
@ -1,14 +1,17 @@
|
||||||
|
// ACTIONS
|
||||||
import { TActionSelectedUsers } from '../../actions/selectedUsers';
|
import { TActionSelectedUsers } from '../../actions/selectedUsers';
|
||||||
import { TActionActiveUsers } from '../../actions/activeUsers';
|
import { TActionActiveUsers } from '../../actions/activeUsers';
|
||||||
|
import { TActionServer } from '../../actions/server';
|
||||||
// REDUCERS
|
// REDUCERS
|
||||||
import { IActiveUsers } from '../../reducers/activeUsers';
|
import { IActiveUsers } from '../../reducers/activeUsers';
|
||||||
import { ISelectedUsers } from '../../reducers/selectedUsers';
|
import { ISelectedUsers } from '../../reducers/selectedUsers';
|
||||||
|
import { IServer } from '../../reducers/server';
|
||||||
|
|
||||||
export interface IApplicationState {
|
export interface IApplicationState {
|
||||||
settings: any;
|
settings: any;
|
||||||
login: any;
|
login: any;
|
||||||
meteor: any;
|
meteor: any;
|
||||||
server: any;
|
server: IServer;
|
||||||
selectedUsers: ISelectedUsers;
|
selectedUsers: ISelectedUsers;
|
||||||
createChannel: any;
|
createChannel: any;
|
||||||
app: any;
|
app: any;
|
||||||
|
@ -28,4 +31,4 @@ export interface IApplicationState {
|
||||||
roles: any;
|
roles: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TApplicationActions = TActionActiveUsers & TActionSelectedUsers;
|
export type TApplicationActions = TActionActiveUsers & TActionSelectedUsers & TActionServer;
|
||||||
|
|
|
@ -1,6 +1,18 @@
|
||||||
|
import { TApplicationActions } from '../definitions';
|
||||||
import { SERVER } from '../actions/actionsTypes';
|
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,
|
connecting: false,
|
||||||
connected: false,
|
connected: false,
|
||||||
failure: false,
|
failure: false,
|
||||||
|
@ -11,7 +23,7 @@ const initialState = {
|
||||||
changingServer: false
|
changingServer: false
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function server(state = initialState, action) {
|
export default function server(state = initialState, action: TApplicationActions): IServer {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case SERVER.REQUEST:
|
case SERVER.REQUEST:
|
||||||
return {
|
return {
|
||||||
|
@ -34,7 +46,7 @@ export default function server(state = initialState, action) {
|
||||||
connecting: true,
|
connecting: true,
|
||||||
connected: false,
|
connected: false,
|
||||||
loading: true,
|
loading: true,
|
||||||
changingServer: action.changeServer
|
changingServer: action.changeServer!
|
||||||
};
|
};
|
||||||
case SERVER.SELECT_SUCCESS:
|
case SERVER.SELECT_SUCCESS:
|
||||||
return {
|
return {
|
Loading…
Reference in New Issue