Skip to content

Commit

Permalink
feat: reset editedHikeProgramState action/reducer
Browse files Browse the repository at this point in the history
  • Loading branch information
petrot committed May 7, 2018
1 parent d1875bc commit da03fbf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/app/pages/hike-edit/hike-edit.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export class HikeEditComponent implements OnInit, OnDestroy {

this._store.dispatch(new hikeEditMapActions.ResetMapState());
this._store.dispatch(new hikeEditRoutePlannerActions.ResetRoutePlanningState());
this._store.dispatch(new editedHikeProgramActions.ResetHikeProgram());

this._activatedRoute.params
.takeUntil(this._destroy$)
Expand Down
6 changes: 6 additions & 0 deletions src/app/store/actions/edited-hike-program.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Action } from '@ngrx/store';
import { ILocalizedItem, ITextualDescription } from 'subrepos/provider-client';

export const RESET_HIKE_PROGRAM = '[HikeProgram] Reset';
export const ADD_NEW_TRANSLATED_HIKE_DESCRIPTION = '[HikeProgram] Add new translated hike description';
export const DELETE_TRANSLATED_HIKE_DESCRIPTION = '[HikeProgram] Delete translated hike description';
export const ADD_HIKE_PROGRAM_DETAILS = '[HikeProgram] Add some details';
Expand All @@ -12,6 +13,10 @@ export const SAVE_HIKE_PROGRAM = '[HikeProgram] Save hike program';
export const HIKE_PROGRAM_SAVE_SUCCESS = '[HikeProgram] Hike program saved successfully';
export const HIKE_PROGRAM_SAVE_FAILED = '[HikeProgram] Hike program save failure';

export class ResetHikeProgram implements Action {
readonly type = RESET_HIKE_PROGRAM;
}

export class AddNewTranslatedHikeProgramDescription implements Action {
readonly type = ADD_NEW_TRANSLATED_HIKE_DESCRIPTION;

Expand Down Expand Up @@ -70,6 +75,7 @@ export class HikeProgramSaveFailed implements Action {
constructor(public error: any) {}
}
export type AllEditedHikeProgramActions =
| ResetHikeProgram
| AddNewTranslatedHikeProgramDescription
| DeleteTranslatedHikeProgramDescription
| AddHikeProgramDetails
Expand Down
4 changes: 4 additions & 0 deletions src/app/store/reducer/edited-hike-program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export const editedHikeProgramReducer: ActionReducer<IEditedHikeProgramState> =
): IEditedHikeProgramState => {
let newState = _.cloneDeep(state);
switch (action.type) {
case editedHikeProgramActions.RESET_HIKE_PROGRAM: {
return initialEditedHikeProgramState;
}

case editedHikeProgramActions.ADD_NEW_TRANSLATED_HIKE_DESCRIPTION: {
newState.data.description[action.languageKey] = action.content;
newState.dirty = true;
Expand Down

0 comments on commit da03fbf

Please sign in to comment.