pleroma-fe/src/components/mobile_nav/mobile_nav.js

156 lines
4.3 KiB
JavaScript
Raw Normal View History

2023-04-06 16:32:21 -06:00
import { mapState } from 'pinia'
2026-01-08 17:26:52 +02:00
import { mapGetters } from 'vuex'
2026-01-06 16:23:17 +02:00
import NavigationPins from 'src/components/navigation/navigation_pins.vue'
import GestureService from '../../services/gesture_service/gesture_service'
2020-10-20 21:18:23 +03:00
import {
2026-01-06 16:23:17 +02:00
countExtraNotifications,
unseenNotificationsFromStore,
} from '../../services/notification_utils/notification_utils'
import ConfirmModal from '../confirm_modal/confirm_modal.vue'
import Notifications from '../notifications/notifications.vue'
import SideDrawer from '../side_drawer/side_drawer.vue'
2020-10-20 21:18:23 +03:00
2026-01-29 20:44:55 +02:00
import { useAnnouncementsStore } from 'src/stores/announcements.js'
2026-01-29 20:40:00 +02:00
import { useInstanceStore } from 'src/stores/instance.js'
2026-02-13 13:59:00 +02:00
import { useSyncConfigStore } from 'src/stores/sync_config.js'
2026-01-29 20:40:00 +02:00
2026-01-08 17:26:52 +02:00
import { library } from '@fortawesome/fontawesome-svg-core'
import {
faArrowUp,
faBars,
faBell,
faCheckDouble,
faMinus,
faTimes,
} from '@fortawesome/free-solid-svg-icons'
2026-01-06 16:22:52 +02:00
library.add(faTimes, faBell, faBars, faArrowUp, faMinus, faCheckDouble)
const MobileNav = {
components: {
SideDrawer,
Notifications,
2022-02-09 16:51:13 -05:00
NavigationPins,
2026-01-06 16:22:52 +02:00
ConfirmModal,
},
data: () => ({
notificationsCloseGesture: undefined,
notificationsOpen: false,
2022-02-09 16:51:13 -05:00
notificationsAtTop: true,
2026-01-06 16:22:52 +02:00
showingConfirmLogout: false,
}),
2026-01-06 16:22:52 +02:00
created() {
this.notificationsCloseGesture = GestureService.swipeGesture(
GestureService.DIRECTION_RIGHT,
() => this.closeMobileNotifications(true),
2026-01-06 16:22:52 +02:00
50,
)
},
computed: {
2026-01-06 16:22:52 +02:00
currentUser() {
return this.$store.state.users.currentUser
},
2026-01-06 16:22:52 +02:00
unseenNotifications() {
return unseenNotificationsFromStore(this.$store)
},
2026-01-06 16:22:52 +02:00
unseenNotificationsCount() {
return (
this.unseenNotifications.length + countExtraNotifications(this.$store)
)
},
2026-01-06 16:22:52 +02:00
unseenCount() {
return this.unseenNotifications.length
},
2026-01-06 16:22:52 +02:00
unseenCountBadgeText() {
2023-12-13 20:38:39 +02:00
return `${this.unseenCount ? this.unseenCount : ''}`
2023-12-13 20:37:40 +02:00
},
2026-01-06 16:22:52 +02:00
hideSitename() {
return useInstanceStore().hideSitename
2026-01-06 16:22:52 +02:00
},
sitename() {
return useInstanceStore().name
2026-01-06 16:22:52 +02:00
},
isChat() {
return this.$route.name === 'chat'
2020-07-10 13:21:42 +03:00
},
2023-04-06 16:32:21 -06:00
...mapState(useAnnouncementsStore, ['unreadAnnouncementCount']),
2026-02-13 13:59:00 +02:00
...mapState(useSyncConfigStore, {
2026-01-06 16:22:52 +02:00
pinnedItems: (store) =>
new Set(store.prefsStorage.collections.pinnedNavItems).has('chats'),
2025-03-23 20:03:25 +02:00
}),
2026-01-06 16:22:52 +02:00
shouldConfirmLogout() {
2026-02-13 13:59:00 +02:00
return useSyncConfigStore().mergedConfig.modalOnLogout
2022-02-09 16:51:13 -05:00
},
2026-01-06 16:22:52 +02:00
closingDrawerMarksAsSeen() {
2026-02-13 13:59:00 +02:00
return useSyncConfigStore().mergedConfig.closingDrawerMarksAsSeen
2023-11-19 15:24:34 +02:00
},
2026-01-06 16:22:52 +02:00
...mapGetters(['unreadChatCount']),
},
methods: {
2026-01-06 16:22:52 +02:00
toggleMobileSidebar() {
this.$refs.sideDrawer.toggleDrawer()
},
2026-01-06 16:22:52 +02:00
openMobileNotifications() {
2019-03-23 22:03:38 +02:00
this.notificationsOpen = true
},
2026-01-06 16:22:52 +02:00
closeMobileNotifications(markRead) {
2019-03-23 22:03:38 +02:00
if (this.notificationsOpen) {
// make sure to mark notifs seen only when the notifs were open and not
// from close-calls.
this.notificationsOpen = false
2023-11-19 17:02:46 +02:00
if (markRead && this.closingDrawerMarksAsSeen) {
this.markNotificationsAsSeen()
}
}
},
2026-01-06 16:22:52 +02:00
notificationsTouchStart(e) {
GestureService.beginSwipe(e, this.notificationsCloseGesture)
},
2026-01-06 16:22:52 +02:00
notificationsTouchMove(e) {
GestureService.updateSwipe(e, this.notificationsCloseGesture)
},
2026-01-06 16:22:52 +02:00
scrollToTop() {
window.scrollTo(0, 0)
},
2026-01-06 16:22:52 +02:00
scrollMobileNotificationsToTop() {
this.$refs.mobileNotifications.scrollTo(0, 0)
},
2026-01-06 16:22:52 +02:00
showConfirmLogout() {
2022-02-09 16:51:13 -05:00
this.showingConfirmLogout = true
},
2026-01-06 16:22:52 +02:00
hideConfirmLogout() {
2022-02-09 16:51:13 -05:00
this.showingConfirmLogout = false
},
2026-01-06 16:22:52 +02:00
logout() {
2022-02-09 16:51:13 -05:00
if (!this.shouldConfirmLogout) {
this.doLogout()
} else {
this.showConfirmLogout()
}
},
2026-01-06 16:22:52 +02:00
doLogout() {
this.$router.replace('/main/public')
this.$store.dispatch('logout')
2022-02-09 16:51:13 -05:00
this.hideConfirmLogout()
},
2026-01-06 16:22:52 +02:00
markNotificationsAsSeen() {
2022-04-05 19:22:15 +03:00
this.$store.dispatch('markNotificationsAsSeen')
},
2026-01-06 16:22:52 +02:00
onScroll({ target: { scrollTop, clientHeight, scrollHeight } }) {
this.notificationsAtTop = scrollTop > 0
if (scrollTop + clientHeight >= scrollHeight) {
this.$refs.notifications.fetchOlderNotifications()
}
2026-01-06 16:22:52 +02:00
},
2019-03-23 22:03:38 +02:00
},
watch: {
2026-01-06 16:22:52 +02:00
$route() {
2019-03-23 22:03:38 +02:00
// handles closing notificaitons when you press any router-link on the
// notifications.
this.closeMobileNotifications()
2026-01-06 16:22:52 +02:00
},
},
}
export default MobileNav