2020-03-21 17:11:07 +01:00
|
|
|
import Vue from 'vue'
|
|
|
|
import Vuex from 'vuex'
|
2020-03-21 19:39:07 +01:00
|
|
|
import axios from 'axios';
|
2020-03-21 17:11:07 +01:00
|
|
|
|
2020-03-21 19:39:07 +01:00
|
|
|
Vue.use(Vuex)
|
2020-03-21 18:57:15 +01:00
|
|
|
|
|
|
|
export default new Vuex.Store({
|
|
|
|
state: {
|
2020-03-22 19:23:06 +01:00
|
|
|
surveyCompletedOnce: false,
|
2020-03-21 18:57:15 +01:00
|
|
|
answers: [],
|
2020-03-22 21:07:21 +01:00
|
|
|
skipped: [],
|
2020-03-21 19:39:07 +01:00
|
|
|
questions: []
|
2020-03-21 18:57:15 +01:00
|
|
|
},
|
|
|
|
mutations: {
|
2020-03-22 00:33:29 +01:00
|
|
|
startWithFirstQuestion() {
|
|
|
|
this.state.currentQuestion = 0
|
|
|
|
},
|
2020-03-22 14:21:58 +01:00
|
|
|
answerQuestion(state, pl) {
|
2020-03-22 22:08:45 +01:00
|
|
|
this.state.skipped[pl.id] = false
|
2020-03-22 14:21:58 +01:00
|
|
|
this.state.answers[pl.id] = pl.answer
|
2020-03-21 20:20:55 +01:00
|
|
|
},
|
2020-03-22 21:07:21 +01:00
|
|
|
setSkipped(state, n) {
|
|
|
|
this.state.skipped[n] = true
|
|
|
|
},
|
2020-03-22 19:23:06 +01:00
|
|
|
setSurveyCompleted() {
|
|
|
|
this.state.surveyCompletedOnce = true
|
|
|
|
},
|
2020-03-21 19:39:07 +01:00
|
|
|
init() {
|
|
|
|
axios.get('https://avian-safeguard-214619.firebaseio.com/questions.json')
|
|
|
|
.then(res => {
|
|
|
|
console.log(res)
|
|
|
|
this.state.questions = res.data
|
2020-03-22 21:07:21 +01:00
|
|
|
|
|
|
|
this.state.answers = Array(res.data.length).fill(0);
|
|
|
|
this.state.skipped = Array(res.data.length).fill(false);
|
2020-03-21 19:39:07 +01:00
|
|
|
})
|
2020-03-21 18:57:15 +01:00
|
|
|
}
|
|
|
|
},
|
2020-03-21 21:54:20 +01:00
|
|
|
getters: {
|
|
|
|
numberQuestions: (state) => {
|
|
|
|
return state.questions.length
|
|
|
|
}
|
|
|
|
},
|
2020-03-21 19:39:07 +01:00
|
|
|
actions: {
|
|
|
|
},
|
2020-03-21 18:57:15 +01:00
|
|
|
modules: {}
|
2020-03-21 17:11:07 +01:00
|
|
|
})
|