local storage for form; some fixes
This commit is contained in:
parent
a799d276cf
commit
d38cc9ab2d
11
frontend/wizard-vue/package-lock.json
generated
11
frontend/wizard-vue/package-lock.json
generated
@ -9,6 +9,7 @@
|
|||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@kalimahapps/vue-icons": "^1.7.1",
|
"@kalimahapps/vue-icons": "^1.7.1",
|
||||||
|
"es-toolkit": "^1.32.0",
|
||||||
"pinia": "^2.3.1",
|
"pinia": "^2.3.1",
|
||||||
"vue": "^3.5.13",
|
"vue": "^3.5.13",
|
||||||
"vue-router": "^4.5.0"
|
"vue-router": "^4.5.0"
|
||||||
@ -2648,6 +2649,16 @@
|
|||||||
"url": "https://github.com/sponsors/antfu"
|
"url": "https://github.com/sponsors/antfu"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/es-toolkit": {
|
||||||
|
"version": "1.32.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/es-toolkit/-/es-toolkit-1.32.0.tgz",
|
||||||
|
"integrity": "sha512-ZfSfHP1l6ubgW/B/FRtqb9bYdMvI6jizbOSfbwwJNcOQ1QE6TFsC3jpQkZ900uUPSR3t3SU5Ds7UWKnYz+uP8Q==",
|
||||||
|
"license": "MIT",
|
||||||
|
"workspaces": [
|
||||||
|
"docs",
|
||||||
|
"benchmarks"
|
||||||
|
]
|
||||||
|
},
|
||||||
"node_modules/esbuild": {
|
"node_modules/esbuild": {
|
||||||
"version": "0.24.2",
|
"version": "0.24.2",
|
||||||
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.24.2.tgz",
|
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.24.2.tgz",
|
||||||
|
|||||||
@ -14,6 +14,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@kalimahapps/vue-icons": "^1.7.1",
|
"@kalimahapps/vue-icons": "^1.7.1",
|
||||||
|
"es-toolkit": "^1.32.0",
|
||||||
"pinia": "^2.3.1",
|
"pinia": "^2.3.1",
|
||||||
"vue": "^3.5.13",
|
"vue": "^3.5.13",
|
||||||
"vue-router": "^4.5.0"
|
"vue-router": "^4.5.0"
|
||||||
|
|||||||
@ -1,14 +1,19 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import {fields, type Specs} from '@/urlmaker/specs.ts';
|
import {fields, type Specs} from '@/urlmaker/specs.ts';
|
||||||
import Field from "@/components/Field.vue";
|
import Field from "@/components/Field.vue";
|
||||||
|
import {useWizardStore} from "@/stores/wizard.ts";
|
||||||
|
|
||||||
const model = defineModel<Specs>({required: true});
|
const store = useWizardStore();
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<Field v-for="field in fields" :field="field" v-model="model[field.name]"></Field>
|
<Field v-for="field in fields"
|
||||||
|
:field="field"
|
||||||
|
:model-value="store.specs[field.name]"
|
||||||
|
@update:model-value="event => store.updateSpec(field.name, event)"
|
||||||
|
></Field>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@ -42,7 +42,7 @@ function screenshot() {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="wrapper">
|
<div class="wrapper">
|
||||||
<SpecsForm :model-value="store.specs" @update:model-value="store.updateSpecs" class="specs-form"></SpecsForm>
|
<SpecsForm class="specs-form"></SpecsForm>
|
||||||
<Btn :active="store.formValid" @click="generateLink">Generate link</Btn>
|
<Btn :active="store.formValid" @click="generateLink">Generate link</Btn>
|
||||||
<Btn :active="store.formValid" @click="screenshot">Screenshot</Btn>
|
<Btn :active="store.formValid" @click="screenshot">Screenshot</Btn>
|
||||||
<Btn @click="editModalVisible = true">Edit existing task</Btn>
|
<Btn @click="editModalVisible = true">Edit existing task</Btn>
|
||||||
|
|||||||
@ -1,16 +1,35 @@
|
|||||||
import {defineStore} from "pinia";
|
import {defineStore} from "pinia";
|
||||||
import {emptySpecs, type Field, fields, type Specs} from "@/urlmaker/specs.ts";
|
import {emptySpecs, type Field, type FieldNames, fields, type Specs} from "@/urlmaker/specs.ts";
|
||||||
import {computed, reactive, ref} from "vue";
|
import {computed, reactive} from "vue";
|
||||||
|
import {debounce} from "es-toolkit";
|
||||||
|
|
||||||
|
const LOCAL_STORAGE_KEY = 'rssalchemy_store_wizard';
|
||||||
|
|
||||||
export const useWizardStore = defineStore('wizard', () => {
|
export const useWizardStore = defineStore('wizard', () => {
|
||||||
const specs = reactive(emptySpecs);
|
|
||||||
|
const locStorageContent = localStorage.getItem(LOCAL_STORAGE_KEY);
|
||||||
|
const defaultSpecs = locStorageContent ? JSON.parse(locStorageContent) as Specs : emptySpecs;
|
||||||
|
|
||||||
|
const specs = reactive(defaultSpecs);
|
||||||
|
|
||||||
const formValid = computed(() => {
|
const formValid = computed(() => {
|
||||||
return fields.every(field => (
|
return fields.every(field => (
|
||||||
specs[field.name].length === 0 && !(field as Field).required || field.validate(specs[field.name]).ok
|
specs[field.name].length === 0 && !(field as Field).required || field.validate(specs[field.name]).ok
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
function updateSpecs(newSpecs: Specs) {
|
|
||||||
Object.assign(specs, newSpecs);
|
const updateLocalStorage = debounce(() => {
|
||||||
|
localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(specs));
|
||||||
|
}, 500);
|
||||||
|
|
||||||
|
function updateSpec(fieldName: FieldNames, newValue: string) {
|
||||||
|
specs[fieldName] = newValue;
|
||||||
|
updateLocalStorage();
|
||||||
}
|
}
|
||||||
return {specs, formValid, updateSpecs};
|
function updateSpecs(newValue: Specs) {
|
||||||
|
Object.assign(specs, newValue);
|
||||||
|
updateLocalStorage();
|
||||||
|
}
|
||||||
|
|
||||||
|
return {specs, formValid, updateSpec, updateSpecs};
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user