diff --git a/client/src/main.js b/client/src/main.js index 480a5e3..5319e43 100644 --- a/client/src/main.js +++ b/client/src/main.js @@ -2,7 +2,9 @@ import { createApp } from 'vue' import '@/style.css' import App from '@/App.vue' import Router from '@/router' +import { createPinia } from 'pinia' import '@/assets/js/quiz.js' const app = createApp(App) +app.use(createPinia()) app.use(Router) app.mount('#app') diff --git a/client/src/stores/answers.js b/client/src/stores/answers.js new file mode 100644 index 0000000..5350a0c --- /dev/null +++ b/client/src/stores/answers.js @@ -0,0 +1,22 @@ +import { defineStore } from 'pinia' + +export const useAnswersStore = defineStore({ + id: 'answers', + state: () => ({ + answers: [], + }), + actions: { + isAnswered(index) { + if (!Array.isArray(this.answers[index]) ) { + return this.answers[index] != null + } else { + return this.answers[index].length > 0 + } + }, + makeArray(index, selectNumber) { + if (selectNumber > 1 && !Array.isArray(this.answers[index])) { + this.answers[index] = [ ] + } + } + } +}) \ No newline at end of file diff --git a/client/src/stores/app.js b/client/src/stores/app.js new file mode 100644 index 0000000..ba31109 --- /dev/null +++ b/client/src/stores/app.js @@ -0,0 +1,18 @@ +import { defineStore } from 'pinia' + +export const useAppStore = defineStore({ + id: 'app', + state: () => ({ + hasData: false, + results: {} + }), + actions: { + toggleData() { + this.hasData = !this.hasData + console.log('Toggled Has Data. New value', this.hasData) + }, + storeResults(results) { + this.results = JSON.parse(JSON.stringify(results)) + } + } +}) \ No newline at end of file diff --git a/client/src/stores/questions.js b/client/src/stores/questions.js new file mode 100644 index 0000000..50d8d63 --- /dev/null +++ b/client/src/stores/questions.js @@ -0,0 +1,20 @@ +import { defineStore } from 'pinia' + +export const useQuestionStore = defineStore({ + id: 'questions', + state: () => ({ + questions: [], + currentQuestion: 0 + }), + actions: { + storeQuestions(questionArray) { + this.questions = [...questionArray] + }, + nextQuestion() { + this.currentQuestion ++ + }, + previousQuestion() { + this.currentQuestion -- + } + } +}) \ No newline at end of file