From 7bca8a41945b16433788d25fd65f647e479f4ae2 Mon Sep 17 00:00:00 2001 From: alexm <alexm@verdnatura.es> Date: Tue, 21 Jan 2025 13:48:04 +0100 Subject: [PATCH 1/2] fix(VnSection): refs #8197 check route --- src/components/common/VnSection.vue | 32 ++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/components/common/VnSection.vue b/src/components/common/VnSection.vue index 16ea79047..69e25cdfd 100644 --- a/src/components/common/VnSection.vue +++ b/src/components/common/VnSection.vue @@ -2,9 +2,9 @@ import RightMenu from './RightMenu.vue'; import VnSearchbar from 'components/ui/VnSearchbar.vue'; import VnTableFilter from '../VnTable/VnTableFilter.vue'; -import { onBeforeMount, computed, ref } from 'vue'; +import { onBeforeMount, onMounted, onUnmounted, computed, ref } from 'vue'; import { useArrayData } from 'src/composables/useArrayData'; -import { useRoute } from 'vue-router'; +import { useRoute, useRouter } from 'vue-router'; import { useHasContent } from 'src/composables/useHasContent'; const $props = defineProps({ @@ -47,16 +47,12 @@ const $props = defineProps({ }); const route = useRoute(); +const router = useRouter(); + let arrayData; const sectionValue = computed(() => $props.section ?? $props.dataKey); -const isMainSection = computed(() => { - const isSame = sectionValue.value == route.name; - if (!isSame && arrayData) { - arrayData.reset(['userParams', 'filter']); - arrayData.setCurrentFilter(); - } - return isSame; -}); +const isMainSection = ref(); + const searchbarId = 'section-searchbar'; const hasContent = useHasContent(`#${searchbarId}`); @@ -68,7 +64,23 @@ onBeforeMount(() => { ...$props.arrayDataProps, navigate: $props.redirect, }); + checkIsMain(); }); + +onMounted(() => { + const unsubscribe = router.afterEach(() => { + checkIsMain(); + }); + onUnmounted(() => unsubscribe()); +}); + +function checkIsMain() { + isMainSection.value = sectionValue.value == route.name; + if (!isMainSection.value && arrayData) { + arrayData.reset(['userParams', 'filter']); + arrayData.setCurrentFilter(); + } +} </script> <template> <slot name="searchbar"> From 979c96c5ac8a3611d0d6f5faa70129885a078ca6 Mon Sep 17 00:00:00 2001 From: alexm <alexm@verdnatura.es> Date: Tue, 21 Jan 2025 14:11:03 +0100 Subject: [PATCH 2/2] perf: refs #8197 perf --- src/components/common/VnSection.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/common/VnSection.vue b/src/components/common/VnSection.vue index 69e25cdfd..cacb3d551 100644 --- a/src/components/common/VnSection.vue +++ b/src/components/common/VnSection.vue @@ -51,7 +51,7 @@ const router = useRouter(); let arrayData; const sectionValue = computed(() => $props.section ?? $props.dataKey); -const isMainSection = ref(); +const isMainSection = ref(false); const searchbarId = 'section-searchbar'; const hasContent = useHasContent(`#${searchbarId}`); @@ -71,7 +71,7 @@ onMounted(() => { const unsubscribe = router.afterEach(() => { checkIsMain(); }); - onUnmounted(() => unsubscribe()); + onUnmounted(unsubscribe); }); function checkIsMain() {