From 3bd11fce38110c9fbfbb8db2d0f81333ea340913 Mon Sep 17 00:00:00 2001
From: thilo <thilo.billerbeck@officerent.de>
Date: Sun, 22 Mar 2020 19:23:06 +0100
Subject: [PATCH] prevent from jumping to an end without completing the survey
 once

---
 src/App.vue                 | 3 +++
 src/components/Question.vue | 1 +
 src/store/index.js          | 4 ++++
 src/views/HelpPage.vue      | 1 +
 src/views/Results.vue       | 6 ++++++
 5 files changed, 15 insertions(+)

diff --git a/src/App.vue b/src/App.vue
index 7986880..90b8ffa 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -11,6 +11,9 @@
   export default {
     mounted() {
       this.$store.commit("init")
+      if (!this.$store.state.surveyCompletedOnce) {
+        this.$router.push("/")
+      }
     },
   }
 </script>
diff --git a/src/components/Question.vue b/src/components/Question.vue
index ec32091..0f1ecbf 100644
--- a/src/components/Question.vue
+++ b/src/components/Question.vue
@@ -98,6 +98,7 @@
                     this.$router.push("/questionnaire/" + nextQuestion)
                 }
                 else {
+                    this.$store.commit("setSurveyCompleted")
                     router.push('/results')
                 }
             }
diff --git a/src/store/index.js b/src/store/index.js
index adff0fb..8dd1086 100644
--- a/src/store/index.js
+++ b/src/store/index.js
@@ -6,6 +6,7 @@ Vue.use(Vuex)
 
 export default new Vuex.Store({
     state: {
+        surveyCompletedOnce: false,
         answers: [],
         questions: []
     },
@@ -16,6 +17,9 @@ export default new Vuex.Store({
         answerQuestion(state, pl) {
             this.state.answers[pl.id] = pl.answer
         },
+        setSurveyCompleted() {
+            this.state.surveyCompletedOnce = true
+        },
         init() {
             axios.get('https://avian-safeguard-214619.firebaseio.com/questions.json')
                 .then(res => {
diff --git a/src/views/HelpPage.vue b/src/views/HelpPage.vue
index dac58c5..3d019fb 100644
--- a/src/views/HelpPage.vue
+++ b/src/views/HelpPage.vue
@@ -43,6 +43,7 @@
                     this.$router.push("/questionnaire/" + nextQuestion)
                 }
                 else {
+                    this.$store.commit("setSurveyCompleted")
                     router.push('/results')
                 }
             },
diff --git a/src/views/Results.vue b/src/views/Results.vue
index 58c590c..46f5b74 100644
--- a/src/views/Results.vue
+++ b/src/views/Results.vue
@@ -4,6 +4,9 @@
             <p class="risk-chance alert" v-if="risk >= 66">hoch</p>
             <p class="risk-chance warning" v-if="risk >= 33 && risk < 66">durchschnittlich</p>
             <p class="risk-chance success" v-if="risk < 33">niedrig</p>
+        <p class="text-center"><router-link style="text-decoration:none" to="/">
+            Zurück zum Anfang
+        </router-link></p>
         <p v-if="bad.length > 0">Auf Folgendes sollten Sie achten:</p>
         <div v-for="card in bad" v-bind:key="card.description" class="card-advice alert">
             <div class="card-advice-title">{{ card.title }}</div>
@@ -114,4 +117,7 @@
     .risk-chance.alert {
         color: #E94A47;
     }
+    .text-center {
+        text-align: center;
+    }
 </style>