Skip to content

Commit

Permalink
add: prepare scrolling to the current item
Browse files Browse the repository at this point in the history
  • Loading branch information
pbek committed Jun 7, 2024
1 parent 48e4b88 commit 42fb0f9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
18 changes: 9 additions & 9 deletions src/components/feed-display/FeedItemDisplayList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
</button>
</div>
<div class="feed-item-display-container">
<VirtualScroll :reached-end="reachedEnd"
<VirtualScroll ref="virtualScroll"
:reached-end="reachedEnd"
:fetch-key="fetchKey"
@load-more="fetchMore()">
<template v-if="items && items.length > 0">
Expand Down Expand Up @@ -77,7 +78,7 @@ const DEFAULT_DISPLAY_LIST_CONFIG = {
export type Config = {
unreadFilter: boolean;
starFlter: boolean;
starFilter: boolean;
}
export default Vue.extend({
Expand Down Expand Up @@ -194,7 +195,7 @@ export default Vue.extend({
return response.sort(this.sort)
},
// Trigger the click event programmatically to benefit from the item handling inside the FeedItemRow component
clickItem(item: FeedItem) {
clickItem(item: FeedItem, alignToTop = false) {

Check warning on line 198 in src/components/feed-display/FeedItemDisplayList.vue

View workflow job for this annotation

GitHub Actions / eslint node

'alignToTop' is assigned a value but never used

Check warning on line 198 in src/components/feed-display/FeedItemDisplayList.vue

View workflow job for this annotation

GitHub Actions / eslint

'alignToTop' is assigned a value but never used
const refName = 'feedItemRow' + item.id
const ref = this.$refs[refName]
// Make linter happy
Expand All @@ -203,10 +204,9 @@ export default Vue.extend({
if (element) {
element.click()
// TODO: This doesn't seem to do a lot in the VirtualScroll component
element.scrollIntoView(true)
// this.$nextTick(() => element.scrollIntoView())
const virtualScroll = this.$refs.virtualScroll

Check warning on line 207 in src/components/feed-display/FeedItemDisplayList.vue

View workflow job for this annotation

GitHub Actions / eslint node

'virtualScroll' is assigned a value but never used

Check warning on line 207 in src/components/feed-display/FeedItemDisplayList.vue

View workflow job for this annotation

GitHub Actions / eslint

'virtualScroll' is assigned a value but never used
// TODO: This is still jerky and even can derail the current item
// virtualScroll.showElement(element, alignToTop)
}
},
currentIndex(items: FeedItem[]): number {
Expand All @@ -222,7 +222,7 @@ export default Vue.extend({
// Jump to the previous item
if (currentIndex > 0) {
const previousItem = items[currentIndex - 1]
this.clickItem(previousItem)
this.clickItem(previousItem, true)
}
},
jumpToNextItem() {
Expand All @@ -231,7 +231,7 @@ export default Vue.extend({
// Jump to the first item, if none was selected, otherwise jump to the next item
if (currentIndex === -1 || (currentIndex < items.length - 1)) {
const nextItem = items[currentIndex + 1]
this.clickItem(nextItem)
this.clickItem(nextItem, false)
}
},
},
Expand Down
16 changes: 15 additions & 1 deletion src/components/feed-display/VirtualScroll.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ export default Vue.extend({
scrollHeight: 500,
initialLoadingSkeleton: false,
initialLoadingTimeout: null,
elementToShow: null,
}
},
computed: {
fetching() {
return this.$store.state.items.fetchingItems[this.key]
},
},
created() {
this.elementToShowAlignToTop = false
},
watch: {

Check warning on line 45 in src/components/feed-display/VirtualScroll.vue

View workflow job for this annotation

GitHub Actions / eslint node

The "watch" property should be above the "created" property on line 42

Check warning on line 45 in src/components/feed-display/VirtualScroll.vue

View workflow job for this annotation

GitHub Actions / eslint

The "watch" property should be above the "created" property on line 42
newBookmark() {
this.$el.scrollTop = 0
Expand All @@ -58,6 +62,10 @@ export default Vue.extend({
this.scrollTop = this.$el.scrollTop
this.scrollHeight = this.$el.scrollHeight
},
showElement(element, alignToTop) {
this.elementToShow = element
this.elementToShowAlignToTop = alignToTop
},
},
render(h) {
let children = []
Expand Down Expand Up @@ -106,7 +114,13 @@ export default Vue.extend({
const scrollTop = this.scrollTop
this.$nextTick(() => {
this.$el.scrollTop = scrollTop
if (this.elementToShow) {
// this.elementToShow.scrollIntoView(this.elementToShowAlignToTop)
this.elementToShow.scrollIntoView({ behavior: 'smooth', block: 'center' })
this.elementToShow = null
} else {
this.$el.scrollTop = scrollTop
}
})
return h('div', {
Expand Down

0 comments on commit 42fb0f9

Please sign in to comment.