From 86ae560d9037f7fccc66c4dbac25e228603928d0 Mon Sep 17 00:00:00 2001 From: Jona <8698248+jonamil@users.noreply.github.com> Date: Sun, 8 Dec 2024 00:39:04 +0100 Subject: [PATCH] Add resetting of posts list scroll position --- .../column-posts-list/ThePostsListColumnBody.vue | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/components/column-posts-list/ThePostsListColumnBody.vue b/src/components/column-posts-list/ThePostsListColumnBody.vue index b186c37..a0ca6ef 100644 --- a/src/components/column-posts-list/ThePostsListColumnBody.vue +++ b/src/components/column-posts-list/ThePostsListColumnBody.vue @@ -23,11 +23,11 @@ const content = useContentStore(); const router = useRouter(); const route = useRoute(); -const containerElement = ref(null); +const containerElement = ref(null); onMounted(() => { useInfiniteScroll( - containerElement, + containerElement.value?.$el, () => { if (content.currentCategoryHasSomePostItems && !content.currentCategoryHasAllPostItems) { content.fetchPostItems(); @@ -37,6 +37,15 @@ onMounted(() => { ); }); +// reset container's scroll position when category is switched +watch( + () => content.currentCategory, + () => { + if (!containerElement.value) return; + containerElement.value.$el.scrollTop = 0; + } +); + const statusMessage = computed(() => { if (content.currentCategoryHasAllPostItems) return `You have browsed all “${content.currentCategoryName.replace(' ', ' ')}” entries. Refresh the list to view newer posts.`;