savestate

This commit is contained in:
Yannick7777 2025-04-01 23:05:16 +02:00
parent 101754cc43
commit 3514c4df4e
2 changed files with 70 additions and 45 deletions

View file

@ -3,72 +3,102 @@ import Rule from '@/components/Rule.vue'
import { reactive, computed, ref } from 'vue' import { reactive, computed, ref } from 'vue'
let currentRule = ref(0) let currentRule = ref(0)
let lang = "eng" let lang = ref(true)
const toggleLang = () => {
lang.value = !lang.value
}
const availableRules = computed(() => { const availableRules = computed(() => {
rules = this.rules.find(rule => rule.lang === this.lang) console.log("Rule update:", rules);
if (this.lang === "eng") { return rules.map(rule => {
rules.description = rules.engdescription if (lang.value) {
rule.name = rule.engname
rule.description = rule.engdescription
} else { } else {
rules.description = rules.gerdescription rule.name = rule.gername
rule.description = rule.gerdescription
} }
return rule;
return rules })
}) })
let rules = [ let rules = reactive([
{ {
name: "Strings can be simply matched by setting them as a regex Rule", engname: "Strings can be simply matched by setting them as a regex Rule",
description: "Nothing yet", engdescription: "Nothing yet",
gername: "aaaa",
gerdescription: "",
name: "",
description: "",
id: 0 id: 0
}, },
{ {
name: "Dots represent any number of any Character", engname: "Dots represent any number of any Character",
description: "Nothing yet", engdescription: "Nothing yet",
gername: "",
gerdescription: "",
id: 1 id: 1
}, },
{ {
name: "Put characters in square brackets to match any of them", engname: "Put characters in square brackets to match any of them",
description: "Nothing yet", engdescription: "Nothing yet",
gername: "",
gerdescription: "",
id: 2 id: 2
}, },
{ {
name: "Put a range of numbers inside square brackets with a dash in between to match a range", engname: "Put a range of numbers inside square brackets with a dash in between to match a range",
description: "Nothing yet", engdescription: "Nothing yet",
gername: "",
gerdescription: "",
id: 3 id: 3
}, },
{ {
name: "Use an asterisk to match any amount of a specific character", engname: "Use an asterisk to match any amount of a specific character",
description: "Nothing yet", engdescription: "Nothing yet",
gername: "",
gerdescription: "",
id: 4 id: 4
}, },
{ {
name: "Use a plus sign to match a specific character if it exists one or more times", engname: "Use a plus sign to match a specific character if it exists one or more times",
description: "Nothing yet", engdescription: "Nothing yet",
gername: "",
gerdescription: "",
id: 5 id: 5
}, },
{ {
name: "Use a question mark to match a character that could exist optionally", engname: "Use a question mark to match a character that could exist optionally",
description: "Nothing yet", engdescription: "Nothing yet",
gername: "",
gerdescription: "",
id: 6 id: 6
}, },
{ {
name: "To match a specific amount of a specific character, use curly braces", engname: "To match a specific amount of a specific character, use curly braces",
description: "Nothing yet", engdescription: "Nothing yet",
gername: "",
gerdescription: "",
id: 7 id: 7
}, },
{ {
name: "To match a specific amount or a higher amount of a specific character, use curly braces with a comma", engname: "To match a specific amount or a higher amount of a specific character, use curly braces with a comma",
description: "Nothing yet", engdescription: "Nothing yet",
gername: "",
gerdescription: "",
id: 8 id: 8
}, },
{ {
name: "To match a number of characters within a specific range, use curly braces with the range and a comma in between", engname: "To match a number of characters within a specific range, use curly braces with the range and a comma in between",
description: "Nothing yet", engdescription: "Nothing yet",
gername: "",
gerdescription: "",
id: 9 id: 9
} }
] ]
)
@ -80,14 +110,10 @@ let rules = [
<option v-for="rule in availableRules" :key="rule.id" :value="rule.id"> <option v-for="rule in availableRules" :key="rule.id" :value="rule.id">
{{ rule.name }} {{ rule.name }}
</option> </option>
</select> </select>
{{ currentRule }} <Rule :currentRule="currentRule" :rules="rules" />
<Rule <br>
:currentRule="currentRule" <button @click="toggleLang">{{ lang ? "Toggele Sprache" : "Toggle language" }}</button>
:rules="rules"
:lang="lang"
/>
</template> </template>
<style scoped> <style scoped></style>
</style>

View file

@ -3,8 +3,7 @@ import { computed } from 'vue'
const props = defineProps ({ const props = defineProps ({
rules: Array, rules: Array,
currentRule: Number, currentRule: Number,
lang: String })
})
const currentRuleObj = computed(() => { const currentRuleObj = computed(() => {
return props.rules.find(rule => rule.id === props.currentRule) return props.rules.find(rule => rule.id === props.currentRule)