feat: filter-popup script setup (#2418)

Co-authored-by: Dominik Pschenitschni <mail@celement.de>
Reviewed-on: https://kolaente.dev/vikunja/frontend/pulls/2418
Co-authored-by: Dominik Pschenitschni <dpschen@noreply.kolaente.de>
Co-committed-by: Dominik Pschenitschni <dpschen@noreply.kolaente.de>
This commit is contained in:
Dominik Pschenitschni 2022-09-26 15:58:54 +00:00 committed by konrad
parent 1eae7ece9c
commit ba2605af1b

View file

@ -29,37 +29,41 @@
</modal> </modal>
</template> </template>
<script lang="ts"> <script setup lang="ts">
import {defineComponent, ref} from 'vue' import {computed, ref, watch} from 'vue'
import Filters from '@/components/list/partials/filters.vue' import Filters from '@/components/list/partials/filters.vue'
import {getDefaultParams} from '@/composables/taskList' import {getDefaultParams} from '@/composables/taskList'
export default defineComponent({ const props = defineProps({
name: 'filter-popup',
components: {
Filters,
},
props: {
modelValue: { modelValue: {
required: true, required: true,
}, },
}, })
emits: ['update:modelValue'], const emit = defineEmits(['update:modelValue'])
computed: {
value: { const value = computed({
get() { get() {
return this.modelValue return props.modelValue
}, },
set(value) { set(value) {
this.$emit('update:modelValue', value) emit('update:modelValue', value)
}, },
})
watch(
() => props.modelValue,
(modelValue) => {
value.value = modelValue
}, },
hasFilters() { {immediate: true},
)
const hasFilters = computed(() => {
// this.value also contains the page parameter which we don't want to include in filters // this.value also contains the page parameter which we don't want to include in filters
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
const {filter_by, filter_value, filter_comparator, filter_concat, s} = this.value const {filter_by, filter_value, filter_comparator, filter_concat, s} = value.value
const def = {...getDefaultParams()} const def = {...getDefaultParams()}
const params = {filter_by, filter_value, filter_comparator, filter_concat, s} const params = {filter_by, filter_value, filter_comparator, filter_concat, s}
@ -72,29 +76,13 @@ export default defineComponent({
} }
return JSON.stringify(params) !== JSON.stringify(defaultParams) return JSON.stringify(params) !== JSON.stringify(defaultParams)
}, })
},
watch: {
modelValue: {
handler(value) {
this.value = value
},
immediate: true,
},
},
setup() {
const modalOpen = ref(false) const modalOpen = ref(false)
return { function clearFilters() {
modalOpen, value.value = {...getDefaultParams()}
} }
},
methods: {
clearFilters() {
this.value = {...getDefaultParams()}
},
},
})
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">