feat: simplify filter-popup

This commit is contained in:
Dominik Pschenitschni 2021-10-01 20:14:21 +02:00
parent 8d88b3792d
commit 15640e98ec
No known key found for this signature in database
GPG key ID: B257AC0149F43A77
5 changed files with 33 additions and 27 deletions

View file

@ -1,9 +1,8 @@
<template> <template>
<transition name="fade"> <transition name="fade">
<filters <filters
@change="change"
v-if="visibleInternal" v-if="visibleInternal"
v-model="params" v-model="value"
ref="filters" ref="filters"
/> />
</transition> </transition>
@ -15,15 +14,33 @@ import Filters from '../../../components/list/partials/filters'
export default { export default {
name: 'filter-popup', name: 'filter-popup',
emits: ['update:modelValue', 'change'], components: {
Filters,
},
props: {
modelValue: {
required: true,
},
visible: {
type: Boolean,
default: false,
},
},
emits: ['update:modelValue'],
data() { data() {
return { return {
params: null,
visibleInternal: false, visibleInternal: false,
} }
}, },
components: { computed: {
Filters, value: {
get() {
return this.modelValue
},
set(value) {
this.$emit('update:modelValue', value)
},
},
}, },
mounted() { mounted() {
document.addEventListener('click', this.hidePopup) document.addEventListener('click', this.hidePopup)
@ -42,26 +59,15 @@ export default {
this.visibleInternal = !this.visibleInternal this.visibleInternal = !this.visibleInternal
}, },
}, },
props: {
modelValue: {
required: true,
},
visible: {
type: Boolean,
default: false,
},
},
methods: { methods: {
change() {
this.$emit('change', this.params)
this.$emit('update:modelValue', this.params)
},
hidePopup(e) { hidePopup(e) {
if (this.visibleInternal) { if (!this.visibleInternal) {
closeWhenClickedOutside(e, this.$refs.filters.$el, () => { return
this.visibleInternal = false
})
} }
closeWhenClickedOutside(e, this.$refs.filters.$el, () => {
this.visibleInternal = false
})
}, },
}, },
} }

View file

@ -11,9 +11,9 @@
</x-button> </x-button>
</div> </div>
<filter-popup <filter-popup
@change="loadTasks()"
:visible="showTaskFilter" :visible="showTaskFilter"
v-model="params" v-model="params"
@update:modelValue="loadTasks()"
/> />
</div> </div>
<div class="dates"> <div class="dates">

View file

@ -11,7 +11,7 @@
</x-button> </x-button>
</div> </div>
<filter-popup <filter-popup
@change="() => {filtersChanged = true; loadBuckets()}" @update:modelValue="() => {filtersChanged = true; loadBuckets()}"
:visible="showFilters" :visible="showFilters"
v-model="params" v-model="params"
/> />

View file

@ -50,9 +50,9 @@
</x-button> </x-button>
</div> </div>
<filter-popup <filter-popup
@change="loadTasks(1)"
:visible="showTaskFilter" :visible="showTaskFilter"
v-model="params" v-model="params"
@update:modelValue="loadTasks(1)"
/> />
</div> </div>

View file

@ -59,9 +59,9 @@
</card> </card>
</transition> </transition>
<filter-popup <filter-popup
@change="loadTasks(1)"
:visible="showTaskFilter" :visible="showTaskFilter"
v-model="params" v-model="params"
@update:modelValue="loadTasks(1)"
/> />
</div> </div>