diff --git a/projects/ucap-webmessenger-app/src/app/store/setting/index.ts b/projects/ucap-webmessenger-app/src/app/store/setting/index.ts index baab7d4d..bdf395ba 100644 --- a/projects/ucap-webmessenger-app/src/app/store/setting/index.ts +++ b/projects/ucap-webmessenger-app/src/app/store/setting/index.ts @@ -11,7 +11,7 @@ export const effects: Type[] = [VersionInfoStore.Effects]; export function reducers(state: State | undefined, action: Action) { return combineReducers({ - versionInfo: VersionInfoStore.reducers + versionInfo: VersionInfoStore.reducer })(state, action); } diff --git a/projects/ucap-webmessenger-app/src/app/store/setting/version-info/reducers.ts b/projects/ucap-webmessenger-app/src/app/store/setting/version-info/reducers.ts index 28e58c6f..a89a373d 100644 --- a/projects/ucap-webmessenger-app/src/app/store/setting/version-info/reducers.ts +++ b/projects/ucap-webmessenger-app/src/app/store/setting/version-info/reducers.ts @@ -1,6 +1,23 @@ -import { Action, combineReducers } from '@ngrx/store'; -import { State } from './state'; +import { createReducer, on } from '@ngrx/store'; +import { initialState } from './state'; +import { fetchSuccess } from './actions'; -export function reducers(state: State | undefined, action: Action) { - return combineReducers({})(state, action); -} +export const reducer = createReducer( + initialState, + on(fetchSuccess, (state, action) => { + return { + ...state, + profileImageRoot: action.profileRoot, + profileImageUploadUrl: action.profileUploadUrl, + fileUploadMaxSize: + !!action.fileAllowSize && + !isNaN(action.fileAllowSize) && + 0 < action.fileAllowSize + ? action.fileAllowSize + : 0, + fileUploadUrl: action.uploadUrl, + fileDownloadUrl: action.downloadUrl, + serverIp: action.serverIp + }; + }) +); diff --git a/projects/ucap-webmessenger-app/src/app/store/setting/version-info/state.ts b/projects/ucap-webmessenger-app/src/app/store/setting/version-info/state.ts index aacfe4f7..422c0df7 100644 --- a/projects/ucap-webmessenger-app/src/app/store/setting/version-info/state.ts +++ b/projects/ucap-webmessenger-app/src/app/store/setting/version-info/state.ts @@ -1,10 +1,49 @@ -import { Selector } from '@ngrx/store'; +import { Selector, createSelector } from '@ngrx/store'; // tslint:disable-next-line: no-empty-interface -export interface State {} +export interface State { + profileImageRoot: string | null; + profileImageUploadUrl: string | null; + fileUploadMaxSize: number | null; + fileUploadUrl: string | null; + fileDownloadUrl: string | null; + serverIp: string | null; +} -export const initialState: State = {}; +export const initialState: State = { + profileImageRoot: null, + profileImageUploadUrl: null, + fileUploadMaxSize: null, + fileUploadUrl: null, + fileDownloadUrl: null, + serverIp: null +}; export function selectors(selector: Selector) { - return {}; + return { + profileImageRoot: createSelector( + selector, + (state: State) => state.profileImageRoot + ), + profileImageUploadUrl: createSelector( + selector, + (state: State) => state.profileImageUploadUrl + ), + fileUploadMaxSize: createSelector( + selector, + (state: State) => state.fileUploadMaxSize + ), + fileUploadUrl: createSelector( + selector, + (state: State) => state.fileUploadUrl + ), + fileDownloadUrl: createSelector( + selector, + (state: State) => state.fileDownloadUrl + ), + serverIp: createSelector( + selector, + (state: State) => state.serverIp + ) + }; }