ing
This commit is contained in:
4
@overflow/notification/store/detail/index.ts
Normal file
4
@overflow/notification/store/detail/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export * from './notification.action';
|
||||
export * from './notification.effect';
|
||||
export * from './notification.reducer';
|
||||
export * from './notification.state';
|
||||
61
@overflow/notification/store/detail/notification.action.ts
Normal file
61
@overflow/notification/store/detail/notification.action.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import { Action } from '@ngrx/store';
|
||||
|
||||
import { RPCClientError } from '@loafer/ng-rpc';
|
||||
|
||||
import { Member } from '@overflow/commons-typescript/model/member';
|
||||
// import { PageParams, Page } from 'app/commons/model';
|
||||
import { Notification } from '@overflow/commons-typescript/model/notification';
|
||||
|
||||
export enum ActionType {
|
||||
MarkAsRead = '[Notification.notification] MarkAsRead',
|
||||
MarkAsReadSuccess = '[Notification.notification] MarkAsReadSuccess',
|
||||
MarkAsReadFailure = '[Notification.notification] MarkAsReadFailure',
|
||||
// ReadUnconfirmedCount = '[Notification.notification] ReadUnconfirmedCount',
|
||||
// ReadUnconfirmedCountSuccess = '[Notification.notification] ReadUnconfirmedCountSuccess',
|
||||
// ReadUnconfirmedCountFailure = '[Notification.notification] ReadUnconfirmedCountFailure',
|
||||
}
|
||||
|
||||
export class MarkAsRead implements Action {
|
||||
readonly type = ActionType.MarkAsRead;
|
||||
|
||||
constructor(public payload: Notification ) {}
|
||||
}
|
||||
|
||||
export class MarkAsReadSuccess implements Action {
|
||||
readonly type = ActionType.MarkAsReadSuccess;
|
||||
|
||||
constructor(public payload: Notification) {}
|
||||
}
|
||||
|
||||
export class MarkAsReadFailure implements Action {
|
||||
readonly type = ActionType.MarkAsReadFailure;
|
||||
|
||||
constructor(public payload: RPCClientError) {}
|
||||
}
|
||||
|
||||
// export class ReadUnconfirmedCount implements Action {
|
||||
// readonly type = ActionType.ReadUnconfirmedCount;
|
||||
|
||||
// constructor(public payload: Member) {}
|
||||
// }
|
||||
|
||||
// export class ReadUnconfirmedCountSuccess implements Action {
|
||||
// readonly type = ActionType.ReadUnconfirmedCountSuccess;
|
||||
|
||||
// constructor(public payload: number) {}
|
||||
// }
|
||||
|
||||
// export class ReadUnconfirmedCountFailure implements Action {
|
||||
// readonly type = ActionType.ReadUnconfirmedCountFailure;
|
||||
|
||||
// constructor(public payload: RPCClientError) {}
|
||||
// }
|
||||
|
||||
export type Actions =
|
||||
| MarkAsRead
|
||||
| MarkAsReadSuccess
|
||||
| MarkAsReadFailure
|
||||
// | ReadUnconfirmedCount
|
||||
// | ReadUnconfirmedCountSuccess
|
||||
// | ReadUnconfirmedCountFailure
|
||||
;
|
||||
@@ -0,0 +1,15 @@
|
||||
import { TestBed, inject } from '@angular/core/testing';
|
||||
|
||||
import { Effects } from './notification.effect';
|
||||
|
||||
describe('Notification.Effects', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [Effects]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([Effects], (effects: Effects) => {
|
||||
expect(effects).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
50
@overflow/notification/store/detail/notification.effect.ts
Normal file
50
@overflow/notification/store/detail/notification.effect.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
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/map';
|
||||
import 'rxjs/add/operator/take';
|
||||
|
||||
import { RPCClientError } from '@loafer/ng-rpc';
|
||||
|
||||
import { Notification } from '@overflow/commons-typescript/model/notification';
|
||||
import { NotificationService } from '../../service/notification.service';
|
||||
|
||||
import {
|
||||
MarkAsRead,
|
||||
MarkAsReadSuccess,
|
||||
MarkAsReadFailure,
|
||||
ActionType,
|
||||
} from './notification.action';
|
||||
|
||||
@Injectable()
|
||||
export class Effects {
|
||||
|
||||
constructor(
|
||||
private actions$: Actions,
|
||||
private notificationService: NotificationService,
|
||||
private router: Router
|
||||
) { }
|
||||
|
||||
|
||||
@Effect()
|
||||
markAsRead$: Observable<Action> = this.actions$
|
||||
.ofType(ActionType.MarkAsRead)
|
||||
.map((action: MarkAsRead) => action.payload)
|
||||
.switchMap(payload => this.notificationService.markAsRead(payload))
|
||||
.map(notification => {
|
||||
return new MarkAsReadSuccess(notification);
|
||||
})
|
||||
.catch((error: RPCClientError) => {
|
||||
console.log(error.response.message);
|
||||
return of(new MarkAsReadFailure(error));
|
||||
});
|
||||
}
|
||||
44
@overflow/notification/store/detail/notification.reducer.ts
Normal file
44
@overflow/notification/store/detail/notification.reducer.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
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.MarkAsRead: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
pending: true,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.MarkAsReadSuccess: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
pending: false,
|
||||
notification: action.payload,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.MarkAsReadFailure: {
|
||||
return {
|
||||
...state,
|
||||
error: action.payload,
|
||||
pending: false,
|
||||
notification: null,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
default: {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
||||
14
@overflow/notification/store/detail/notification.state.ts
Normal file
14
@overflow/notification/store/detail/notification.state.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { RPCClientError } from '@loafer/ng-rpc';
|
||||
import { Notification } from '@overflow/commons-typescript/model/notification';
|
||||
|
||||
export interface State {
|
||||
error: RPCClientError | null;
|
||||
pending: boolean;
|
||||
notification: Notification;
|
||||
}
|
||||
|
||||
export const initialState: State = {
|
||||
error: null,
|
||||
pending: false,
|
||||
notification: null,
|
||||
};
|
||||
38
@overflow/notification/store/index.ts
Normal file
38
@overflow/notification/store/index.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
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';
|
||||
|
||||
export interface State {
|
||||
notifications: ListStore.State;
|
||||
notification: DetailStore.State;
|
||||
}
|
||||
|
||||
export const REDUCERS = {
|
||||
notifications: ListStore.reducer,
|
||||
notification: DetailStore.reducer,
|
||||
};
|
||||
|
||||
export const EFFECTS = [
|
||||
ListStore.Effects,
|
||||
DetailStore.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(
|
||||
selectNotificationState,
|
||||
(state: State) => state.notification
|
||||
));
|
||||
4
@overflow/notification/store/list/index.ts
Normal file
4
@overflow/notification/store/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';
|
||||
61
@overflow/notification/store/list/notification.action.ts
Normal file
61
@overflow/notification/store/list/notification.action.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import { Action } from '@ngrx/store';
|
||||
|
||||
import { RPCClientError } from '@loafer/ng-rpc';
|
||||
|
||||
import { Member } from '@overflow/commons-typescript/model/member';
|
||||
// import { PageParams, Page } from 'app/commons/model';
|
||||
|
||||
export enum ActionType {
|
||||
ReadAllByMember = '[Notification.notification] ReadAllByMember',
|
||||
ReadAllByMemberSuccess = '[Notification.notification] ReadAllByMemberSuccess',
|
||||
ReadAllByMemberFailure = '[Notification.notification] ReadAllByMemberFailure',
|
||||
MarkAllAsRead = '[Notification.notification] MarkAllAsRead',
|
||||
MarkAllAsReadSuccess = '[Notification.notification] MarkAllAsReadSuccess',
|
||||
MarkAllAsReadFailure = '[Notification.notification] 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,15 @@
|
||||
import { TestBed, inject } from '@angular/core/testing';
|
||||
|
||||
import { Effects } from './notification.effect';
|
||||
|
||||
describe('Notification.Effects', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [Effects]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([Effects], (effects: Effects) => {
|
||||
expect(effects).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
63
@overflow/notification/store/list/notification.effect.ts
Normal file
63
@overflow/notification/store/list/notification.effect.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
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/map';
|
||||
import 'rxjs/add/operator/take';
|
||||
|
||||
import { RPCClientError } from '@loafer/ng-rpc';
|
||||
|
||||
import { Notification } from '@overflow/commons-typescript/model/notification';
|
||||
import { NotificationService } from '../../service/notification.service';
|
||||
|
||||
import {
|
||||
ReadAllByMember,
|
||||
ReadAllByMemberSuccess,
|
||||
ReadAllByMemberFailure,
|
||||
ActionType,
|
||||
MarkAllAsRead,
|
||||
MarkAllAsReadSuccess,
|
||||
MarkAllAsReadFailure,
|
||||
} from './notification.action';
|
||||
|
||||
@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));
|
||||
// });
|
||||
}
|
||||
69
@overflow/notification/store/list/notification.reducer.ts
Normal file
69
@overflow/notification/store/list/notification.reducer.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
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,
|
||||
pending: true,
|
||||
};
|
||||
}
|
||||
|
||||
// case ActionType.ReadAllByMemberSuccess: {
|
||||
// return {
|
||||
// ...state,
|
||||
// error: null,
|
||||
// pending: false,
|
||||
// page: action.payload,
|
||||
// };
|
||||
// }
|
||||
|
||||
// case ActionType.ReadAllByMemberFailure: {
|
||||
// return {
|
||||
// ...state,
|
||||
// error: action.payload,
|
||||
// pending: false,
|
||||
// page: null,
|
||||
// };
|
||||
// }
|
||||
|
||||
case ActionType.MarkAllAsRead: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
pending: true,
|
||||
};
|
||||
}
|
||||
|
||||
// case ActionType.MarkAllAsReadSuccess: {
|
||||
// return {
|
||||
// ...state,
|
||||
// error: null,
|
||||
// pending: false,
|
||||
// page: action.payload,
|
||||
// };
|
||||
// }
|
||||
|
||||
// case ActionType.MarkAllAsReadFailure: {
|
||||
// return {
|
||||
// ...state,
|
||||
// error: action.payload,
|
||||
// pending: false,
|
||||
// page: null,
|
||||
// };
|
||||
// }
|
||||
|
||||
default: {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
||||
14
@overflow/notification/store/list/notification.state.ts
Normal file
14
@overflow/notification/store/list/notification.state.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { RPCClientError } from '@loafer/ng-rpc';
|
||||
// import { Page } from 'app/commons/model';
|
||||
|
||||
export interface State {
|
||||
error: RPCClientError | null;
|
||||
pending: boolean;
|
||||
// page: Page;
|
||||
}
|
||||
|
||||
export const initialState: State = {
|
||||
error: null,
|
||||
pending: false,
|
||||
// page: null,
|
||||
};
|
||||
Reference in New Issue
Block a user