refactor classic widgets to composition API

This commit is contained in:
Johann150 2022-08-01 21:34:38 +02:00
parent bcb07d819f
commit 2e71083823
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1

View file

@ -1,66 +1,58 @@
<template>
<div class="ddiqwdnk">
<XWidgets class="widgets" :edit="editMode" :widgets="$store.reactiveState.widgets.value.filter(w => w.place === place)" @add-widget="addWidget" @remove-widget="removeWidget" @update-widget="updateWidget" @update-widgets="updateWidgets" @exit="editMode = false"/>
<XWidgets class="widgets" :edit="editMode" :widgets="defaultStore.reactiveState.widgets.value.filter(w => w.place === place)" @add-widget="addWidget" @remove-widget="removeWidget" @update-widget="updateWidget" @update-widgets="updateWidgets" @exit="editMode = false"/>
<button v-if="editMode" class="_textButton edit" style="font-size: 0.9em;" @click="editMode = false"><i class="fas fa-check"></i> {{ $ts.editWidgetsExit }}</button>
<button v-else class="_textButton edit" style="font-size: 0.9em;" @click="editMode = true"><i class="fas fa-pencil-alt"></i> {{ $ts.editWidgets }}</button>
<button v-if="editMode" class="_textButton edit" style="font-size: 0.9em;" @click="editMode = false"><i class="fas fa-check"></i> {{ i81n.ts.editWidgetsExit }}</button>
<button v-else class="_textButton edit" style="font-size: 0.9em;" @click="editMode = true"><i class="fas fa-pencil-alt"></i> {{ i18n.ts.editWidgets }}</button>
</div>
</template>
<script lang="ts">
import { defineComponent, defineAsyncComponent } from 'vue';
<script lang="ts" setup>
import { defineAsyncComponent, onMounted } from 'vue';
import XWidgets from '@/components/widgets.vue';
import { defaultStore } from '@/store';
import { i18n } from '@/i18n';
export default defineComponent({
components: {
XWidgets
},
const emit = defineEmits<{
(ev: 'mounted'): void;
}>();
props: {
const props = defineProps<{
place: {
type: String,
}
},
emits: ['mounted'],
data() {
return {
editMode: false,
type: string;
};
},
}>();
mounted() {
this.$emit('mounted', this.$el);
},
let editMode: boolean = $ref(false);
methods: {
addWidget(widget) {
this.$store.set('widgets', [{
onMounted(() => {
emit('mounted');
}
function addWidget(widget) {
defaultStore.set('widgets', [{
...widget,
place: this.place,
}, ...this.$store.state.widgets]);
},
place: props.place,
}, ...defaultStore.state.widgets]);
}
removeWidget(widget) {
this.$store.set('widgets', this.$store.state.widgets.filter(w => w.id !== widget.id));
},
function removeWidget(widget) {
defaultStore.set('widgets', defaultStore.state.widgets.filter(w => w.id !== widget.id));
}
updateWidget({ id, data }) {
this.$store.set('widgets', this.$store.state.widgets.map(w => w.id === id ? {
function updateWidget({ id, data }) {
defaultStore.set('widgets', defaultStore.state.widgets.map(w => w.id === id ? {
...w,
data,
} : w));
},
}
updateWidgets(widgets) {
this.$store.set('widgets', [
...this.$store.state.widgets.filter(w => w.place !== this.place),
function updateWidgets(widgets) {
defaultStore.set('widgets', [
...defaultStore.state.widgets.filter(w => w.place !== props.place),
...widgets
]);
}
}
});
}
</script>
<style lang="scss" scoped>