Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change localstorage to sessionstorage #248

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 29 additions & 49 deletions frontend/src/stores/CategoryStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { defineStore } from 'pinia'
export const useCategoryStore = defineStore('category', () => {
const startCategory = 'AI verordening van toepassing?'
const startSubCategory = 'Soort toepassing'
const initialPreviousCategory = localStorage.getItem('previousCategory') ?? startCategory
const initialPreviousSubCategory = localStorage.getItem('previousSubCategory') ?? startSubCategory
const initialCurrentCategory = localStorage.getItem('currentCategory') ?? startCategory
const initialCurrentSubCategory = localStorage.getItem('currentSubCategory') ?? startSubCategory
const initialCategoryTrace = JSON.parse(localStorage.getItem('categoryTrace') ?? '["AI verordening van toepassing?"]')
const initialSubCategoryTrace = JSON.parse(localStorage.getItem('subCategoryTrace') ?? '["Soort toepassing"]')
const initialPreviousCategory = sessionStorage.getItem('previousCategory') ?? startCategory
const initialPreviousSubCategory = sessionStorage.getItem('previousSubCategory') ?? startSubCategory
const initialCurrentCategory = sessionStorage.getItem('currentCategory') ?? startCategory
const initialCurrentSubCategory = sessionStorage.getItem('currentSubCategory') ?? startSubCategory
const initialCategoryTrace = JSON.parse(sessionStorage.getItem('categoryTrace') ?? '["AI verordening van toepassing?"]')
const initialSubCategoryTrace = JSON.parse(sessionStorage.getItem('subCategoryTrace') ?? '["Soort toepassing"]')
const initialCategoryStateString = `{
"ai_act_applicable_state": "doing",
"risk_group_state": "incomplete"
Expand All @@ -19,27 +19,7 @@ export const useCategoryStore = defineStore('category', () => {
'Welke risicogroep?': 'risk_group_state'
}

const subCategoryCategoryMapper = {
'Rol': 'ai_act_applicable_state',
'Operationeel': 'ai_act_applicable_state',
'Soort toepassing': 'ai_act_applicable_state',
'Risicogroep': 'risk_group_state',
'Conformiteitsbeoordeling': 'risk_group_state',
'Systeemrisico': 'risk_group_state',
'Transparantieverplichting': 'risk_group_state'
}

const subCategoryCategoryMapperString = {
'Rol': 'AI verordening van toepassing?',
'Operationeel': 'AI verordening van toepassing?',
'Soort toepassing': 'AI verordening van toepassing?',
'Risicogroep': 'Welke risicogroep?',
'Conformiteitsbeoordeling': 'Welke risicogroep?',
'Systeemrisico': 'Welke risicogroep?',
'Transparantieverplichting': 'Welke risicogroep?'
}

const initialCategoryState = JSON.parse(localStorage.getItem('categoryState') ?? initialCategoryStateString)
const initialCategoryState = JSON.parse(sessionStorage.getItem('categoryState') ?? initialCategoryStateString)
const previousCategory = ref(String(initialPreviousCategory))
const previousSubCategory = ref(String(initialPreviousSubCategory))
const currentCategory = ref(String(initialCurrentCategory))
Expand All @@ -57,12 +37,12 @@ export const useCategoryStore = defineStore('category', () => {
currentSubCategory.value = subcategory
categoryTrace.value.push(category)
subCategoryTrace.value.push(subcategory)
localStorage.setItem('categoryTrace', JSON.stringify(categoryTrace.value))
localStorage.setItem('subCategoryTrace', JSON.stringify(subCategoryTrace.value))
localStorage.setItem('previousCategory', previousCategory.value)
localStorage.setItem('previousSubCategory', previousSubCategory.value)
localStorage.setItem('currentCategory', currentCategory.value)
localStorage.setItem('currentSubCategory', currentSubCategory.value)
sessionStorage.setItem('categoryTrace', JSON.stringify(categoryTrace.value))
sessionStorage.setItem('subCategoryTrace', JSON.stringify(subCategoryTrace.value))
sessionStorage.setItem('previousCategory', previousCategory.value)
sessionStorage.setItem('previousSubCategory', previousSubCategory.value)
sessionStorage.setItem('currentCategory', currentCategory.value)
sessionStorage.setItem('currentSubCategory', currentSubCategory.value)
updateCategoryState()
}
}
Expand All @@ -76,7 +56,7 @@ export const useCategoryStore = defineStore('category', () => {
if (previousCategoryKey != currentCategoryKey) {
categoryState.value[previousCategoryKey] = "completed"
categoryState.value[currentCategoryKey] = "doing"
localStorage.setItem('categoryState', JSON.stringify(categoryState.value))
sessionStorage.setItem('categoryState', JSON.stringify(categoryState.value))
}
}

Expand All @@ -89,7 +69,7 @@ export const useCategoryStore = defineStore('category', () => {
if (previousCategoryKey != currentCategoryKey) {
categoryState.value[currentCategoryKey] = "incomplete"
categoryState.value[previousCategoryKey] = "doing"
localStorage.setItem('categoryState', JSON.stringify(categoryState.value))
sessionStorage.setItem('categoryState', JSON.stringify(categoryState.value))
}
}

Expand Down Expand Up @@ -125,12 +105,12 @@ export const useCategoryStore = defineStore('category', () => {
previousSubCategory.value = startSubCategory
}

localStorage.setItem('categoryTrace', JSON.stringify(categoryTrace.value))
localStorage.setItem('subCategoryTrace', JSON.stringify(subCategoryTrace.value))
localStorage.setItem('previousCategory', previousCategory.value)
localStorage.setItem('previousSubCategory', previousSubCategory.value)
localStorage.setItem('currentCategory', currentCategory.value)
localStorage.setItem('currentSubCategory', currentSubCategory.value)
sessionStorage.setItem('categoryTrace', JSON.stringify(categoryTrace.value))
sessionStorage.setItem('subCategoryTrace', JSON.stringify(subCategoryTrace.value))
sessionStorage.setItem('previousCategory', previousCategory.value)
sessionStorage.setItem('previousSubCategory', previousSubCategory.value)
sessionStorage.setItem('currentCategory', currentCategory.value)
sessionStorage.setItem('currentSubCategory', currentSubCategory.value)
}

function reset() {
Expand All @@ -141,14 +121,14 @@ export const useCategoryStore = defineStore('category', () => {
categoryState.value = JSON.parse(initialCategoryStateString)
categoryTrace.value = [startCategory]
subCategoryTrace.value = [startSubCategory]
localStorage.removeItem('currentCategory')
localStorage.removeItem('currentSubCategory')
localStorage.removeItem('previousCategory')
localStorage.removeItem('previousSubCategory')
localStorage.removeItem('categoryState')
localStorage.removeItem('subCategoryState')
localStorage.removeItem('categoryTrace')
localStorage.removeItem('subCategoryTrace')
sessionStorage.removeItem('currentCategory')
sessionStorage.removeItem('currentSubCategory')
sessionStorage.removeItem('previousCategory')
sessionStorage.removeItem('previousSubCategory')
sessionStorage.removeItem('categoryState')
sessionStorage.removeItem('subCategoryState')
sessionStorage.removeItem('categoryTrace')
sessionStorage.removeItem('subCategoryTrace')
}

return { categoryState, previousSubCategory, revertCurrentCategory, updateCurrentCategory, reset }
Expand Down
44 changes: 22 additions & 22 deletions frontend/src/stores/QuestionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ export const useQuestionStore = defineStore('question', () => {
}`

const initialAcceptedDisclaimer = sessionStorage.getItem('acceptedDisclaimer') ?? '0'
const initialAnswers = JSON.parse(localStorage.getItem('answers') ?? '[]')
const initialLabels = JSON.parse(localStorage.getItem('labels') ?? '{}')
const initialLabelsBySubCategory = JSON.parse(localStorage.getItem('labelsbysubcategory') ?? initialLabelsBySubCategoryNTB)
const initialQuestionId = localStorage.getItem('currentquestion') ?? '1.2'
const initialConclusionId = localStorage.getItem('currentconclusion') ?? ''
const initialAnswers = JSON.parse(sessionStorage.getItem('answers') ?? '[]')
const initialLabels = JSON.parse(sessionStorage.getItem('labels') ?? '{}')
const initialLabelsBySubCategory = JSON.parse(sessionStorage.getItem('labelsbysubcategory') ?? initialLabelsBySubCategoryNTB)
const initialQuestionId = sessionStorage.getItem('currentquestion') ?? '1.2'
const initialConclusionId = sessionStorage.getItem('currentconclusion') ?? ''

const AcceptedDisclaimer = ref(String(initialAcceptedDisclaimer))
const QuestionId = ref<any>(initialQuestionId)
Expand All @@ -28,12 +28,12 @@ export const useQuestionStore = defineStore('question', () => {

function setQuestionId(id: string | null) {
QuestionId.value = id
localStorage.setItem('currentquestion', QuestionId.value)
sessionStorage.setItem('currentquestion', QuestionId.value)
}

function setConclusionId(id: string) {
ConclusionId.value = id
localStorage.setItem('currentconclusion', ConclusionId.value)
sessionStorage.setItem('currentconclusion', ConclusionId.value)
}

function getLabelsBySubCategory() {
Expand All @@ -43,7 +43,7 @@ export const useQuestionStore = defineStore('question', () => {


function getJsonLabels() {
const label_dict = JSON.parse(localStorage.getItem('labels') ?? '{}')
const label_dict = JSON.parse(sessionStorage.getItem('labels') ?? '{}')
const label_list = Object.values(label_dict).map(String)
return label_list
}
Expand All @@ -53,7 +53,7 @@ export const useQuestionStore = defineStore('question', () => {
labels.value[question_id] = []
}
labels.value[question_id].push(label)
localStorage.setItem('labels', JSON.stringify(labels.value))
sessionStorage.setItem('labels', JSON.stringify(labels.value))
}

function addLabelBySubCategory(label: string, subcategory: string | undefined) {
Expand All @@ -62,7 +62,7 @@ export const useQuestionStore = defineStore('question', () => {
LabelsBySubCategory.value[subcategory] = []
}
LabelsBySubCategory.value[subcategory].push(label)
localStorage.setItem('labelsbysubcategory', JSON.stringify(LabelsBySubCategory.value))
sessionStorage.setItem('labelsbysubcategory', JSON.stringify(LabelsBySubCategory.value))
}
}

Expand All @@ -76,7 +76,7 @@ export const useQuestionStore = defineStore('question', () => {
LabelsBySubCategory.value[key] = ['niet van toepassing']
}
}
localStorage.setItem('labelsbysubcategory', JSON.stringify(LabelsBySubCategory.value))
sessionStorage.setItem('labelsbysubcategory', JSON.stringify(LabelsBySubCategory.value))
}

function revertLabelsAtConclusion() {
Expand All @@ -89,12 +89,12 @@ export const useQuestionStore = defineStore('question', () => {
LabelsBySubCategory.value[key] = ['nader te bepalen']
}
}
localStorage.setItem('labelsbysubcategory', JSON.stringify(LabelsBySubCategory.value))
sessionStorage.setItem('labelsbysubcategory', JSON.stringify(LabelsBySubCategory.value))
}

function addAnswer(id: string) {
answers.value.push(id)
localStorage.setItem('answers', JSON.stringify(answers.value))
sessionStorage.setItem('answers', JSON.stringify(answers.value))
}

function revertAnswer(previousSubCategory: string) {
Expand All @@ -108,10 +108,10 @@ export const useQuestionStore = defineStore('question', () => {
}
delete labels.value[QuestionId.value]
}
localStorage.setItem('answers', JSON.stringify(answers.value))
localStorage.setItem('currentquestion', QuestionId.value)
localStorage.setItem('labels', JSON.stringify(labels.value))
localStorage.setItem('labelsbysubcategory', JSON.stringify(LabelsBySubCategory.value))
sessionStorage.setItem('answers', JSON.stringify(answers.value))
sessionStorage.setItem('currentquestion', QuestionId.value)
sessionStorage.setItem('labels', JSON.stringify(labels.value))
sessionStorage.setItem('labelsbysubcategory', JSON.stringify(LabelsBySubCategory.value))
}

function reset() {
Expand All @@ -120,11 +120,11 @@ export const useQuestionStore = defineStore('question', () => {
labels.value = {}
LabelsBySubCategory.value = JSON.parse(initialLabelsBySubCategoryNTB)
ConclusionId.value = ''
localStorage.setItem('answers', JSON.stringify(answers.value))
localStorage.setItem('currentquestion', QuestionId.value)
localStorage.setItem('currentconclusion', ConclusionId.value)
localStorage.setItem('labels', JSON.stringify(labels.value))
localStorage.setItem('labelsbysubcategory', JSON.stringify(LabelsBySubCategory.value))
sessionStorage.setItem('answers', JSON.stringify(answers.value))
sessionStorage.setItem('currentquestion', QuestionId.value)
sessionStorage.setItem('currentconclusion', ConclusionId.value)
sessionStorage.setItem('labels', JSON.stringify(labels.value))
sessionStorage.setItem('labelsbysubcategory', JSON.stringify(LabelsBySubCategory.value))
}

function acceptDisclaimer() {
Expand Down