owntone-server/web-src/src/components/NavbarItemLink.vue

66 lines
1.3 KiB
Vue
Raw Normal View History

<template>
<a
class="navbar-item"
:class="{ 'is-active': is_active }"
:href="full_path()"
@click.stop.prevent="open_link()"
>
<slot />
</a>
</template>
<script>
import * as types from '@/store/mutation_types'
export default {
name: 'NavbarItemLink',
props: {
2023-12-14 10:43:22 +01:00
exact: Boolean,
2024-02-28 13:10:08 +01:00
to: { required: true, type: Object }
},
computed: {
is_active() {
if (this.exact) {
return this.$route.path === this.to
}
return this.$route.path.startsWith(this.to)
},
2023-12-14 10:43:22 +01:00
show_burger_menu: {
get() {
2023-12-14 10:43:22 +01:00
return this.$store.state.show_burger_menu
},
set(value) {
2023-12-14 10:43:22 +01:00
this.$store.commit(types.SHOW_BURGER_MENU, value)
}
},
2023-12-14 10:43:22 +01:00
show_player_menu: {
get() {
2023-12-14 10:43:22 +01:00
return this.$store.state.show_player_menu
},
set(value) {
2023-12-14 10:43:22 +01:00
this.$store.commit(types.SHOW_PLAYER_MENU, value)
}
}
},
methods: {
2023-12-14 10:43:22 +01:00
full_path() {
const resolved = this.$router.resolve(this.to)
return resolved.href
},
open_link() {
if (this.show_burger_menu) {
this.$store.commit(types.SHOW_BURGER_MENU, false)
}
if (this.show_player_menu) {
this.$store.commit(types.SHOW_PLAYER_MENU, false)
}
this.$router.push(this.to)
}
}
}
</script>