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

109 lines
3.5 KiB
JavaScript
Raw Normal View History

import Popover from '../popover/popover.vue'
2022-08-11 21:00:27 +03:00
import NavigationEntry from 'src/components/navigation/navigation_entry.vue'
2022-12-15 00:53:32 +02:00
import { mapState } from 'vuex'
2022-08-11 21:00:27 +03:00
import { ListsMenuContent } from '../lists_menu/lists_menu_content.vue'
import { BookmarkFoldersMenuContent } from '../bookmark_folders_menu/bookmark_folders_menu_content.vue'
import { library } from '@fortawesome/fontawesome-svg-core'
2022-08-11 21:00:27 +03:00
import { TIMELINES } from 'src/components/navigation/navigation.js'
2022-12-15 00:53:32 +02:00
import { filterNavigation } from 'src/components/navigation/filter.js'
import {
faChevronDown
} from '@fortawesome/free-solid-svg-icons'
2021-02-22 16:24:04 +02:00
library.add(faChevronDown)
2020-11-10 12:52:54 +02:00
// Route -> i18n key mapping, exported and not in the computed
// because nav panel benefits from the same information.
export const timelineNames = (supportsBookmarkFolders) => {
return {
2022-07-31 12:35:48 +03:00
friends: 'nav.home_timeline',
bookmarks: supportsBookmarkFolders ? 'nav.all_bookmarks' : 'nav.bookmarks',
2022-07-31 12:35:48 +03:00
dms: 'nav.dms',
'public-timeline': 'nav.public_tl',
'public-external-timeline': 'nav.twkn',
quotes: 'nav.quotes'
}
}
const TimelineMenu = {
components: {
2021-02-22 16:24:04 +02:00
Popover,
2022-08-11 21:00:27 +03:00
NavigationEntry,
ListsMenuContent,
BookmarkFoldersMenuContent
},
data () {
return {
2022-12-15 00:53:32 +02:00
isOpen: false
}
},
created () {
if (timelineNames(this.bookmarkFolders)[this.$route.name]) {
this.$store.dispatch('setLastTimeline', this.$route.name)
}
},
2022-08-11 21:00:27 +03:00
computed: {
useListsMenu () {
const route = this.$route.name
return route === 'lists-timeline'
2022-12-15 00:53:32 +02:00
},
useBookmarkFoldersMenu () {
const route = this.$route.name
return this.bookmarkFolders && (route === 'bookmark-folder' || route === 'bookmarks')
},
2022-12-15 00:53:32 +02:00
...mapState({
currentUser: state => state.users.currentUser,
privateMode: state => state.instance.private,
federating: state => state.instance.federating,
bookmarkFolders: state => state.instance.pleromaBookmarkFoldersAvailable
2022-12-15 00:53:32 +02:00
}),
timelinesList () {
return filterNavigation(
Object.entries(TIMELINES).map(([k, v]) => ({ ...v, name: k })),
{
hasChats: this.pleromaChatMessagesAvailable,
isFederating: this.federating,
isPrivate: this.privateMode,
currentUser: this.currentUser,
supportsBookmarkFolders: this.bookmarkFolders
2022-12-15 00:53:32 +02:00
}
)
2022-08-11 21:00:27 +03:00
}
},
methods: {
openMenu () {
// $nextTick is too fast, animation won't play back but
// instead starts in fully open position. Low values
// like 1-5 work on fast machines but not on mobile, 25
// seems like a good compromise that plays without significant
// added lag.
setTimeout(() => {
this.isOpen = true
}, 25)
},
2020-12-03 10:07:42 +02:00
blockOpen (event) {
// For the blank area inside the button element.
// Just setting @click.stop="" makes unintuitive behavior when
// menu is open and clicking on the blank area doesn't close it.
if (!this.isOpen) {
event.stopPropagation()
}
},
timelineName () {
const route = this.$route.name
if (route === 'tag-timeline') {
return '#' + this.$route.params.tag
}
if (route === 'lists-timeline') {
2022-08-06 17:26:43 +03:00
return this.$store.getters.findListTitle(this.$route.params.id)
}
if (route === 'bookmark-folder') {
return this.$store.getters.findBookmarkFolderName(this.$route.params.id)
}
const i18nkey = timelineNames(this.bookmarkFolders)[this.$route.name]
return i18nkey ? this.$t(i18nkey) : route
}
}
}
export default TimelineMenu