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 (3763B)


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