From 9f2d8fe0f7657a4c24996943cac4097f1b1a16fd Mon Sep 17 00:00:00 2001 From: Nadeige COUTHON Date: Thu, 21 Sep 2023 16:00:18 +0200 Subject: [PATCH] refactor: :recycle: Fix refactoring selectOption component --- frontend/src/stores/steps.js | 21 +-- frontend/src/utils/storage-utils.js | 6 +- .../SecuringSelectOptionContent.vue | 41 ++-- .../SecuringTutorialContent.vue | 178 +++++++++--------- 4 files changed, 109 insertions(+), 137 deletions(-) diff --git a/frontend/src/stores/steps.js b/frontend/src/stores/steps.js index e1a411db..259f209c 100644 --- a/frontend/src/stores/steps.js +++ b/frontend/src/stores/steps.js @@ -8,9 +8,6 @@ export const useStepsStore = defineStore('steps', () => { const currentOptionStep = useLocalStorage('currentOptionStep', {}) const selectedAmmo = useLocalStorage('selectedAmmo', undefined, { serializer }) - const selectedOptionStep1 = useLocalStorage('selectedOptionStep1', undefined, { serializer }) - const selectedOptionStep2 = useLocalStorage('selectedOptionStep2', undefined, { serializer }) - const selectedOptionStep3 = useLocalStorage('selectedOptionStep3', undefined, { serializer }) const tutorialFeedback = useLocalStorage('tutorialFeedback', '') const isDummy = useLocalStorage('isDummy', computed(() => !!(selectedAmmo.value === 'billes')), { serializer }) @@ -26,34 +23,18 @@ export const useStepsStore = defineStore('steps', () => { } function setOptionStep (step, value) { - currentOptionStep.value = { ...currentOptionStep, [step]: value } - } - - function setOptionStep1 (option) { - selectedOptionStep1.value = option - } - function setOptionStep2 (option) { - selectedOptionStep2.value = option - } - function setOptionStep3 (option) { - selectedOptionStep3.value = option + currentOptionStep.value = { ...currentOptionStep.value, [step]: value } } return { currentStep, currentOptionStep, selectedAmmo, - selectedOptionStep1, - selectedOptionStep2, - selectedOptionStep3, tutorialFeedback, setOptionStep, isDummy, isModalTransparentAmmoOpened, setCurrentStep, setAmmo, - setOptionStep1, - setOptionStep2, - setOptionStep3, } }) diff --git a/frontend/src/utils/storage-utils.js b/frontend/src/utils/storage-utils.js index e704e8a1..895e2fcb 100644 --- a/frontend/src/utils/storage-utils.js +++ b/frontend/src/utils/storage-utils.js @@ -1,10 +1,9 @@ import { useResultStore } from '@/stores/result.js' import { useStepsStore } from '@/stores/steps.js' -// import { useLocalStorage } from '@vueuse/core' export const serializer = { read: (v) => (v == null || v === 'null') ? undefined : JSON.parse(v), - write: (v) => v === undefined ? 'null' : JSON.stringify(v), + write: (v) => v == null ? 'null' : JSON.stringify(v), } export const clearLocalStorage = (to, from, next) => { @@ -12,9 +11,6 @@ export const clearLocalStorage = (to, from, next) => { const { setResult } = useResultStore() useStepsStore.isModalTransparentAmmoOpened = undefined - localStorage.selectedOptionStep1 = undefined - localStorage.selectedOptionStep2 = undefined - localStorage.selectedOptionStep3 = undefined setAmmo(undefined) setOptionStep(1, undefined) setOptionStep(2, undefined) diff --git a/frontend/src/views/GuideSecuringFirearm/SecuringSelectOptionContent.vue b/frontend/src/views/GuideSecuringFirearm/SecuringSelectOptionContent.vue index 3fe593f5..ce79605c 100644 --- a/frontend/src/views/GuideSecuringFirearm/SecuringSelectOptionContent.vue +++ b/frontend/src/views/GuideSecuringFirearm/SecuringSelectOptionContent.vue @@ -1,6 +1,5 @@