From d195fe0e194f04bdbd897c6c7186928dc1287810 Mon Sep 17 00:00:00 2001 From: leejinho Date: Fri, 27 Dec 2019 11:26:29 +0900 Subject: [PATCH] =?UTF-8?q?=EC=AA=BD=EC=A7=80=20store=20=EC=A0=81=EC=9A=A9?= =?UTF-8?q?=20>.=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../left-sidenav/message.component.html | 8 +- .../left-sidenav/message.component.ts | 198 ++++------------ .../src/app/store/messenger/index.ts | 7 + .../app/store/messenger/message/actions.ts | 42 ++++ .../app/store/messenger/message/effects.ts | 210 +++++++++++++++++ .../src/app/store/messenger/message/index.ts | 4 + .../app/store/messenger/message/reducers.ts | 100 ++++++++ .../src/app/store/messenger/message/state.ts | 218 ++++++++++++++++++ 8 files changed, 630 insertions(+), 157 deletions(-) create mode 100644 projects/ucap-webmessenger-app/src/app/store/messenger/message/actions.ts create mode 100644 projects/ucap-webmessenger-app/src/app/store/messenger/message/effects.ts create mode 100644 projects/ucap-webmessenger-app/src/app/store/messenger/message/index.ts create mode 100644 projects/ucap-webmessenger-app/src/app/store/messenger/message/reducers.ts create mode 100644 projects/ucap-webmessenger-app/src/app/store/messenger/message/state.ts diff --git a/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/left-sidenav/message.component.html b/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/left-sidenav/message.component.html index 2d357359..4d6b2812 100644 --- a/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/left-sidenav/message.component.html +++ b/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/left-sidenav/message.component.html @@ -51,7 +51,7 @@
; + messageSendList$: Observable; + messageReservationList$: Observable; + messageSearchList$: Observable; currentTabIndex = 0; defaultPageSize = 1000; // default - recieveCurrentPage = 0; // start index is 0. - sendCurrentPage = 0; // start index is 0. - reservationCurrentPage = 0; // start index is 0. - searchCurrentPage = 0; // start index is 0. currentTotalCount = 0; currentPage = 0; @@ -124,8 +119,23 @@ export class MessageBoxComponent searchMessageSearchType: [MessageSearchType.Name] }); + this.messageRetrieveList$ = this.store.pipe( + select(AppStore.MessengerSelector.MessageSelector.selectAllReceiveList) + ); + this.messageSendList$ = this.store.pipe( + select(AppStore.MessengerSelector.MessageSelector.selectAllSendList) + ); + this.messageReservationList$ = this.store.pipe( + select( + AppStore.MessengerSelector.MessageSelector.selectAllReservationList + ) + ); + this.messageSearchList$ = this.store.pipe( + select(AppStore.MessengerSelector.MessageSelector.selectAllSearchList) + ); + // 초기 검색은 수신함. - this.getRetrieveMessage(MessageType.Receive, this.recieveCurrentPage); + this.getRetrieveMessage(MessageType.Receive, 0); if (!!this.tabs) { this.tabs.realignInkBar(); @@ -139,51 +149,34 @@ export class MessageBoxComponent } } - ngOnDestroy(): void { - if (!!this.messageRecieveListSubscription) { - this.messageRecieveListSubscription.unsubscribe(); - } - if (!!this.messageSendListSubscription) { - this.messageSendListSubscription.unsubscribe(); - } - if (!!this.messageReservationListSubscription) { - this.messageReservationListSubscription.unsubscribe(); - } - if (!!this.messageSearchListSubscription) { - this.messageSearchListSubscription.unsubscribe(); - } - } + ngOnDestroy(): void {} onSelectedIndexTab(value: number) { this.tabs.selectedIndex = value; } onSelectedIndexChange(value: number) { this.currentTabIndex = value; - let type: MessageType; + let messageType: MessageType; switch (value) { case 0: // Recieve - type = MessageType.Receive; - this.recieveCurrentPage = 0; + messageType = MessageType.Receive; break; case 1: // Send - type = MessageType.Send; - this.sendCurrentPage = 0; + messageType = MessageType.Send; break; case 2: // Reservation - type = MessageType.Reservation; - this.reservationCurrentPage = 0; + messageType = MessageType.Reservation; break; } - this.getRetrieveMessage(type, 0); + this.getRetrieveMessage(messageType, 0); } /** 쪽지 검색 관련 */ onChangeSelection(event: MatSelectChange) { - this.searchCurrentPage = 0; this.getSearchMessage( event.value, this.fgSearchType.get('searchMessageSearchType').value, @@ -191,7 +184,6 @@ export class MessageBoxComponent ); } onChangeSearchType(event: MatRadioChange) { - this.searchCurrentPage = 0; this.getSearchMessage( this.fgSearchType.get('searchMessageType').value, event.value, @@ -202,8 +194,6 @@ export class MessageBoxComponent event.preventDefault(); event.stopPropagation(); - this.searchCurrentPage = 0; - this.getSearchMessage( MessageType.All, MessageSearchType.Name, @@ -216,125 +206,27 @@ export class MessageBoxComponent searchStr: string ) { this.isSearch = true; - this.messageSendListSubscription = this.messageApiService - .retrieveSearchMessage({ - userSeq: this.loginRes.userSeq, - deviceType: DeviceType.PC, - tokenKey: this.loginRes.tokenString, - type: messageType, - pageSize: this.defaultPageSize, - pageCount: this.searchCurrentPage, - searchTitle: searchType === MessageSearchType.Title ? searchStr : '', - searchName: searchType === MessageSearchType.Name ? searchStr : '', - searchContent: - searchType === MessageSearchType.Contents ? searchStr : '' - } as RetrieveSearchRequest) - .pipe( - take(1), - map(res => { - if (res.responseCode === MessageStatusCode.Success) { - this.currentTotalCount = res.totalCount; - this.currentPage = res.pageCount; - this.searchCurrentPage = res.pageCount; - this.messageList = res.messageList; - } else { - } - }), - catchError(error => of(this.logger.error(error))) - ) - .subscribe(); + this.store.dispatch( + MessageStore.searchMessage({ + messageType, + searchType, + searchStr + }) + ); } onClickSearchCancel() { this.isSearch = false; - this.getRetrieveMessage(MessageType.Receive, this.recieveCurrentPage); + this.getRetrieveMessage(MessageType.Receive, 0); } /** 쪽지 타입별 조회 */ - getRetrieveMessage(type: MessageType, trgtPageIndex: number) { - switch (type) { - case MessageType.Receive: - { - this.messageSendListSubscription = this.messageApiService - .retrieveReceiveMessage({ - userSeq: this.loginRes.userSeq, - deviceType: DeviceType.PC, - tokenKey: this.loginRes.tokenString, - type: MessageType.Receive, - pageSize: this.defaultPageSize, - pageCount: this.recieveCurrentPage - } as RetrieveRequest) - .pipe( - take(1), - map(res => { - if (res.responseCode === MessageStatusCode.Success) { - this.currentTotalCount = res.totalCount; - this.currentPage = res.pageCount; - this.recieveCurrentPage = res.pageCount; - this.messageList = res.messageList; - } else { - } - }), - catchError(error => of(this.logger.error(error))) - ) - .subscribe(); - } - break; - case MessageType.Send: - { - this.messageSendListSubscription = this.messageApiService - .retrieveSendMessage({ - userSeq: this.loginRes.userSeq, - deviceType: DeviceType.PC, - tokenKey: this.loginRes.tokenString, - type: MessageType.Send, - pageSize: this.defaultPageSize, - pageCount: this.sendCurrentPage - } as RetrieveRequest) - .pipe( - take(1), - map(res => { - if (res.responseCode === MessageStatusCode.Success) { - this.currentTotalCount = res.totalCount; - this.currentPage = res.pageCount; - this.sendCurrentPage = res.pageCount; - this.messageList = res.messageList; - } else { - } - }), - catchError(error => of(this.logger.error(error))) - ) - .subscribe(); - } - break; - case MessageType.Reservation: - { - this.messageSendListSubscription = this.messageApiService - .retrieveReservationMessage({ - userSeq: this.loginRes.userSeq, - deviceType: DeviceType.PC, - tokenKey: this.loginRes.tokenString, - type: MessageType.Reservation, - pageSize: this.defaultPageSize, - pageCount: this.reservationCurrentPage - } as RetrieveRequest) - .pipe( - take(1), - map(res => { - if (res.responseCode === MessageStatusCode.Success) { - this.currentTotalCount = res.totalCount; - this.currentPage = res.pageCount; - this.reservationCurrentPage = res.pageCount; - this.messageList = res.messageList; - } else { - } - }), - catchError(error => of(this.logger.error(error))) - ) - .subscribe(); - } - break; - } + getRetrieveMessage(messageType: MessageType, trgtPageIndex: number) { + this.store.dispatch( + MessageStore.retrieveMessage({ + messageType + }) + ); } /** 쪽지 상세보기 */ diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/index.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/index.ts index 44ba4d69..422d862d 100644 --- a/projects/ucap-webmessenger-app/src/app/store/messenger/index.ts +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/index.ts @@ -3,6 +3,7 @@ import { Action, combineReducers, Selector, createSelector } from '@ngrx/store'; import * as ChatStore from './chat'; import * as EventStore from './event'; +import * as MessageStore from './message'; import * as OptionStore from './option'; import * as QueryStore from './query'; import * as RoomStore from './room'; @@ -13,6 +14,7 @@ import * as SettingsStore from './settings'; export interface State { chat: ChatStore.State; event: EventStore.State; + message: MessageStore.State; option: OptionStore.State; query: QueryStore.State; room: RoomStore.State; @@ -24,6 +26,7 @@ export interface State { export const effects: Type[] = [ ChatStore.Effects, EventStore.Effects, + MessageStore.Effects, OptionStore.Effects, QueryStore.Effects, RoomStore.Effects, @@ -36,6 +39,7 @@ export function reducers(state: State | undefined, action: Action) { return combineReducers({ chat: ChatStore.reducer, event: EventStore.reducer, + message: MessageStore.reducer, option: OptionStore.reducer, query: QueryStore.reducer, room: RoomStore.reducer, @@ -53,6 +57,9 @@ export function selectors(selector: Selector) { EventSelector: EventStore.selectors( createSelector(selector, (state: State) => state.event) ), + MessageSelector: MessageStore.selectors( + createSelector(selector, (state: State) => state.message) + ), OptionSelector: OptionStore.selectors( createSelector(selector, (state: State) => state.option) ), diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/message/actions.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/message/actions.ts new file mode 100644 index 00000000..b36671bc --- /dev/null +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/message/actions.ts @@ -0,0 +1,42 @@ +import { createAction, props } from '@ngrx/store'; +import { + MessageType, + RetrieveResponse, + MessageSearchType +} from '@ucap-webmessenger/api-message'; + +export const retrieveMessage = createAction( + '[Messenger::Message] RetrieveMessage', + props<{ + messageType: MessageType; + pageSize?: number; + pageCount?: number; + }>() +); +export const retrieveMessageSuccess = createAction( + '[Messenger::Message] RetrieveMessage Success', + props<{ res: RetrieveResponse; messageType: MessageType }>() +); +export const retrieveMessageFailure = createAction( + '[Messenger::Message] RetrieveMessage Failure', + props<{ error: any }>() +); + +export const searchMessage = createAction( + '[Messenger::Message] searchMessage', + props<{ + messageType: MessageType; + pageSize?: number; + pageCount?: number; + searchType?: MessageSearchType; + searchStr?: string; + }>() +); +export const searchMessageSuccess = createAction( + '[Messenger::Message] searchMessage Success', + props<{ res: RetrieveResponse; messageType: MessageType }>() +); +export const searchMessageFailure = createAction( + '[Messenger::Message] searchMessage Failure', + props<{ error: any }>() +); diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/message/effects.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/message/effects.ts new file mode 100644 index 00000000..d273c4c5 --- /dev/null +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/message/effects.ts @@ -0,0 +1,210 @@ +import { Injectable } from '@angular/core'; + +import { Actions, createEffect, ofType } from '@ngrx/effects'; + +import { Store, select } from '@ngrx/store'; + +import { NGXLogger } from 'ngx-logger'; + +import { of } from 'rxjs'; +import { + tap, + switchMap, + map, + catchError, + exhaustMap, + withLatestFrom, + concatMap, + take +} from 'rxjs/operators'; +import moment from 'moment'; + +import * as ChatStore from '@app/store/messenger/chat'; +import * as RoomStore from '@app/store/messenger/room'; +import * as SyncStore from '@app/store/messenger/sync'; + +import { SessionStorageService } from '@ucap-webmessenger/web-storage'; +import { KEY_ENVIRONMENTS_INFO } from './../../../types/environment.type'; +import { LoginInfo, KEY_LOGIN_INFO, EnvironmentsInfo } from '@app/types'; +import { Dictionary } from '@ngrx/entity'; +import { openSuccess, openFailure } from '../room'; +import { LoginResponse } from '@ucap-webmessenger/protocol-authentication'; +import { KEY_LOGIN_RES_INFO } from '@app/types/login-res-info.type'; +import { StatusCode, MessageStatusCode } from '@ucap-webmessenger/api'; +import { environment } from '../../../../environments/environment'; +import { + AlertDialogComponent, + AlertDialogResult, + AlertDialogData, + DialogService +} from '@ucap-webmessenger/ui'; +import { + retrieveMessage, + retrieveMessageFailure, + retrieveMessageSuccess, + searchMessage, + searchMessageSuccess, + searchMessageFailure +} from './actions'; +import { + MessageApiService, + RetrieveRequest, + MessageType, + RetrieveSearchRequest, + MessageSearchType +} from '@ucap-webmessenger/api-message'; + +@Injectable() +export class Effects { + retrieveMessage$ = createEffect( + () => { + // const loginResInfo: LoginResponse = this.sessionStorageService.get< + // LoginResponse + // >(KEY_LOGIN_RES_INFO); + const environmentsInfo = this.sessionStorageService.get( + KEY_ENVIRONMENTS_INFO + ); + + return this.actions$.pipe( + ofType(retrieveMessage), + withLatestFrom( + this.store.pipe( + select( + (state: any) => + state.account.authentication.loginRes as LoginResponse + ) + ) + ), + switchMap(([req, loginResInfo]) => { + const request: RetrieveRequest = { + userSeq: loginResInfo.userSeq, + deviceType: environmentsInfo.deviceType, + tokenKey: loginResInfo.tokenString, + type: req.messageType, + pageSize: !!req.pageSize ? req.pageSize : 1000, + pageCount: !!req.pageCount ? req.pageCount : 0 + }; + + switch (req.messageType) { + case MessageType.Receive: { + return this.messageApiService + .retrieveReceiveMessage(request) + .pipe( + map(res => { + if (res.responseCode === MessageStatusCode.Success) { + this.store.dispatch( + retrieveMessageSuccess({ + res, + messageType: req.messageType + }) + ); + } + }), + catchError(error => of(retrieveMessageFailure({ error }))) + ); + } + case MessageType.Send: { + return this.messageApiService.retrieveSendMessage(request).pipe( + map(res => { + if (res.responseCode === MessageStatusCode.Success) { + this.store.dispatch( + retrieveMessageSuccess({ + res, + messageType: req.messageType + }) + ); + } + }), + catchError(error => of(retrieveMessageFailure({ error }))) + ); + } + case MessageType.Reservation: { + return this.messageApiService + .retrieveReservationMessage(request) + .pipe( + map(res => { + if (res.responseCode === MessageStatusCode.Success) { + this.store.dispatch( + retrieveMessageSuccess({ + res, + messageType: req.messageType + }) + ); + } + }), + catchError(error => of(retrieveMessageFailure({ error }))) + ); + } + } + }) + ); + }, + { dispatch: false } + ); + + searchMessage$ = createEffect( + () => { + const environmentsInfo = this.sessionStorageService.get( + KEY_ENVIRONMENTS_INFO + ); + + return this.actions$.pipe( + ofType(searchMessage), + withLatestFrom( + this.store.pipe( + select( + (state: any) => + state.account.authentication.loginRes as LoginResponse + ) + ) + ), + switchMap(([req, loginResInfo]) => { + const request: RetrieveRequest = { + userSeq: loginResInfo.userSeq, + deviceType: environmentsInfo.deviceType, + tokenKey: loginResInfo.tokenString, + type: req.messageType, + pageSize: !!req.pageSize ? req.pageSize : 1000, + pageCount: !!req.pageCount ? req.pageCount : 0 + }; + + return this.messageApiService + .retrieveSearchMessage({ + ...request, + searchTitle: + req.searchType === MessageSearchType.Title ? req.searchStr : '', + searchName: + req.searchType === MessageSearchType.Name ? req.searchStr : '', + searchContent: + req.searchType === MessageSearchType.Contents + ? req.searchStr + : '' + } as RetrieveSearchRequest) + .pipe( + map(res => { + if (res.responseCode === MessageStatusCode.Success) { + this.store.dispatch( + searchMessageSuccess({ + res, + messageType: req.messageType + }) + ); + } + }), + catchError(error => of(searchMessageFailure({ error }))) + ); + }) + ); + }, + { dispatch: false } + ); + + constructor( + private actions$: Actions, + private store: Store, + private messageApiService: MessageApiService, + private sessionStorageService: SessionStorageService, + private dialogService: DialogService, + private logger: NGXLogger + ) {} +} diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/message/index.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/message/index.ts new file mode 100644 index 00000000..2663cade --- /dev/null +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/message/index.ts @@ -0,0 +1,4 @@ +export * from './actions'; +export * from './effects'; +export * from './reducers'; +export * from './state'; diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/message/reducers.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/message/reducers.ts new file mode 100644 index 00000000..cf60e690 --- /dev/null +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/message/reducers.ts @@ -0,0 +1,100 @@ +import { createReducer, on } from '@ngrx/store'; +import { + initialState, + adapterReceiveList, + adapterSendList, + adapterReservationList, + adapterSearchList +} from './state'; +import * as AuthenticationStore from '@app/store/account/authentication'; +import { + retrieveMessageSuccess, + retrieveMessage, + searchMessage, + searchMessageSuccess +} from './actions'; +import { MessageType } from '@ucap-webmessenger/api-message'; + +export const reducer = createReducer( + initialState, + + on(retrieveMessage, (state, action) => { + switch (action.messageType) { + case MessageType.Receive: { + return { + ...state, + receiveListProcessing: true + }; + } + case MessageType.Send: { + return { + ...state, + sendListProcessing: true + }; + } + case MessageType.Reservation: { + return { + ...state, + reservationListProcessing: true + }; + } + } + }), + on(retrieveMessageSuccess, (state, action) => { + switch (action.messageType) { + case MessageType.Receive: { + return { + ...state, + receiveList: adapterReceiveList.upsertMany(action.res.messageList, { + ...state.receiveList + }), + receiveListProcessing: false + }; + } + case MessageType.Send: { + return { + ...state, + sendList: adapterSendList.upsertMany(action.res.messageList, { + ...state.sendList + }), + sendListProcessing: false + }; + } + case MessageType.Reservation: { + return { + ...state, + reservationList: adapterReservationList.upsertMany( + action.res.messageList, + { + ...state.reservationList + } + ), + reservationListProcessing: false + }; + } + } + }), + + on(searchMessage, (state, action) => { + return { + ...state, + searchList: adapterSearchList.removeAll(state.searchList), + searchListProcessing: true + }; + }), + on(searchMessageSuccess, (state, action) => { + return { + ...state, + searchList: adapterSearchList.upsertMany(action.res.messageList, { + ...state.searchList + }), + searchListProcessing: false + }; + }), + + on(AuthenticationStore.logoutInitialize, (state, action) => { + return { + ...initialState + }; + }) +); diff --git a/projects/ucap-webmessenger-app/src/app/store/messenger/message/state.ts b/projects/ucap-webmessenger-app/src/app/store/messenger/message/state.ts new file mode 100644 index 00000000..ef289c77 --- /dev/null +++ b/projects/ucap-webmessenger-app/src/app/store/messenger/message/state.ts @@ -0,0 +1,218 @@ +import { Selector, createSelector } from '@ngrx/store'; +import { EntityState, createEntityAdapter } from '@ngrx/entity'; + +import { MessageList } from '@ucap-webmessenger/api-message'; + +import { + InfoResponse, + Info, + EventJson +} from '@ucap-webmessenger/protocol-event'; +import { FileInfo, FileDownloadInfo } from '@ucap-webmessenger/protocol-file'; + +export interface ReceiveListState extends EntityState {} +export interface SendListState extends EntityState {} +export interface ReservationListState extends EntityState {} +export interface SearchListState extends EntityState {} + +export interface InfoListState extends EntityState> {} +export interface FileInfoListState extends EntityState {} +export interface FileInfoCheckListState extends EntityState {} + +export interface State { + receiveListProcessing: boolean; + receiveList: ReceiveListState; + receiveTotalCount: number; + receivePage: number; + + sendListProcessing: boolean; + sendList: SendListState; + sendTotalCount: number; + sendPage: number; + + reservationListProcessing: boolean; + reservationList: ReservationListState; + reservationTotalCount: number; + reservationPage: number; + + searchListProcessing: boolean; + searchList: SearchListState; + searchTotalCount: number; + searchPage: number; +} + +export const adapterReceiveList = createEntityAdapter({ + selectId: info => info.msgId, + sortComparer: (a, b) => { + return b.msgId - a.msgId; + } +}); +export const adapterSendList = createEntityAdapter({ + selectId: info => info.msgId, + sortComparer: (a, b) => { + return b.msgId - a.msgId; + } +}); +export const adapterReservationList = createEntityAdapter({ + selectId: info => info.msgId, + sortComparer: (a, b) => { + return b.msgId - a.msgId; + } +}); +export const adapterSearchList = createEntityAdapter({ + selectId: info => info.msgId, + sortComparer: (a, b) => { + return b.msgId - a.msgId; + } +}); + +const receiveListInitialState: ReceiveListState = adapterReceiveList.getInitialState( + {} +); +const sendListInitialState: SendListState = adapterSendList.getInitialState({}); +const reservationListInitialState: ReservationListState = adapterReservationList.getInitialState( + {} +); +const searchListInitialState: SearchListState = adapterSearchList.getInitialState( + {} +); + +export const initialState: State = { + receiveListProcessing: false, + receiveList: receiveListInitialState, + receiveTotalCount: 0, + receivePage: 0, + + sendListProcessing: false, + sendList: sendListInitialState, + sendTotalCount: 0, + sendPage: 0, + + reservationListProcessing: false, + reservationList: reservationListInitialState, + reservationTotalCount: 0, + reservationPage: 0, + + searchListProcessing: false, + searchList: searchListInitialState, + searchTotalCount: 0, + searchPage: 0 +}; + +const { + selectAll: ngeSelectAllReceiveList, + selectEntities: ngeSelectEntitiesReceiveList, + selectIds: ngeSelectIdsReceiveList, + selectTotal: ngeSelectTotalReceiveList +} = adapterReceiveList.getSelectors(); +const { + selectAll: ngeSelectAllSendList, + selectEntities: ngeSelectEntitiesSendList, + selectIds: ngeSelectIdsSendList, + selectTotal: ngeSelectTotalSendList +} = adapterSendList.getSelectors(); +const { + selectAll: ngeSelectAllReservationList, + selectEntities: ngeSelectEntitiesReservationList, + selectIds: ngeSelectIdsReservationList, + selectTotal: ngeSelectTotalReservationList +} = adapterReservationList.getSelectors(); +const { + selectAll: ngeSelectAllSearchList, + selectEntities: ngeSelectEntitiesSearchList, + selectIds: ngeSelectIdsSearchList, + selectTotal: ngeSelectTotalSearchList +} = adapterSearchList.getSelectors(); + +export function selectors(selector: Selector) { + const selectReceiveList = createSelector( + selector, + (state: State) => state.receiveList + ); + const selectSendList = createSelector( + selector, + (state: State) => state.sendList + ); + const selectReservationList = createSelector( + selector, + (state: State) => state.reservationList + ); + const selectSearchList = createSelector( + selector, + (state: State) => state.searchList + ); + + return { + receiveListProcessing: createSelector( + selector, + (state: State) => state.receiveListProcessing + ), + sendListProcessing: createSelector( + selector, + (state: State) => state.sendListProcessing + ), + reservationListProcessing: createSelector( + selector, + (state: State) => state.reservationListProcessing + ), + searchListProcessing: createSelector( + selector, + (state: State) => state.searchListProcessing + ), + + selectAllReceiveList: createSelector( + selectReceiveList, + ngeSelectAllReceiveList + ), + selectEntitiesReceiveList: createSelector( + selectReceiveList, + ngeSelectEntitiesReceiveList + ), + selectReceiveList: (seq: number) => + createSelector( + selectReceiveList, + ngeSelectEntitiesReceiveList, + (_, entities) => (!!entities ? entities[seq] : undefined) + ), + + selectAllSendList: createSelector(selectSendList, ngeSelectAllSendList), + selectEntitiesSendList: createSelector( + selectSendList, + ngeSelectEntitiesSendList + ), + selectSendList: (seq: number) => + createSelector(selectSendList, ngeSelectEntitiesSendList, (_, entities) => + !!entities ? entities[seq] : undefined + ), + + selectAllReservationList: createSelector( + selectReservationList, + ngeSelectAllReservationList + ), + selectEntitiesReservationList: createSelector( + selectReservationList, + ngeSelectEntitiesReservationList + ), + selectReservationList: (seq: number) => + createSelector( + selectReservationList, + ngeSelectEntitiesReservationList, + (_, entities) => (!!entities ? entities[seq] : undefined) + ), + + selectAllSearchList: createSelector( + selectSearchList, + ngeSelectAllSearchList + ), + selectEntitiesSearchList: createSelector( + selectSearchList, + ngeSelectEntitiesSearchList + ), + selectSearchList: (seq: number) => + createSelector( + selectSearchList, + ngeSelectEntitiesSearchList, + (_, entities) => (!!entities ? entities[seq] : undefined) + ) + }; +}