This commit is contained in:
crusader
2018-05-24 15:44:13 +09:00
parent b69539d368
commit d59d9379f9
514 changed files with 4868 additions and 8262 deletions

View File

@@ -0,0 +1,4 @@
export * from './notification.action';
export * from './notification.effect';
export * from './notification.reducer';
export * from './notification.state';

View 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
;

View File

@@ -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();
}));
});

View 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));
});
}

View 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;
}
}
}

View 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,
};

View 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
));

View File

@@ -0,0 +1,4 @@
export * from './notification.action';
export * from './notification.effect';
export * from './notification.reducer';
export * from './notification.state';

View 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
;

View File

@@ -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();
}));
});

View 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));
// });
}

View 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;
}
}
}

View 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,
};