Skip to content

Commit

Permalink
Enable multi-page history for back button
Browse files Browse the repository at this point in the history
Previously, the back button just navigated to the home page. Now, it
can navigate back like one would expect.
  • Loading branch information
davejbax committed Aug 4, 2019
1 parent 9abb5a2 commit 58a9c2f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/containers/PagedApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const mapStateToProps = state => {
return {
selectedGoal: goal,
title: state.page.selectedGoalId === null ? 'Subgoals' : goal.name,
hasBack: state.page.selectedGoalId != null
hasBack: state.page.history.length > 0
};
};

Expand Down
8 changes: 5 additions & 3 deletions src/ducks/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@ const GO_BACK = 'subgoals/page/GO_BACK';

// Reducer
const INITIAL_STATE = {
selectedGoalId: null
selectedGoalId: null,
history: []
};

export default function reducer(state = INITIAL_STATE, action) {
switch (action.type) {
case SET_SELECTED_GOAL:
return {
...state,
selectedGoalId: action.goalId
selectedGoalId: action.goalId,
history: [...state.history, state.selectedGoalId]
};

case GO_BACK:
return {
...state,
selectedGoalId: null
selectedGoalId: state.history.pop()
}
default: return state;
}
Expand Down

0 comments on commit 58a9c2f

Please sign in to comment.