logo

pleroma-fe

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

timeline_menu.js (3589B)


  1. import Popover from '../popover/popover.vue'
  2. import NavigationEntry from 'src/components/navigation/navigation_entry.vue'
  3. import { mapState } from 'vuex'
  4. import { ListsMenuContent } from '../lists_menu/lists_menu_content.vue'
  5. import { BookmarkFoldersMenuContent } from '../bookmark_folders_menu/bookmark_folders_menu_content.vue'
  6. import { library } from '@fortawesome/fontawesome-svg-core'
  7. import { TIMELINES } from 'src/components/navigation/navigation.js'
  8. import { filterNavigation } from 'src/components/navigation/filter.js'
  9. import {
  10. faChevronDown
  11. } from '@fortawesome/free-solid-svg-icons'
  12. library.add(faChevronDown)
  13. // Route -> i18n key mapping, exported and not in the computed
  14. // because nav panel benefits from the same information.
  15. export const timelineNames = (supportsBookmarkFolders) => {
  16. return {
  17. friends: 'nav.home_timeline',
  18. bookmarks: supportsBookmarkFolders ? 'nav.all_bookmarks' : 'nav.bookmarks',
  19. dms: 'nav.dms',
  20. 'public-timeline': 'nav.public_tl',
  21. 'public-external-timeline': 'nav.twkn',
  22. quotes: 'nav.quotes'
  23. }
  24. }
  25. const TimelineMenu = {
  26. components: {
  27. Popover,
  28. NavigationEntry,
  29. ListsMenuContent,
  30. BookmarkFoldersMenuContent
  31. },
  32. data () {
  33. return {
  34. isOpen: false
  35. }
  36. },
  37. created () {
  38. if (timelineNames(this.bookmarkFolders)[this.$route.name]) {
  39. this.$store.dispatch('setLastTimeline', this.$route.name)
  40. }
  41. },
  42. computed: {
  43. useListsMenu () {
  44. const route = this.$route.name
  45. return route === 'lists-timeline'
  46. },
  47. useBookmarkFoldersMenu () {
  48. const route = this.$route.name
  49. return this.bookmarkFolders && (route === 'bookmark-folder' || route === 'bookmarks')
  50. },
  51. ...mapState({
  52. currentUser: state => state.users.currentUser,
  53. privateMode: state => state.instance.private,
  54. federating: state => state.instance.federating,
  55. bookmarkFolders: state => state.instance.pleromaBookmarkFoldersAvailable
  56. }),
  57. timelinesList () {
  58. return filterNavigation(
  59. Object.entries(TIMELINES).map(([k, v]) => ({ ...v, name: k })),
  60. {
  61. hasChats: this.pleromaChatMessagesAvailable,
  62. isFederating: this.federating,
  63. isPrivate: this.privateMode,
  64. currentUser: this.currentUser,
  65. supportsBookmarkFolders: this.bookmarkFolders
  66. }
  67. )
  68. }
  69. },
  70. methods: {
  71. openMenu () {
  72. // $nextTick is too fast, animation won't play back but
  73. // instead starts in fully open position. Low values
  74. // like 1-5 work on fast machines but not on mobile, 25
  75. // seems like a good compromise that plays without significant
  76. // added lag.
  77. setTimeout(() => {
  78. this.isOpen = true
  79. }, 25)
  80. },
  81. blockOpen (event) {
  82. // For the blank area inside the button element.
  83. // Just setting @click.stop="" makes unintuitive behavior when
  84. // menu is open and clicking on the blank area doesn't close it.
  85. if (!this.isOpen) {
  86. event.stopPropagation()
  87. }
  88. },
  89. timelineName () {
  90. const route = this.$route.name
  91. if (route === 'tag-timeline') {
  92. return '#' + this.$route.params.tag
  93. }
  94. if (route === 'lists-timeline') {
  95. return this.$store.getters.findListTitle(this.$route.params.id)
  96. }
  97. if (route === 'bookmark-folder') {
  98. return this.$store.getters.findBookmarkFolderName(this.$route.params.id)
  99. }
  100. const i18nkey = timelineNames(this.bookmarkFolders)[this.$route.name]
  101. return i18nkey ? this.$t(i18nkey) : route
  102. }
  103. }
  104. }
  105. export default TimelineMenu