notification in progress
This commit is contained in:
@@ -1,38 +1,29 @@
|
||||
import {
|
||||
createSelector,
|
||||
createFeatureSelector,
|
||||
ActionReducerMap,
|
||||
} from '@ngrx/store';
|
||||
|
||||
import { StateSelector } from '@overflow/core/ngrx/store';
|
||||
|
||||
import { MODULE } from '../notification.constant';
|
||||
|
||||
import * as ListStore from './list';
|
||||
import * as DetailStore from './detail';
|
||||
import * as NotificationStore from './notification';
|
||||
|
||||
export interface State {
|
||||
notifications: ListStore.State;
|
||||
notification: DetailStore.State;
|
||||
notification: NotificationStore.State;
|
||||
}
|
||||
|
||||
export const REDUCERS = {
|
||||
notifications: ListStore.reducer,
|
||||
notification: DetailStore.reducer,
|
||||
notification: NotificationStore.reducer,
|
||||
};
|
||||
|
||||
export const EFFECTS = [
|
||||
ListStore.Effects,
|
||||
DetailStore.Effects,
|
||||
NotificationStore.Effects,
|
||||
];
|
||||
|
||||
export const selectNotificationState = createFeatureSelector<State>(MODULE.name);
|
||||
|
||||
export const ReadAllByMemberSelector = new StateSelector<ListStore.State>(createSelector(
|
||||
selectNotificationState,
|
||||
(state: State) => state.notifications
|
||||
));
|
||||
export const ReadSelector = new StateSelector<DetailStore.State>(createSelector(
|
||||
export const NotificationSelector = new StateSelector<NotificationStore.State>(createSelector(
|
||||
selectNotificationState,
|
||||
(state: State) => state.notification
|
||||
));
|
||||
|
||||
4
@overflow/notification/store/notification/list/index.ts
Normal file
4
@overflow/notification/store/notification/list/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export * from './notification.action';
|
||||
export * from './notification.effect';
|
||||
export * from './notification.reducer';
|
||||
export * from './notification.state';
|
||||
@@ -0,0 +1,60 @@
|
||||
import { Action } from '@ngrx/store';
|
||||
import { RPCClientError } from '@loafer/ng-rpc';
|
||||
import { Member } from '@overflow/commons-typescript/model/member';
|
||||
import { PageParams } from '@overflow/commons-typescript/model/commons/PageParams';
|
||||
import { Page } from '@overflow/commons-typescript/model/commons/Page';
|
||||
|
||||
export enum ActionType {
|
||||
ReadAllByMember = '[Notification.list] ReadAllByMember',
|
||||
ReadAllByMemberSuccess = '[Notification.list] ReadAllByMemberSuccess',
|
||||
ReadAllByMemberFailure = '[Notification.list] ReadAllByMemberFailure',
|
||||
MarkAllAsRead = '[Notification.mark] MarkAllAsRead',
|
||||
MarkAllAsReadSuccess = '[Notification.mark] MarkAllAsReadSuccess',
|
||||
MarkAllAsReadFailure = '[Notification.mark] MarkAllAsReadFailure',
|
||||
}
|
||||
|
||||
export class ReadAllByMember implements Action {
|
||||
readonly type = ActionType.ReadAllByMember;
|
||||
|
||||
constructor(public payload: { member: Member, pageParams: PageParams }) {}
|
||||
}
|
||||
|
||||
export class ReadAllByMemberSuccess implements Action {
|
||||
readonly type = ActionType.ReadAllByMemberSuccess;
|
||||
|
||||
constructor(public payload: Page) {}
|
||||
}
|
||||
|
||||
export class ReadAllByMemberFailure implements Action {
|
||||
readonly type = ActionType.ReadAllByMemberFailure;
|
||||
|
||||
constructor(public payload: RPCClientError) {}
|
||||
}
|
||||
|
||||
export class MarkAllAsRead implements Action {
|
||||
readonly type = ActionType.MarkAllAsRead;
|
||||
|
||||
constructor(public payload: { member: Member, pageParams: PageParams }) {}
|
||||
}
|
||||
|
||||
export class MarkAllAsReadSuccess implements Action {
|
||||
readonly type = ActionType.MarkAllAsReadSuccess;
|
||||
|
||||
constructor(public payload: Page) {}
|
||||
}
|
||||
|
||||
export class MarkAllAsReadFailure implements Action {
|
||||
readonly type = ActionType.MarkAllAsReadFailure;
|
||||
|
||||
constructor(public payload: RPCClientError) {}
|
||||
}
|
||||
|
||||
|
||||
export type Actions =
|
||||
| ReadAllByMember
|
||||
| ReadAllByMemberSuccess
|
||||
| ReadAllByMemberFailure
|
||||
| MarkAllAsRead
|
||||
| MarkAllAsReadSuccess
|
||||
| MarkAllAsReadFailure
|
||||
;
|
||||
@@ -0,0 +1,64 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
|
||||
import { Effect, Actions, ofType } from '@ngrx/effects';
|
||||
import { Action } from '@ngrx/store';
|
||||
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { of } from 'rxjs/observable/of';
|
||||
|
||||
import 'rxjs/add/operator/catch';
|
||||
import 'rxjs/add/operator/do';
|
||||
import 'rxjs/add/operator/exhaustMap';
|
||||
import 'rxjs/add/operator/switchMap';
|
||||
import 'rxjs/add/operator/map';
|
||||
import 'rxjs/add/operator/take';
|
||||
|
||||
import { RPCClientError } from '@loafer/ng-rpc';
|
||||
|
||||
import { Domain } from '@overflow/commons-typescript/model/domain';
|
||||
|
||||
import {
|
||||
ReadAllByMember,
|
||||
ReadAllByMemberSuccess,
|
||||
ReadAllByMemberFailure,
|
||||
MarkAllAsRead,
|
||||
MarkAllAsReadSuccess,
|
||||
MarkAllAsReadFailure,
|
||||
ActionType,
|
||||
} from './notification.action';
|
||||
import { NotificationService } from '../../service/notification.service';
|
||||
|
||||
@Injectable()
|
||||
export class Effects {
|
||||
|
||||
constructor(
|
||||
private actions$: Actions,
|
||||
private notificationService: NotificationService,
|
||||
private router: Router
|
||||
) { }
|
||||
|
||||
@Effect()
|
||||
readAllByMember$: Observable<Action> = this.actions$
|
||||
.ofType(ActionType.ReadAllByMember)
|
||||
.map((action: ReadAllByMember) => action.payload)
|
||||
.switchMap(payload => this.notificationService.readAllByMember(payload.member, payload.pageParams))
|
||||
.map(page => {
|
||||
return new ReadAllByMemberSuccess(page);
|
||||
})
|
||||
.catch((error: RPCClientError) => {
|
||||
return of(new ReadAllByMemberFailure(error));
|
||||
});
|
||||
|
||||
@Effect()
|
||||
markAllAsRead$: Observable<Action> = this.actions$
|
||||
.ofType(ActionType.MarkAllAsRead)
|
||||
.map((action: MarkAllAsRead) => action.payload)
|
||||
.switchMap(payload => this.notificationService.markAllAsRead(payload.member, payload.pageParams))
|
||||
.map(page => {
|
||||
return new MarkAllAsReadSuccess(page);
|
||||
})
|
||||
.catch((error: RPCClientError) => {
|
||||
return of(new MarkAllAsReadFailure(error));
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
import {
|
||||
Actions,
|
||||
ActionType,
|
||||
} from './notification.action';
|
||||
|
||||
import {
|
||||
State,
|
||||
initialState,
|
||||
} from './notification.state';
|
||||
|
||||
export function reducer(state = initialState, action: Actions): State {
|
||||
switch (action.type) {
|
||||
case ActionType.ReadAllByMember: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ReadAllByMemberSuccess: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
page: action.payload,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ReadAllByMemberFailure: {
|
||||
return {
|
||||
...state,
|
||||
error: action.payload,
|
||||
page: null,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.MarkAllAsRead: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.MarkAllAsReadSuccess: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
page: action.payload,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.MarkAllAsReadFailure: {
|
||||
return {
|
||||
...state,
|
||||
error: action.payload,
|
||||
page: null,
|
||||
};
|
||||
}
|
||||
|
||||
default: {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { RPCClientError } from '@loafer/ng-rpc';
|
||||
import { Page } from '@overflow/commons-typescript/model/commons/Page';
|
||||
|
||||
export interface State {
|
||||
error: RPCClientError | null;
|
||||
page: Page | null;
|
||||
}
|
||||
|
||||
export const initialState: State = {
|
||||
error: null,
|
||||
page: null,
|
||||
};
|
||||
Reference in New Issue
Block a user