chore: init reducer/app migration to ts
This commit is contained in:
parent
bc92a4f29d
commit
16e04c7232
|
@ -2,8 +2,8 @@ const REQUEST = 'REQUEST';
|
||||||
const SUCCESS = 'SUCCESS';
|
const SUCCESS = 'SUCCESS';
|
||||||
const FAILURE = 'FAILURE';
|
const FAILURE = 'FAILURE';
|
||||||
const defaultTypes = [REQUEST, SUCCESS, FAILURE];
|
const defaultTypes = [REQUEST, SUCCESS, FAILURE];
|
||||||
function createRequestTypes(base = {}, types = defaultTypes): Record<any, any> {
|
function createRequestTypes(base = {}, types = defaultTypes): Record<string, string> {
|
||||||
const res: Record<any, any> = {};
|
const res: Record<string, string> = {};
|
||||||
types.forEach(type => (res[type] = `${base}_${type}`));
|
types.forEach(type => (res[type] = `${base}_${type}`));
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { Action } from 'redux';
|
||||||
import { IActiveUsers } from '../reducers/activeUsers';
|
import { IActiveUsers } from '../reducers/activeUsers';
|
||||||
import { SET_ACTIVE_USERS } from './actionsTypes';
|
import { SET_ACTIVE_USERS } from './actionsTypes';
|
||||||
|
|
||||||
export interface ISetActiveUsers extends Action {
|
interface ISetActiveUsers extends Action {
|
||||||
activeUsers: IActiveUsers;
|
activeUsers: IActiveUsers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,39 +0,0 @@
|
||||||
import { APP } from './actionsTypes';
|
|
||||||
|
|
||||||
export const ROOT_OUTSIDE = 'outside';
|
|
||||||
export const ROOT_INSIDE = 'inside';
|
|
||||||
export const ROOT_LOADING = 'loading';
|
|
||||||
export const ROOT_SET_USERNAME = 'setUsername';
|
|
||||||
|
|
||||||
export function appStart({ root, ...args }) {
|
|
||||||
return {
|
|
||||||
type: APP.START,
|
|
||||||
root,
|
|
||||||
...args
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function appReady() {
|
|
||||||
return {
|
|
||||||
type: APP.READY
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function appInit() {
|
|
||||||
return {
|
|
||||||
type: APP.INIT
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function appInitLocalSettings() {
|
|
||||||
return {
|
|
||||||
type: APP.INIT_LOCAL_SETTINGS
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function setMasterDetail(isMasterDetail) {
|
|
||||||
return {
|
|
||||||
type: APP.SET_MASTER_DETAIL,
|
|
||||||
isMasterDetail
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
import { Action } from 'redux';
|
||||||
|
|
||||||
|
import { TRootEnum } from '../definitions';
|
||||||
|
import { APP } from './actionsTypes';
|
||||||
|
|
||||||
|
export const ROOT_OUTSIDE = 'outside';
|
||||||
|
export const ROOT_INSIDE = 'inside';
|
||||||
|
export const ROOT_LOADING = 'loading';
|
||||||
|
export const ROOT_SET_USERNAME = 'setUsername';
|
||||||
|
|
||||||
|
interface IAppStart extends Action {
|
||||||
|
root: TRootEnum;
|
||||||
|
text?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ISetMasterDetail extends Action {
|
||||||
|
isMasterDetail: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type TActionApp = IAppStart & ISetMasterDetail;
|
||||||
|
|
||||||
|
export function appStart({ root, ...args }: { root: TRootEnum }): IAppStart {
|
||||||
|
return {
|
||||||
|
type: APP.START,
|
||||||
|
root,
|
||||||
|
...args
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function appReady(): Action {
|
||||||
|
return {
|
||||||
|
type: APP.READY
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function appInit(): Action {
|
||||||
|
return {
|
||||||
|
type: APP.INIT
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function appInitLocalSettings(): Action {
|
||||||
|
return {
|
||||||
|
type: APP.INIT_LOCAL_SETTINGS
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setMasterDetail(isMasterDetail: boolean): ISetMasterDetail {
|
||||||
|
return {
|
||||||
|
type: APP.SET_MASTER_DETAIL,
|
||||||
|
isMasterDetail
|
||||||
|
};
|
||||||
|
}
|
|
@ -10,3 +10,4 @@ export interface IBaseScreen<T extends Record<string, object | undefined>, S ext
|
||||||
}
|
}
|
||||||
|
|
||||||
export * from './redux';
|
export * from './redux';
|
||||||
|
export * from './redux/TRootEnum';
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
export type TRootEnum = {
|
||||||
|
ROOT_OUTSIDE: 'outside';
|
||||||
|
ROOT_INSIDE: 'inside';
|
||||||
|
ROOT_LOADING: 'loading';
|
||||||
|
ROOT_SET_USERNAME: 'setUsername';
|
||||||
|
};
|
|
@ -1,8 +1,10 @@
|
||||||
import { TActionSelectedUsers } from '../../actions/selectedUsers';
|
import { TActionSelectedUsers } from '../../actions/selectedUsers';
|
||||||
import { TActionActiveUsers } from '../../actions/activeUsers';
|
import { TActionActiveUsers } from '../../actions/activeUsers';
|
||||||
|
import { TActionApp } from '../../actions/app';
|
||||||
// REDUCERS
|
// REDUCERS
|
||||||
import { IActiveUsers } from '../../reducers/activeUsers';
|
import { IActiveUsers } from '../../reducers/activeUsers';
|
||||||
import { ISelectedUsers } from '../../reducers/selectedUsers';
|
import { ISelectedUsers } from '../../reducers/selectedUsers';
|
||||||
|
import { IApp } from '../../reducers/app';
|
||||||
|
|
||||||
export interface IApplicationState {
|
export interface IApplicationState {
|
||||||
settings: any;
|
settings: any;
|
||||||
|
@ -11,7 +13,7 @@ export interface IApplicationState {
|
||||||
server: any;
|
server: any;
|
||||||
selectedUsers: ISelectedUsers;
|
selectedUsers: ISelectedUsers;
|
||||||
createChannel: any;
|
createChannel: any;
|
||||||
app: any;
|
app: IApp;
|
||||||
room: any;
|
room: any;
|
||||||
rooms: any;
|
rooms: any;
|
||||||
sortPreferences: any;
|
sortPreferences: any;
|
||||||
|
@ -28,4 +30,4 @@ export interface IApplicationState {
|
||||||
roles: any;
|
roles: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TApplicationActions = TActionActiveUsers & TActionSelectedUsers;
|
export type TApplicationActions = TActionActiveUsers & TActionSelectedUsers & TActionApp;
|
||||||
|
|
|
@ -1,15 +1,26 @@
|
||||||
|
import { TActionApp } from '../actions/app';
|
||||||
|
import { TRootEnum } from '../definitions';
|
||||||
import { APP, APP_STATE } from '../actions/actionsTypes';
|
import { APP, APP_STATE } from '../actions/actionsTypes';
|
||||||
|
|
||||||
const initialState = {
|
export interface IApp {
|
||||||
root: null,
|
root?: TRootEnum;
|
||||||
|
isMasterDetail: boolean;
|
||||||
|
text?: string;
|
||||||
|
ready: boolean;
|
||||||
|
foreground: boolean;
|
||||||
|
background: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const initialState: IApp = {
|
||||||
|
root: undefined,
|
||||||
isMasterDetail: false,
|
isMasterDetail: false,
|
||||||
text: null,
|
text: undefined,
|
||||||
ready: false,
|
ready: false,
|
||||||
foreground: true,
|
foreground: true,
|
||||||
background: false
|
background: false
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function app(state = initialState, action) {
|
export default function app(state = initialState, action: TActionApp): IApp {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case APP_STATE.FOREGROUND:
|
case APP_STATE.FOREGROUND:
|
||||||
return {
|
return {
|
Loading…
Reference in New Issue