2019-03-12 22:50:54 +01: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 21:54:45 +01:00
|
|
|
import GestureService from '../../services/gesture_service/gesture_service'
|
2020-07-10 12:21:42 +02:00
|
|
|
import { mapGetters } from 'vuex'
|
2020-10-20 20:18:23 +02:00
|
|
|
import { library } from '@fortawesome/fontawesome-svg-core'
|
|
|
|
import {
|
2020-10-20 21:13:19 +02:00
|
|
|
faTimes,
|
|
|
|
faBell,
|
|
|
|
faBars
|
2020-10-20 20:18:23 +02:00
|
|
|
} from '@fortawesome/free-solid-svg-icons'
|
|
|
|
|
|
|
|
library.add(
|
2020-10-20 21:13:19 +02:00
|
|
|
faTimes,
|
|
|
|
faBell,
|
|
|
|
faBars
|
2020-10-20 20:18:23 +02:00
|
|
|
)
|
2019-03-12 22:50:54 +01:00
|
|
|
|
|
|
|
const MobileNav = {
|
|
|
|
components: {
|
|
|
|
SideDrawer,
|
2019-07-31 19:18:47 +02:00
|
|
|
Notifications
|
2019-03-12 22:50:54 +01:00
|
|
|
},
|
|
|
|
data: () => ({
|
2019-03-28 21:54:45 +01:00
|
|
|
notificationsCloseGesture: undefined,
|
2019-03-12 22:50:54 +01:00
|
|
|
notificationsOpen: false
|
|
|
|
}),
|
2019-03-28 21:54:45 +01:00
|
|
|
created () {
|
|
|
|
this.notificationsCloseGesture = GestureService.swipeGesture(
|
|
|
|
GestureService.DIRECTION_RIGHT,
|
|
|
|
this.closeMobileNotifications,
|
|
|
|
50
|
|
|
|
)
|
|
|
|
},
|
2019-03-12 22:50:54 +01:00
|
|
|
computed: {
|
2019-03-14 19:40:56 +01:00
|
|
|
currentUser () {
|
|
|
|
return this.$store.state.users.currentUser
|
|
|
|
},
|
2019-03-12 22:50:54 +01:00
|
|
|
unseenNotifications () {
|
|
|
|
return unseenNotificationsFromStore(this.$store)
|
|
|
|
},
|
|
|
|
unseenNotificationsCount () {
|
|
|
|
return this.unseenNotifications.length
|
|
|
|
},
|
2019-12-02 01:34:01 +01:00
|
|
|
hideSitename () { return this.$store.state.instance.hideSitename },
|
2020-05-07 15:10:53 +02:00
|
|
|
sitename () { return this.$store.state.instance.name },
|
2020-07-07 20:43:46 +02:00
|
|
|
isChat () {
|
|
|
|
return this.$route.name === 'chat'
|
2020-07-10 12:21:42 +02:00
|
|
|
},
|
|
|
|
...mapGetters(['unreadChatCount'])
|
2019-03-12 22:50:54 +01:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
toggleMobileSidebar () {
|
|
|
|
this.$refs.sideDrawer.toggleDrawer()
|
|
|
|
},
|
2019-03-23 21:03:38 +01: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 16:46:04 +01:00
|
|
|
this.markNotificationsAsSeen()
|
|
|
|
}
|
2019-03-12 22:50:54 +01:00
|
|
|
},
|
2019-03-28 21:54:45 +01:00
|
|
|
notificationsTouchStart (e) {
|
|
|
|
GestureService.beginSwipe(e, this.notificationsCloseGesture)
|
|
|
|
},
|
|
|
|
notificationsTouchMove (e) {
|
|
|
|
GestureService.updateSwipe(e, this.notificationsCloseGesture)
|
|
|
|
},
|
2019-03-12 22:50:54 +01:00
|
|
|
scrollToTop () {
|
|
|
|
window.scrollTo(0, 0)
|
2019-03-14 16:46:04 +01:00
|
|
|
},
|
|
|
|
logout () {
|
|
|
|
this.$router.replace('/main/public')
|
|
|
|
this.$store.dispatch('logout')
|
|
|
|
},
|
|
|
|
markNotificationsAsSeen () {
|
|
|
|
this.$refs.notifications.markAsSeen()
|
2019-05-03 13:52:22 +02:00
|
|
|
},
|
|
|
|
onScroll ({ target: { scrollTop, clientHeight, scrollHeight } }) {
|
2020-07-14 14:08:04 +02:00
|
|
|
if (scrollTop + clientHeight >= scrollHeight) {
|
2019-05-03 13:52:22 +02:00
|
|
|
this.$refs.notifications.fetchOlderNotifications()
|
|
|
|
}
|
2019-03-12 22:50:54 +01:00
|
|
|
}
|
2019-03-23 21:03:38 +01:00
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
$route () {
|
|
|
|
// handles closing notificaitons when you press any router-link on the
|
|
|
|
// notifications.
|
|
|
|
this.closeMobileNotifications()
|
|
|
|
}
|
2019-03-12 22:50:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default MobileNav
|