2019-03-13 08:50:54 +11:00
|
|
|
import SideDrawer from '../side_drawer/side_drawer.vue'
|
|
|
|
import Notifications from '../notifications/notifications.vue'
|
|
|
|
import { unseenNotificationsFromStore } from '../../services/notification_utils/notification_utils'
|
2019-03-29 07:54:45 +11:00
|
|
|
import GestureService from '../../services/gesture_service/gesture_service'
|
2019-03-13 08:50:54 +11:00
|
|
|
|
|
|
|
const MobileNav = {
|
|
|
|
components: {
|
|
|
|
SideDrawer,
|
2019-08-01 03:18:47 +10:00
|
|
|
Notifications
|
2019-03-13 08:50:54 +11:00
|
|
|
},
|
|
|
|
data: () => ({
|
2019-03-29 07:54:45 +11:00
|
|
|
notificationsCloseGesture: undefined,
|
2019-03-13 08:50:54 +11:00
|
|
|
notificationsOpen: false
|
|
|
|
}),
|
2019-03-29 07:54:45 +11:00
|
|
|
created () {
|
|
|
|
this.notificationsCloseGesture = GestureService.swipeGesture(
|
|
|
|
GestureService.DIRECTION_RIGHT,
|
|
|
|
this.closeMobileNotifications,
|
|
|
|
50
|
|
|
|
)
|
|
|
|
},
|
2019-03-13 08:50:54 +11:00
|
|
|
computed: {
|
2019-03-15 05:40:56 +11:00
|
|
|
currentUser () {
|
|
|
|
return this.$store.state.users.currentUser
|
|
|
|
},
|
2019-03-13 08:50:54 +11:00
|
|
|
unseenNotifications () {
|
|
|
|
return unseenNotificationsFromStore(this.$store)
|
|
|
|
},
|
|
|
|
unseenNotificationsCount () {
|
|
|
|
return this.unseenNotifications.length
|
|
|
|
},
|
|
|
|
sitename () { return this.$store.state.instance.name }
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
toggleMobileSidebar () {
|
|
|
|
this.$refs.sideDrawer.toggleDrawer()
|
|
|
|
},
|
2019-03-24 07:03:38 +11:00
|
|
|
openMobileNotifications () {
|
|
|
|
this.notificationsOpen = true
|
|
|
|
},
|
|
|
|
closeMobileNotifications () {
|
|
|
|
if (this.notificationsOpen) {
|
|
|
|
// make sure to mark notifs seen only when the notifs were open and not
|
|
|
|
// from close-calls.
|
|
|
|
this.notificationsOpen = false
|
2019-03-15 02:46:04 +11:00
|
|
|
this.markNotificationsAsSeen()
|
|
|
|
}
|
2019-03-13 08:50:54 +11:00
|
|
|
},
|
2019-03-29 07:54:45 +11:00
|
|
|
notificationsTouchStart (e) {
|
|
|
|
GestureService.beginSwipe(e, this.notificationsCloseGesture)
|
|
|
|
},
|
|
|
|
notificationsTouchMove (e) {
|
|
|
|
GestureService.updateSwipe(e, this.notificationsCloseGesture)
|
|
|
|
},
|
2019-03-13 08:50:54 +11:00
|
|
|
scrollToTop () {
|
|
|
|
window.scrollTo(0, 0)
|
2019-03-15 02:46:04 +11:00
|
|
|
},
|
|
|
|
logout () {
|
|
|
|
this.$router.replace('/main/public')
|
|
|
|
this.$store.dispatch('logout')
|
|
|
|
},
|
|
|
|
markNotificationsAsSeen () {
|
|
|
|
this.$refs.notifications.markAsSeen()
|
2019-05-03 21:52:22 +10:00
|
|
|
},
|
|
|
|
onScroll ({ target: { scrollTop, clientHeight, scrollHeight } }) {
|
2019-10-07 07:28:30 +11:00
|
|
|
if (this.$store.getters.mergedConfig.autoLoad && scrollTop + clientHeight >= scrollHeight) {
|
2019-05-03 21:52:22 +10:00
|
|
|
this.$refs.notifications.fetchOlderNotifications()
|
|
|
|
}
|
2019-03-13 08:50:54 +11:00
|
|
|
}
|
2019-03-24 07:03:38 +11:00
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
$route () {
|
|
|
|
// handles closing notificaitons when you press any router-link on the
|
|
|
|
// notifications.
|
|
|
|
this.closeMobileNotifications()
|
|
|
|
}
|
2019-03-13 08:50:54 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default MobileNav
|