From a17e3e54d105fa4a9101d5f2266e25c9f9d0739a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Klingler?= Date: Thu, 29 Feb 2024 12:37:11 +0100 Subject: [PATCH] feat: add some results display config --- src/components/Index.vue | 1 - src/components/Results.vue | 24 ++++++++++- src/components/ResultsCard.vue | 5 ++- src/components/ResultsConfig.vue | 20 +++++++++ .../card-templates/LayoutDoubleFaced.vue | 32 +++++++++++---- src/components/results-config.ts | 41 +++++++++++++++++++ src/style.css | 3 ++ 7 files changed, 114 insertions(+), 12 deletions(-) create mode 100644 src/components/ResultsConfig.vue create mode 100644 src/components/results-config.ts diff --git a/src/components/Index.vue b/src/components/Index.vue index c20c349..aa64c26 100644 --- a/src/components/Index.vue +++ b/src/components/Index.vue @@ -36,7 +36,6 @@ function onSubmit() { diff --git a/src/components/card-templates/LayoutDoubleFaced.vue b/src/components/card-templates/LayoutDoubleFaced.vue index 4ad0c14..a93a6a9 100644 --- a/src/components/card-templates/LayoutDoubleFaced.vue +++ b/src/components/card-templates/LayoutDoubleFaced.vue @@ -3,6 +3,7 @@ import { defineProps } from 'vue' import { ScryfallCard } from '../../scryfall' import { cardInnerTemplate } from './index' import CardError from './CardError.vue' +import { resultsConfig } from '../results-config'; const props = defineProps<{ card: ScryfallCard @@ -16,15 +17,30 @@ const error = props.card.card_faces?.length != 2; diff --git a/src/components/results-config.ts b/src/components/results-config.ts new file mode 100644 index 0000000..7d5337e --- /dev/null +++ b/src/components/results-config.ts @@ -0,0 +1,41 @@ +import { reactive, watch } from 'vue' + +type ResultsConfig = { + editableContent: boolean, + displayReminderText: boolean, + doubleFacedOnTwoCards: boolean +} + +const defaultResultsConfig: ResultsConfig = { + editableContent: false, + displayReminderText: true, + doubleFacedOnTwoCards: true +} + +export const resultsConfig = reactive(defaultResultsConfig) + +// Load from local storage on start +loadConfigFromLocalStorage() + +// Store in local storage when config changes +watch(resultsConfig, config => { + localStorage.setItem('resultsConfig', JSON.stringify(config)) +}) + +function loadConfigFromLocalStorage() { + const storedRawConfig = localStorage.getItem('resultsConfig') + + if (storedRawConfig) { + const storedConfig = JSON.parse(storedRawConfig) + + if (storedConfig.editableContent !== undefined) { + resultsConfig.editableContent = storedConfig.editableContent + } + if (storedConfig.displayReminderText !== undefined) { + resultsConfig.displayReminderText = storedConfig.displayReminderText + } + if (storedConfig.doubleFacedOnTwoCards !== undefined) { + resultsConfig.doubleFacedOnTwoCards = storedConfig.doubleFacedOnTwoCards + } + } +} diff --git a/src/style.css b/src/style.css index e69de29..5db250e 100644 --- a/src/style.css +++ b/src/style.css @@ -0,0 +1,3 @@ +* { + font-family: 'Open Sans', sans-serif; +}