fix links not being active by default

This commit is contained in:
Henry Jameson 2022-08-23 15:36:54 +03:00
parent 63f35509a7
commit bd7356376e
4 changed files with 43 additions and 2 deletions

View File

@ -4,6 +4,15 @@ import { faThumbtack } from '@fortawesome/free-solid-svg-icons'
library.add(faThumbtack) library.add(faThumbtack)
const USERNAME_ROUTES = new Set([
'bookmarks',
'dms',
'interactions',
'notifications',
'chat',
'chats'
])
const NavigationEntry = { const NavigationEntry = {
props: ['item', 'showPin'], props: ['item', 'showPin'],
methods: { methods: {
@ -20,6 +29,16 @@ const NavigationEntry = {
} }
}, },
computed: { computed: {
routeTo () {
if (this.item.routeObject) {
return this.item.routeObject
}
const route = { name: (this.item.anon || this.currentUser) ? this.item.route : this.item.anonRoute }
if (USERNAME_ROUTES.has(route.name)) {
route.params = { username: this.currentUser.screen_name }
}
return route
},
getters () { getters () {
return this.$store.getters return this.$store.getters
}, },

View File

@ -2,7 +2,7 @@
<li class="NavigationEntry"> <li class="NavigationEntry">
<router-link <router-link
class="menu-item" class="menu-item"
:to="item.routeObject || { name: (currentUser || item.anon) ? item.route : item.anonRoute, params: { username: currentUser.screen_name } }" :to="routeTo"
> >
<FAIcon <FAIcon
v-if="item.icon" v-if="item.icon"

View File

@ -26,8 +26,30 @@ library.add(
faStream, faStream,
faList faList
) )
const USERNAME_ROUTES = new Set([
'bookmarks',
'dms',
'interactions',
'notifications',
'chat',
'chats'
])
const NavPanel = { const NavPanel = {
props: ['limit'], props: ['limit'],
methods: {
getRouteTo (item) {
if (item.routeObject) {
return item.routeObject
}
const route = { name: (item.anon || this.currentUser) ? item.route : item.anonRoute }
if (USERNAME_ROUTES.has(route.name)) {
route.params = { username: this.currentUser.screen_name }
}
return route
}
},
computed: { computed: {
getters () { getters () {
return this.$store.getters return this.$store.getters

View File

@ -4,7 +4,7 @@
v-for="item in pinnedList" v-for="item in pinnedList"
:key="item.name" :key="item.name"
class="pinned-item" class="pinned-item"
:to="item.routeObject || { name: (currentUser || item.anon) ? item.route : item.anonRoute, params: { username: currentUser.screen_name } }" :to="getRouteTo(item)"
> >
<FAIcon <FAIcon
v-if="item.icon" v-if="item.icon"