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

127 lines
4.1 KiB
JavaScript
Raw Normal View History

2026-01-29 20:33:59 +02:00
import { mapState as mapPiniaState } from 'pinia'
2026-01-08 17:26:52 +02:00
import { mapState } from 'vuex'
2026-01-06 16:23:17 +02:00
import { filterNavigation } from 'src/components/navigation/filter.js'
import { TIMELINES } from 'src/components/navigation/navigation.js'
import NavigationEntry from 'src/components/navigation/navigation_entry.vue'
2026-01-29 20:40:00 +02:00
import BookmarkFoldersMenuContent from '../bookmark_folders_menu/bookmark_folders_menu_content.vue'
import ListsMenuContent from '../lists_menu/lists_menu_content.vue'
import Popover from '../popover/popover.vue'
2026-01-06 16:23:17 +02:00
import { useBookmarkFoldersStore } from 'src/stores/bookmark_folders'
import { useInstanceStore } from 'src/stores/instance.js'
2025-02-03 13:02:14 +02:00
import { useInterfaceStore } from 'src/stores/interface'
import { useListsStore } from 'src/stores/lists'
2026-01-08 17:26:52 +02:00
import { library } from '@fortawesome/fontawesome-svg-core'
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',
2025-06-18 17:48:11 +03:00
quotes: 'nav.quotes',
2026-01-06 16:22:52 +02:00
bubble: 'nav.bubble',
}
}
const TimelineMenu = {
components: {
2021-02-22 16:24:04 +02:00
Popover,
2022-08-11 21:00:27 +03:00
NavigationEntry,
ListsMenuContent,
2026-01-06 16:22:52 +02:00
BookmarkFoldersMenuContent,
},
2026-01-06 16:22:52 +02:00
data() {
return {
2026-01-06 16:22:52 +02:00
isOpen: false,
}
},
2026-01-06 16:22:52 +02:00
created() {
if (timelineNames(this.bookmarkFolders)[this.$route.name]) {
2023-04-05 21:06:37 -06:00
useInterfaceStore().setLastTimeline(this.$route.name)
}
},
2022-08-11 21:00:27 +03:00
computed: {
2026-01-06 16:22:52 +02:00
useListsMenu() {
2022-08-11 21:00:27 +03:00
const route = this.$route.name
return route === 'lists-timeline'
2022-12-15 00:53:32 +02:00
},
2026-01-06 16:22:52 +02:00
useBookmarkFoldersMenu() {
const route = this.$route.name
2026-01-06 16:22:52 +02:00
return (
this.bookmarkFolders &&
(route === 'bookmark-folder' || route === 'bookmarks')
)
},
2026-01-29 20:33:59 +02:00
...mapPiniaState(useInstanceStore, ['private', 'federating']),
...mapPiniaState(useInstanceStore, {
pleromaChatMessagesAvailable: (store) =>
store.featureSet.pleromaChatMessagesAvailable,
bookmarkFolders: (store) =>
store.featureSet.pleromaBookmarkFoldersAvailable,
bubbleTimeline: (store) => store.featureSet.localBubble,
}),
2022-12-15 00:53:32 +02:00
...mapState({
2026-01-06 16:22:52 +02:00
currentUser: (state) => state.users.currentUser,
2022-12-15 00:53:32 +02:00
}),
2026-01-06 16:22:52 +02:00
timelinesList() {
2022-12-15 00:53:32 +02:00
return filterNavigation(
Object.entries(TIMELINES).map(([k, v]) => ({ ...v, name: k })),
{
hasChats: this.pleromaChatMessagesAvailable,
isFederating: this.federating,
2026-01-29 20:33:59 +02:00
isPrivate: this.private,
currentUser: this.currentUser,
2025-06-18 17:48:11 +03:00
supportsBookmarkFolders: this.bookmarkFolders,
2026-01-06 16:22:52 +02:00
supportsBubbleTimeline: this.bubbleTimeline,
},
2022-12-15 00:53:32 +02:00
)
2026-01-06 16:22:52 +02:00
},
2022-08-11 21:00:27 +03:00
},
methods: {
2026-01-06 16:22:52 +02:00
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)
},
2026-01-06 16:22:52 +02:00
blockOpen(event) {
2020-12-03 10:07:42 +02:00
// 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()
}
},
2026-01-06 16:22:52 +02:00
timelineName() {
const route = this.$route.name
if (route === 'tag-timeline') {
return '#' + this.$route.params.tag
}
if (route === 'lists-timeline') {
2023-04-06 22:13:30 -06:00
return useListsStore().findListTitle(this.$route.params.id)
2022-08-06 17:26:43 +03:00
}
if (route === 'bookmark-folder') {
2026-01-06 16:22:52 +02:00
return useBookmarkFoldersStore().findBookmarkFolderName(
this.$route.params.id,
)
}
const i18nkey = timelineNames(this.bookmarkFolders)[this.$route.name]
return i18nkey ? this.$t(i18nkey) : route
2026-01-06 16:22:52 +02:00
},
},
}
export default TimelineMenu