From 0414eb357017b75d2f20ba161696b25ebea72a79 Mon Sep 17 00:00:00 2001
From: Julia Friesel <julia.friesel@gmail.com>
Date: Fri, 31 Aug 2018 16:43:35 +0200
Subject: [PATCH] When navigating to cycle day, remember origin

---
 components/app.js | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/components/app.js b/components/app.js
index 827b11e3..ba584370 100644
--- a/components/app.js
+++ b/components/app.js
@@ -29,6 +29,10 @@ export default class App extends Component {
   }
 
   navigate = (pageName, props) => {
+    const curr = this.state.currentPage
+    if (navigatingToCycleDayFromMainMenuEntry(pageName, curr)) {
+      this.cycleDayOrigin = curr
+    }
     this.setState({currentPage: pageName, currentProps: props})
   }
 
@@ -36,6 +40,9 @@ export default class App extends Component {
     if (this.state.currentPage === 'Home') return false
     if (isSymptomView(this.state.currentPage)) {
       this.navigate('CycleDay', { cycleDay: this.state.currentProps.cycleDay })
+    } else if(this.state.currentPage === 'CycleDay') {
+      this.navigate(this.cycleDayOrigin || 'Home')
+      this.cycleDayOrigin = null
     } else {
       this.navigate('Home')
     }
@@ -63,3 +70,7 @@ export default class App extends Component {
     )
   }
 }
+
+function navigatingToCycleDayFromMainMenuEntry(target, curr) {
+  return target === 'CycleDay' && ['Home', 'Calendar', 'Chart'].indexOf(curr) > -1
+}
\ No newline at end of file
-- 
GitLab