Skip to content

Commit

Permalink
Add resetting of posts list scroll position
Browse files Browse the repository at this point in the history
  • Loading branch information
jonamil committed Dec 7, 2024
1 parent 1ff6027 commit 86ae560
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/components/column-posts-list/ThePostsListColumnBody.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ const content = useContentStore();
const router = useRouter();
const route = useRoute();
const containerElement = ref<HTMLElement | null>(null);
const containerElement = ref<ComponentPublicInstance | null>(null);
onMounted(() => {
useInfiniteScroll(
containerElement,
containerElement.value?.$el,
() => {
if (content.currentCategoryHasSomePostItems && !content.currentCategoryHasAllPostItems) {
content.fetchPostItems();
Expand All @@ -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(' ', '&nbsp;')}” entries. Refresh the list to view newer posts.`;
Expand Down

1 comment on commit 86ae560

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for hackernews-dot-cool ready!

✅ Preview
https://hackernews-dot-cool-oyf5c4qg5-jonamil-56ba8df7.vercel.app

Built with commit 86ae560.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.