Просмотр исходного кода

:construction: Started work on refreshing state of survey

tags/0.0.3^2
tomit4 3 лет назад
Родитель
Сommit
d0e542f0fe
1 измененных файлов: 21 добавлений и 5 удалений
  1. 21
    5
      frontend/src/views/OnboardingView.vue

+ 21
- 5
frontend/src/views/OnboardingView.vue Просмотреть файл

62
         // uses createSurvey/getQuestions from from utils/survey.service.js 
62
         // uses createSurvey/getQuestions from from utils/survey.service.js 
63
         // which calls in fetchQuestions from services/survey.service.js
63
         // which calls in fetchQuestions from services/survey.service.js
64
         this.survey = await surveyFactory.createSurvey()
64
         this.survey = await surveyFactory.createSurvey()
65
-        // TODO: create boolean value based off if a passed user_email is found in user db (i.e. login)
65
+        // checks if the user has simply refreshed the page after creating a basic profile
66
+        // and redirects the user to their last unanswered survey question
67
+        if (localStorage['currentStep'] &&
68
+            localStorage['currentProfileId'] &&
69
+            localStorage['responses']) {
70
+            this.currentStep = Number(localStorage['currentStep'])
71
+            this.currentProfileId = Number(localStorage['currentProfileId'])
72
+            this.responses = JSON.parse(localStorage['responses'])
73
+            this.goToStep(this.currentStep)
74
+        }
66
     },
75
     },
67
     methods: {
76
     methods: {
68
         onSubmit() {
77
         onSubmit() {
93
                 response.val = payload.input
102
                 response.val = payload.input
94
                 this.responses.push(response)
103
                 this.responses.push(response)
95
 
104
 
96
-                // save endpoint here
97
-                // start with utils/surve.js
105
+                // sends latest survey response to db
98
                 if (this.currentProfileId) {
106
                 if (this.currentProfileId) {
99
-                    surveyFactory.addNewSurveyAnswer(this.responses[this.responses.length - 1], this.currentProfileId)
107
+                    surveyFactory.addNewSurveyAnswer(
108
+                        this.responses[this.responses.length - 1], 
109
+                        this.currentProfileId)
100
                 }
110
                 }
101
 
111
 
102
                 // creates a user in db as long as name, email, and seeking are defined
112
                 // creates a user in db as long as name, email, and seeking are defined
103
-                if (!this.currentProfileId && this.survey.hasMinResponsesToCreateProfile(this.answered)) {
113
+                if (!this.currentProfileId && 
114
+                    this.survey.hasMinResponsesToCreateProfile(this.answered)) {
104
                     const newUser = await signupUser(this.answered)
115
                     const newUser = await signupUser(this.answered)
105
                     const newUserId = newUser.user_id
116
                     const newUserId = newUser.user_id
106
                     const newProfile = await createProfileForUserId(newUserId, this.responses)
117
                     const newProfile = await createProfileForUserId(newUserId, this.responses)
107
                     this.currentProfileId = newProfile.profile_id
118
                     this.currentProfileId = newProfile.profile_id
119
+                    // save user's progress through survey
120
+                    localStorage.setItem('currentProfileId', Number(newProfile.profile_id))
121
+                    localStorage.setItem('responses', JSON.stringify(this.responses))
108
                 }
122
                 }
109
 
123
 
110
                 if (k === 'aspects') return
124
                 if (k === 'aspects') return
113
                 this.onSubmit(this.answered)
127
                 this.onSubmit(this.answered)
114
             } else {
128
             } else {
115
                 this.goToStep(this.currentStep + 1)
129
                 this.goToStep(this.currentStep + 1)
130
+                // save user's progress through survey
131
+                localStorage.setItem('currentStep', Number(this.currentStep))
116
             }
132
             }
117
         },
133
         },
118
     },
134
     },

Загрузка…
Отмена
Сохранить