add "scroll to top" button to timelines and notifications
This commit is contained in:
parent
2c76c46aa7
commit
efc6b6b703
|
@ -10,10 +10,11 @@ import {
|
||||||
} from '../../services/notification_utils/notification_utils.js'
|
} from '../../services/notification_utils/notification_utils.js'
|
||||||
import FaviconService from '../../services/favicon_service/favicon_service.js'
|
import FaviconService from '../../services/favicon_service/favicon_service.js'
|
||||||
import { library } from '@fortawesome/fontawesome-svg-core'
|
import { library } from '@fortawesome/fontawesome-svg-core'
|
||||||
import { faCircleNotch } from '@fortawesome/free-solid-svg-icons'
|
import { faCircleNotch, faCircleUp } from '@fortawesome/free-solid-svg-icons'
|
||||||
|
|
||||||
library.add(
|
library.add(
|
||||||
faCircleNotch
|
faCircleNotch,
|
||||||
|
faCircleUp
|
||||||
)
|
)
|
||||||
|
|
||||||
const DEFAULT_SEEN_TO_DISPLAY_COUNT = 30
|
const DEFAULT_SEEN_TO_DISPLAY_COUNT = 30
|
||||||
|
@ -34,6 +35,7 @@ const Notifications = {
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
|
showScrollTop: false,
|
||||||
bottomedOut: false,
|
bottomedOut: false,
|
||||||
// How many seen notifications to display in the list. The more there are,
|
// How many seen notifications to display in the list. The more there are,
|
||||||
// the heavier the page becomes. This count is increased when loading
|
// the heavier the page becomes. This count is increased when loading
|
||||||
|
@ -90,8 +92,16 @@ const Notifications = {
|
||||||
notificationsToDisplay () {
|
notificationsToDisplay () {
|
||||||
return this.filteredNotifications.slice(0, this.unseenCount + this.seenToDisplayCount)
|
return this.filteredNotifications.slice(0, this.unseenCount + this.seenToDisplayCount)
|
||||||
},
|
},
|
||||||
|
noSticky () { return this.$store.getters.mergedConfig.disableStickyHeaders },
|
||||||
...mapGetters(['unreadChatCount'])
|
...mapGetters(['unreadChatCount'])
|
||||||
},
|
},
|
||||||
|
mounted () {
|
||||||
|
this.scrollerRef = this.$refs.root.closest('.column.-scrollable')
|
||||||
|
this.scrollerRef.addEventListener('scroll', this.updateScrollPosition)
|
||||||
|
},
|
||||||
|
unmounted () {
|
||||||
|
this.scrollerRef.removeEventListener('scroll', this.updateScrollPosition)
|
||||||
|
},
|
||||||
watch: {
|
watch: {
|
||||||
unseenCountTitle (count) {
|
unseenCountTitle (count) {
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
|
@ -104,6 +114,14 @@ const Notifications = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
scrollToTop () {
|
||||||
|
const scrollable = this.scrollerRef
|
||||||
|
scrollable.scrollTo({ top: this.$refs.root.offsetTop })
|
||||||
|
// this.$refs.root.scrollIntoView({ behavior: 'smooth', block: 'start' })
|
||||||
|
},
|
||||||
|
updateScrollPosition () {
|
||||||
|
this.showScrollTop = this.$refs.root.offsetTop < this.scrollerRef.scrollTop
|
||||||
|
},
|
||||||
markAsSeen () {
|
markAsSeen () {
|
||||||
this.$store.dispatch('markNotificationsAsSeen')
|
this.$store.dispatch('markNotificationsAsSeen')
|
||||||
this.seenToDisplayCount = DEFAULT_SEEN_TO_DISPLAY_COUNT
|
this.seenToDisplayCount = DEFAULT_SEEN_TO_DISPLAY_COUNT
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
<div
|
<div
|
||||||
:class="{ minimal: minimalMode }"
|
:class="{ minimal: minimalMode }"
|
||||||
class="Notifications"
|
class="Notifications"
|
||||||
|
ref="root"
|
||||||
>
|
>
|
||||||
<div :class="mainClass">
|
<div :class="mainClass">
|
||||||
<div
|
<div
|
||||||
|
@ -19,12 +20,21 @@
|
||||||
class="badge badge-notification unseen-count"
|
class="badge badge-notification unseen-count"
|
||||||
>{{ unseenCount }}</span>
|
>{{ unseenCount }}</span>
|
||||||
</div>
|
</div>
|
||||||
|
<button
|
||||||
|
v-if="showScrollTop"
|
||||||
|
class="button-unstyled scroll-to-top-button"
|
||||||
|
type="button"
|
||||||
|
@click="scrollToTop"
|
||||||
|
>
|
||||||
|
<FAIcon icon="circle-up" />
|
||||||
|
</button>
|
||||||
<button
|
<button
|
||||||
v-if="unseenCount"
|
v-if="unseenCount"
|
||||||
class="button-default read-button"
|
class="button-default read-button"
|
||||||
|
type="button"
|
||||||
@click.prevent="markAsSeen"
|
@click.prevent="markAsSeen"
|
||||||
>
|
>
|
||||||
{{ $t('notifications.read') }}
|
<FAIcon icon="filter" />
|
||||||
</button>
|
</button>
|
||||||
<NotificationFilters />
|
<NotificationFilters />
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -29,6 +29,7 @@ const Timeline = {
|
||||||
],
|
],
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
|
showScrollTop: false,
|
||||||
paused: false,
|
paused: false,
|
||||||
unfocused: false,
|
unfocused: false,
|
||||||
bottomedOut: false,
|
bottomedOut: false,
|
||||||
|
@ -123,6 +124,9 @@ const Timeline = {
|
||||||
this.$store.commit('setLoading', { timeline: this.timelineName, value: false })
|
this.$store.commit('setLoading', { timeline: this.timelineName, value: false })
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
scrollToTop () {
|
||||||
|
window.scrollTo({ top: this.$el.offsetTop })
|
||||||
|
},
|
||||||
stopBlockingClicks: debounce(function () {
|
stopBlockingClicks: debounce(function () {
|
||||||
this.blockingClicks = false
|
this.blockingClicks = false
|
||||||
}, 1000),
|
}, 1000),
|
||||||
|
@ -222,6 +226,7 @@ const Timeline = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
handleScroll: throttle(function (e) {
|
handleScroll: throttle(function (e) {
|
||||||
|
this.showScrollTop = this.$el.offsetTop < window.scrollY
|
||||||
this.determineVisibleStatuses()
|
this.determineVisibleStatuses()
|
||||||
this.scrollLoad(e)
|
this.scrollLoad(e)
|
||||||
}, 200),
|
}, 200),
|
||||||
|
|
|
@ -2,6 +2,14 @@
|
||||||
<div :class="['Timeline', classes.root]">
|
<div :class="['Timeline', classes.root]">
|
||||||
<div :class="classes.header">
|
<div :class="classes.header">
|
||||||
<TimelineMenu v-if="!embedded" />
|
<TimelineMenu v-if="!embedded" />
|
||||||
|
<button
|
||||||
|
v-if="showScrollTop"
|
||||||
|
class="button-unstyled scroll-to-top-button"
|
||||||
|
type="button"
|
||||||
|
@click="scrollToTop"
|
||||||
|
>
|
||||||
|
<FAIcon icon="circle-up" />
|
||||||
|
</button>
|
||||||
<button
|
<button
|
||||||
v-if="showLoadButton"
|
v-if="showLoadButton"
|
||||||
class="button-default loadmore-button"
|
class="button-default loadmore-button"
|
||||||
|
|
Loading…
Reference in New Issue