logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://anongit.hacktivis.me/git/pleroma-fe.git/

mobile_nav.js (4354B)


  1. import SideDrawer from '../side_drawer/side_drawer.vue'
  2. import Notifications from '../notifications/notifications.vue'
  3. import ConfirmModal from '../confirm_modal/confirm_modal.vue'
  4. import {
  5. unseenNotificationsFromStore,
  6. countExtraNotifications
  7. } from '../../services/notification_utils/notification_utils'
  8. import GestureService from '../../services/gesture_service/gesture_service'
  9. import NavigationPins from 'src/components/navigation/navigation_pins.vue'
  10. import { mapGetters } from 'vuex'
  11. import { mapState } from 'pinia'
  12. import { library } from '@fortawesome/fontawesome-svg-core'
  13. import {
  14. faTimes,
  15. faBell,
  16. faBars,
  17. faArrowUp,
  18. faMinus,
  19. faCheckDouble
  20. } from '@fortawesome/free-solid-svg-icons'
  21. import { useAnnouncementsStore } from 'src/stores/announcements'
  22. library.add(
  23. faTimes,
  24. faBell,
  25. faBars,
  26. faArrowUp,
  27. faMinus,
  28. faCheckDouble
  29. )
  30. const MobileNav = {
  31. components: {
  32. SideDrawer,
  33. Notifications,
  34. NavigationPins,
  35. ConfirmModal
  36. },
  37. data: () => ({
  38. notificationsCloseGesture: undefined,
  39. notificationsOpen: false,
  40. notificationsAtTop: true,
  41. showingConfirmLogout: false
  42. }),
  43. created () {
  44. this.notificationsCloseGesture = GestureService.swipeGesture(
  45. GestureService.DIRECTION_RIGHT,
  46. () => this.closeMobileNotifications(true),
  47. 50
  48. )
  49. },
  50. computed: {
  51. currentUser () {
  52. return this.$store.state.users.currentUser
  53. },
  54. unseenNotifications () {
  55. return unseenNotificationsFromStore(this.$store)
  56. },
  57. unseenNotificationsCount () {
  58. return this.unseenNotifications.length + countExtraNotifications(this.$store)
  59. },
  60. unseenCount () {
  61. return this.unseenNotifications.length
  62. },
  63. unseenCountBadgeText () {
  64. return `${this.unseenCount ? this.unseenCount : ''}`
  65. },
  66. hideSitename () { return this.$store.state.instance.hideSitename },
  67. sitename () { return this.$store.state.instance.name },
  68. isChat () {
  69. return this.$route.name === 'chat'
  70. },
  71. ...mapState(useAnnouncementsStore, ['unreadAnnouncementCount']),
  72. ...mapGetters(['unreadChatCount']),
  73. chatsPinned () {
  74. return new Set(this.$store.state.serverSideStorage.prefsStorage.collections.pinnedNavItems).has('chats')
  75. },
  76. shouldConfirmLogout () {
  77. return this.$store.getters.mergedConfig.modalOnLogout
  78. },
  79. closingDrawerMarksAsSeen () {
  80. return this.$store.getters.mergedConfig.closingDrawerMarksAsSeen
  81. },
  82. ...mapGetters(['unreadChatCount'])
  83. },
  84. methods: {
  85. toggleMobileSidebar () {
  86. this.$refs.sideDrawer.toggleDrawer()
  87. },
  88. openMobileNotifications () {
  89. this.notificationsOpen = true
  90. },
  91. closeMobileNotifications (markRead) {
  92. if (this.notificationsOpen) {
  93. // make sure to mark notifs seen only when the notifs were open and not
  94. // from close-calls.
  95. this.notificationsOpen = false
  96. if (markRead && this.closingDrawerMarksAsSeen) {
  97. this.markNotificationsAsSeen()
  98. }
  99. }
  100. },
  101. notificationsTouchStart (e) {
  102. GestureService.beginSwipe(e, this.notificationsCloseGesture)
  103. },
  104. notificationsTouchMove (e) {
  105. GestureService.updateSwipe(e, this.notificationsCloseGesture)
  106. },
  107. scrollToTop () {
  108. window.scrollTo(0, 0)
  109. },
  110. scrollMobileNotificationsToTop () {
  111. this.$refs.mobileNotifications.scrollTo(0, 0)
  112. },
  113. showConfirmLogout () {
  114. this.showingConfirmLogout = true
  115. },
  116. hideConfirmLogout () {
  117. this.showingConfirmLogout = false
  118. },
  119. logout () {
  120. if (!this.shouldConfirmLogout) {
  121. this.doLogout()
  122. } else {
  123. this.showConfirmLogout()
  124. }
  125. },
  126. doLogout () {
  127. this.$router.replace('/main/public')
  128. this.$store.dispatch('logout')
  129. this.hideConfirmLogout()
  130. },
  131. markNotificationsAsSeen () {
  132. this.$store.dispatch('markNotificationsAsSeen')
  133. },
  134. onScroll ({ target: { scrollTop, clientHeight, scrollHeight } }) {
  135. this.notificationsAtTop = scrollTop > 0
  136. if (scrollTop + clientHeight >= scrollHeight) {
  137. this.$refs.notifications.fetchOlderNotifications()
  138. }
  139. }
  140. },
  141. watch: {
  142. $route () {
  143. // handles closing notificaitons when you press any router-link on the
  144. // notifications.
  145. this.closeMobileNotifications()
  146. }
  147. }
  148. }
  149. export default MobileNav