1
0
mirror of https://git.pleroma.social/sjw/pleroma-fe.git synced 2024-11-12 08:10:40 +01:00
pleroma-fe/src/components/mobile_nav/mobile_nav.js

99 lines
2.6 KiB
JavaScript
Raw Normal View History

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