From 16e04c7232d85d3e2edc9d6e7d93f03b31139177 Mon Sep 17 00:00:00 2001 From: GleidsonDaniel Date: Fri, 7 Jan 2022 15:12:59 -0300 Subject: [PATCH] chore: init reducer/app migration to ts --- app/actions/actionsTypes.ts | 4 +-- app/actions/activeUsers.ts | 2 +- app/actions/app.js | 39 ---------------------- app/actions/app.ts | 53 ++++++++++++++++++++++++++++++ app/definitions/index.ts | 1 + app/definitions/redux/TRootEnum.ts | 6 ++++ app/definitions/redux/index.ts | 6 ++-- app/reducers/{app.js => app.ts} | 19 ++++++++--- 8 files changed, 82 insertions(+), 48 deletions(-) delete mode 100644 app/actions/app.js create mode 100644 app/actions/app.ts create mode 100644 app/definitions/redux/TRootEnum.ts rename app/reducers/{app.js => app.ts} (65%) diff --git a/app/actions/actionsTypes.ts b/app/actions/actionsTypes.ts index ad2d1718d..f8852f28c 100644 --- a/app/actions/actionsTypes.ts +++ b/app/actions/actionsTypes.ts @@ -2,8 +2,8 @@ const REQUEST = 'REQUEST'; const SUCCESS = 'SUCCESS'; const FAILURE = 'FAILURE'; const defaultTypes = [REQUEST, SUCCESS, FAILURE]; -function createRequestTypes(base = {}, types = defaultTypes): Record { - const res: Record = {}; +function createRequestTypes(base = {}, types = defaultTypes): Record { + const res: Record = {}; types.forEach(type => (res[type] = `${base}_${type}`)); return res; } diff --git a/app/actions/activeUsers.ts b/app/actions/activeUsers.ts index 737ae86b3..1612e3a8c 100644 --- a/app/actions/activeUsers.ts +++ b/app/actions/activeUsers.ts @@ -3,7 +3,7 @@ import { Action } from 'redux'; import { IActiveUsers } from '../reducers/activeUsers'; import { SET_ACTIVE_USERS } from './actionsTypes'; -export interface ISetActiveUsers extends Action { +interface ISetActiveUsers extends Action { activeUsers: IActiveUsers; } diff --git a/app/actions/app.js b/app/actions/app.js deleted file mode 100644 index fe6981d67..000000000 --- a/app/actions/app.js +++ /dev/null @@ -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 - }; -} diff --git a/app/actions/app.ts b/app/actions/app.ts new file mode 100644 index 000000000..ece16ecdb --- /dev/null +++ b/app/actions/app.ts @@ -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 + }; +} diff --git a/app/definitions/index.ts b/app/definitions/index.ts index f9ca20d4a..4f23911bb 100644 --- a/app/definitions/index.ts +++ b/app/definitions/index.ts @@ -10,3 +10,4 @@ export interface IBaseScreen, S ext } export * from './redux'; +export * from './redux/TRootEnum'; diff --git a/app/definitions/redux/TRootEnum.ts b/app/definitions/redux/TRootEnum.ts new file mode 100644 index 000000000..0c8f801cd --- /dev/null +++ b/app/definitions/redux/TRootEnum.ts @@ -0,0 +1,6 @@ +export type TRootEnum = { + ROOT_OUTSIDE: 'outside'; + ROOT_INSIDE: 'inside'; + ROOT_LOADING: 'loading'; + ROOT_SET_USERNAME: 'setUsername'; +}; diff --git a/app/definitions/redux/index.ts b/app/definitions/redux/index.ts index e95763e29..59eb7c921 100644 --- a/app/definitions/redux/index.ts +++ b/app/definitions/redux/index.ts @@ -1,8 +1,10 @@ import { TActionSelectedUsers } from '../../actions/selectedUsers'; import { TActionActiveUsers } from '../../actions/activeUsers'; +import { TActionApp } from '../../actions/app'; // REDUCERS import { IActiveUsers } from '../../reducers/activeUsers'; import { ISelectedUsers } from '../../reducers/selectedUsers'; +import { IApp } from '../../reducers/app'; export interface IApplicationState { settings: any; @@ -11,7 +13,7 @@ export interface IApplicationState { server: any; selectedUsers: ISelectedUsers; createChannel: any; - app: any; + app: IApp; room: any; rooms: any; sortPreferences: any; @@ -28,4 +30,4 @@ export interface IApplicationState { roles: any; } -export type TApplicationActions = TActionActiveUsers & TActionSelectedUsers; +export type TApplicationActions = TActionActiveUsers & TActionSelectedUsers & TActionApp; diff --git a/app/reducers/app.js b/app/reducers/app.ts similarity index 65% rename from app/reducers/app.js rename to app/reducers/app.ts index 4ed04dcd7..302bff8a7 100644 --- a/app/reducers/app.js +++ b/app/reducers/app.ts @@ -1,15 +1,26 @@ +import { TActionApp } from '../actions/app'; +import { TRootEnum } from '../definitions'; import { APP, APP_STATE } from '../actions/actionsTypes'; -const initialState = { - root: null, +export interface IApp { + root?: TRootEnum; + isMasterDetail: boolean; + text?: string; + ready: boolean; + foreground: boolean; + background: boolean; +} + +const initialState: IApp = { + root: undefined, isMasterDetail: false, - text: null, + text: undefined, ready: false, foreground: true, background: false }; -export default function app(state = initialState, action) { +export default function app(state = initialState, action: TActionApp): IApp { switch (action.type) { case APP_STATE.FOREGROUND: return {