2019-03-12 21:50:54 +00: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-28 20:54:45 +00:00
|
|
|
import GestureService from '../../services/gesture_service/gesture_service'
|
2019-03-12 21:50:54 +00:00
|
|
|
|
|
|
|
const MobileNav = {
|
|
|
|
components: {
|
|
|
|
SideDrawer,
|
2019-07-31 17:18:47 +00:00
|
|
|
Notifications
|
2019-03-12 21:50:54 +00:00
|
|
|
},
|
|
|
|
data: () => ({
|
2019-03-28 20:54:45 +00:00
|
|
|
notificationsCloseGesture: undefined,
|
2019-03-12 21:50:54 +00:00
|
|
|
notificationsOpen: false
|
|
|
|
}),
|
2019-03-28 20:54:45 +00:00
|
|
|
created () {
|
|
|
|
this.notificationsCloseGesture = GestureService.swipeGesture(
|
|
|
|
GestureService.DIRECTION_RIGHT,
|
|
|
|
this.closeMobileNotifications,
|
|
|
|
50
|
|
|
|
)
|
|
|
|
},
|
2019-03-12 21:50:54 +00:00
|
|
|
computed: {
|
2019-03-14 18:40:56 +00:00
|
|
|
currentUser () {
|
|
|
|
return this.$store.state.users.currentUser
|
|
|
|
},
|
2019-03-12 21:50:54 +00: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-23 20:03:38 +00: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-14 15:46:04 +00:00
|
|
|
this.markNotificationsAsSeen()
|
|
|
|
}
|
2019-03-12 21:50:54 +00:00
|
|
|
},
|
2019-03-28 20:54:45 +00:00
|
|
|
notificationsTouchStart (e) {
|
|
|
|
GestureService.beginSwipe(e, this.notificationsCloseGesture)
|
|
|
|
},
|
|
|
|
notificationsTouchMove (e) {
|
|
|
|
GestureService.updateSwipe(e, this.notificationsCloseGesture)
|
|
|
|
},
|
2019-03-12 21:50:54 +00:00
|
|
|
scrollToTop () {
|
|
|
|
window.scrollTo(0, 0)
|
2019-03-14 15:46:04 +00:00
|
|
|
},
|
|
|
|
logout () {
|
|
|
|
this.$router.replace('/main/public')
|
|
|
|
this.$store.dispatch('logout')
|
|
|
|
},
|
|
|
|
markNotificationsAsSeen () {
|
|
|
|
this.$refs.notifications.markAsSeen()
|
2019-05-03 11:52:22 +00:00
|
|
|
},
|
|
|
|
onScroll ({ target: { scrollTop, clientHeight, scrollHeight } }) {
|
|
|
|
if (this.$store.state.config.autoLoad && scrollTop + clientHeight >= scrollHeight) {
|
|
|
|
this.$refs.notifications.fetchOlderNotifications()
|
|
|
|
}
|
2019-03-12 21:50:54 +00:00
|
|
|
}
|
2019-03-23 20:03:38 +00:00
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
$route () {
|
|
|
|
// handles closing notificaitons when you press any router-link on the
|
|
|
|
// notifications.
|
|
|
|
this.closeMobileNotifications()
|
|
|
|
}
|
2019-03-12 21:50:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default MobileNav
|