Change scroll component to use scrollToItem method in bookmarks

This commit is contained in:
AkiraFukushima 2021-07-23 22:04:58 +09:00
parent ba23629596
commit a0d36875db
No known key found for this signature in database
GPG Key ID: B6E51BAC4DE1A957
1 changed files with 26 additions and 25 deletions

View File

@ -1,13 +1,14 @@
<template>
<div id="bookmarks" v-shortkey="shortcutEnabled ? { next: ['j'] } : {}" @shortkey="handleKey">
<div v-shortkey="{ linux: ['ctrl', 'r'], mac: ['meta', 'r'] }" @shortkey="reload()"></div>
<DynamicScroller :items="bookmarks" :min-item-size="60" class="scroller" page-mode>
<DynamicScroller :items="bookmarks" :min-item-size="60" id="scroller" class="scroller" ref="scroller">
<template v-slot="{ item, index, active }">
<DynamicScrollerItem :item="item" :active="active" :size-dependencies="[item.uri]" :data-index="index" :watchData="true">
<toot
:message="item"
:focused="item.uri === focusedId"
:overlaid="modalOpened"
:filters="[]"
v-on:update="updateToot"
v-on:delete="deleteToot"
@focusNext="focusNext"
@ -18,7 +19,6 @@
</DynamicScrollerItem>
</template>
</DynamicScroller>
<div class="loading-card" v-loading="lazyLoading" :element-loading-background="backgroundColor"></div>
<div :class="openSideBar ? 'upper-with-side-bar' : 'upper'" v-show="!heading">
<el-button type="primary" icon="el-icon-arrow-up" @click="upper" circle> </el-button>
</div>
@ -27,7 +27,6 @@
<script>
import { mapState, mapGetters } from 'vuex'
import scrollTop from '@/components/utils/scroll'
import Toot from '@/components/organisms/Toot'
import reloadable from '~/src/renderer/components/mixins/reloadable'
import { Event } from '~/src/renderer/components/event'
@ -79,7 +78,7 @@ export default {
})
},
mounted() {
document.getElementById('scrollable').addEventListener('scroll', this.onScroll)
document.getElementById('scroller').addEventListener('scroll', this.onScroll)
Event.$on('focus-timeline', () => {
// If focusedId does not change, we have to refresh focusedId because Toot component watch change events.
const previousFocusedId = this.focusedId
@ -94,9 +93,9 @@ export default {
},
destroyed() {
this.$store.commit('TimelineSpace/Contents/Bookmarks/updateBookmarks', [])
if (document.getElementById('scrollable') !== undefined && document.getElementById('scrollable') !== null) {
document.getElementById('scrollable').removeEventListener('scroll', this.onScroll)
document.getElementById('scrollable').scrollTop = 0
if (document.getElementById('scroller') !== undefined && document.getElementById('scroller') !== null) {
document.getElementById('scroller').removeEventListener('scroll', this.onScroll)
document.getElementById('scroller').scrollTop = 0
}
},
watch: {
@ -124,7 +123,7 @@ export default {
},
onScroll(event) {
if (
event.target.clientHeight + event.target.scrollTop >= document.getElementById('bookmarks').clientHeight - 10 &&
event.target.clientHeight + event.target.scrollTop >= document.getElementById('scroller').scrollHeight - 10 &&
!this.lazyloading
) {
this.$store.dispatch('TimelineSpace/Contents/Bookmarks/lazyFetchBookmarks', this.bookmarks[this.bookmarks.length - 1]).catch(() => {
@ -156,7 +155,7 @@ export default {
}
},
upper() {
scrollTop(document.getElementById('scrollable'), 0)
this.$refs.scroller.scrollToItem(0)
this.focusedId = null
},
focusNext() {
@ -193,24 +192,26 @@ export default {
</script>
<style lang="scss" scoped>
.loading-card {
height: 60px;
}
#bookmarks {
height: 100%;
overflow: auto;
scroll-behavior: auto;
.loading-card:empty {
height: 0;
}
.scroller {
height: 100%;
}
.upper {
position: fixed;
bottom: 20px;
right: 20px;
}
.upper {
position: fixed;
bottom: 20px;
right: 20px;
}
.upper-with-side-bar {
position: fixed;
bottom: 20px;
right: calc(20px + var(--current-sidebar-width));
transition: all 0.5s;
.upper-with-side-bar {
position: fixed;
bottom: 20px;
right: calc(20px + var(--current-sidebar-width));
transition: all 0.5s;
}
}
</style>