funkwhale/front/src/components/Sidebar.vue

739 wiersze
24 KiB
Vue
Czysty Zwykły widok Historia

<template>
2021-11-26 11:01:58 +00:00
<aside :class="['ui', 'vertical', 'left', 'visible', 'wide', {'collapsed': isCollapsed}, 'sidebar', 'component-sidebar']">
<header class="ui basic segment header-wrapper">
<router-link
:title="'Funkwhale'"
:to="{name: logoUrl}"
>
<i class="logo bordered inverted vibrant big icon">
<logo class="logo" />
<span class="visually-hidden">Home</span>
</i>
</router-link>
<nav class="top ui compact right aligned inverted text menu">
<div class="right menu">
2021-11-26 11:01:58 +00:00
<div
v-if="$store.state.auth.availablePermissions['settings'] || $store.state.auth.availablePermissions['moderation']"
class="item"
:title="labels.administration"
>
<div class="item ui inline admin-dropdown dropdown">
2021-11-26 11:01:58 +00:00
<i class="wrench icon" />
<div
2020-03-18 10:57:33 +00:00
v-if="moderationNotifications > 0"
2021-11-26 11:01:58 +00:00
:class="['ui', 'accent', 'mini', 'bottom floating', 'circular', 'label']"
>
{{ moderationNotifications }}
</div>
<div class="menu">
<h3 class="header">
2021-11-26 11:01:58 +00:00
<translate translate-context="Sidebar/Admin/Title/Noun">
Administration
</translate>
</h3>
2021-11-26 11:01:58 +00:00
<div class="divider" />
<router-link
v-if="$store.state.auth.availablePermissions['library']"
class="item"
2021-11-26 11:01:58 +00:00
:to="{name: 'manage.library.edits', query: {q: 'is_approved:null'}}"
>
<div
v-if="$store.state.ui.notifications.pendingReviewEdits > 0"
:title="labels.pendingReviewEdits"
2021-11-26 11:01:58 +00:00
:class="['ui', 'circular', 'mini', 'right floated', 'accent', 'label']"
>
{{ $store.state.ui.notifications.pendingReviewEdits }}
</div>
<translate translate-context="*/*/*/Noun">
Library
</translate>
</router-link>
<router-link
v-if="$store.state.auth.availablePermissions['moderation']"
class="item"
2021-11-26 11:01:58 +00:00
:to="{name: 'manage.moderation.reports.list', query: {q: 'resolved:no'}}"
>
<div
2020-03-18 10:57:33 +00:00
v-if="$store.state.ui.notifications.pendingReviewReports + $store.state.ui.notifications.pendingReviewRequests> 0"
:title="labels.pendingReviewReports"
2021-11-26 11:01:58 +00:00
:class="['ui', 'circular', 'mini', 'right floated', 'accent', 'label']"
>
{{ $store.state.ui.notifications.pendingReviewReports + $store.state.ui.notifications.pendingReviewRequests }}
</div>
<translate translate-context="*/Moderation/*">
Moderation
</translate>
</router-link>
<router-link
v-if="$store.state.auth.availablePermissions['settings']"
class="item"
2021-11-26 11:01:58 +00:00
:to="{name: 'manage.users.users.list'}"
>
<translate translate-context="*/*/*/Noun">
Users
</translate>
</router-link>
<router-link
v-if="$store.state.auth.availablePermissions['settings']"
class="item"
2021-11-26 11:01:58 +00:00
:to="{path: '/manage/settings'}"
>
<translate translate-context="*/*/*/Noun">
Settings
</translate>
</router-link>
</div>
</div>
</div>
</div>
<router-link
v-if="$store.state.auth.authenticated"
2021-11-26 11:01:58 +00:00
class="item"
:to="{name: 'content.index'}"
>
<i class="upload icon" />
<span class="visually-hidden">{{ labels.addContent }}</span>
2020-08-01 09:11:51 +00:00
</router-link>
2021-11-26 11:01:58 +00:00
<template v-if="width > 768">
<div class="item">
<div class="ui user-dropdown dropdown">
<img
v-if="$store.state.auth.authenticated && $store.state.auth.profile.avatar && $store.state.auth.profile.avatar.urls.medium_square_crop"
class="ui avatar image"
alt=""
:src="$store.getters['instance/absoluteUrl']($store.state.auth.profile.avatar.urls.medium_square_crop)"
>
<actor-avatar
v-else-if="$store.state.auth.authenticated"
:actor="{preferred_username: $store.state.auth.username, full_username: $store.state.auth.username,}"
/>
<i
v-else
class="cog icon"
/>
<div
v-if="$store.state.ui.notifications.inbox + additionalNotifications > 0"
:class="['ui', 'accent', 'mini', 'bottom floating', 'circular', 'label']"
>
{{ $store.state.ui.notifications.inbox + additionalNotifications }}
</div>
<user-menu
:width="width"
v-on="$listeners"
/>
</div>
2020-08-01 09:11:51 +00:00
</div>
2021-11-26 11:01:58 +00:00
</template>
<template v-else>
<a
href=""
class="item"
@click.prevent.exact="showUserModal = !showUserModal"
>
<img
v-if="$store.state.auth.authenticated && $store.state.auth.profile.avatar && $store.state.auth.profile.avatar.urls.medium_square_crop"
class="ui avatar image"
alt=""
:src="$store.getters['instance/absoluteUrl']($store.state.auth.profile.avatar.urls.medium_square_crop)"
>
<actor-avatar
v-else-if="$store.state.auth.authenticated"
:actor="{preferred_username: $store.state.auth.username, full_username: $store.state.auth.username,}"
/>
<i
v-else
class="cog icon"
/>
<div
v-if="$store.state.ui.notifications.inbox + additionalNotifications > 0"
:class="['ui', 'accent', 'mini', 'bottom floating', 'circular', 'label']"
>
{{ $store.state.ui.notifications.inbox + additionalNotifications }}
</div>
2021-11-26 11:01:58 +00:00
</a>
</template>
<user-modal
:show="showUserModal"
@showThemeModalEvent="showThemeModal=true"
@showLanguageModalEvent="showLanguageModal=true"
@update:show="showUserModal = $event"
/>
<modal
ref="languageModal"
:fullscreen="false"
:show="showLanguageModal"
@update:show="showLanguageModal = $event"
>
<i
role="button"
class="left chevron back inside icon"
@click.prevent.exact="showUserModal = !showUserModal"
/>
<div class="header">
<h3 class="title">
{{ labels.language }}
</h3>
</div>
2021-11-26 11:01:58 +00:00
<div class="content">
<fieldset
v-for="(language, key) in $language.available"
:key="key"
>
<input
:id="key"
v-model="languageSelection"
type="radio"
name="language"
:value="key"
>
<label :for="key">{{ language }}</label>
</fieldset>
2018-04-28 12:58:25 +00:00
</div>
2021-11-26 11:01:58 +00:00
</modal>
<modal
ref="themeModal"
:fullscreen="false"
:show="showThemeModal"
@update:show="showThemeModal = $event"
>
<i
role="button"
class="left chevron back inside icon"
@click.prevent.exact="showUserModal = !showUserModal"
/>
<div class="header">
<h3 class="title">
{{ labels.theme }}
</h3>
2018-04-28 12:58:25 +00:00
</div>
2021-11-26 11:01:58 +00:00
<div class="content">
<fieldset
v-for="theme in themes"
:key="theme.key"
>
<input
:id="theme.key"
v-model="themeSelection"
type="radio"
name="theme"
:value="theme.key"
>
<label :for="theme.key">{{ theme.name }}</label>
</fieldset>
2018-04-28 12:58:25 +00:00
</div>
2021-11-26 11:01:58 +00:00
</modal>
<div class="item collapse-button-wrapper">
<button
:class="['ui', 'basic', 'big', {'vibrant': !isCollapsed}, 'inverted icon', 'collapse', 'button']"
@click="isCollapsed = !isCollapsed"
>
<i class="sidebar icon" />
</button>
2018-04-28 12:58:25 +00:00
</div>
</nav>
2021-11-26 11:01:58 +00:00
</header>
<div class="ui basic search-wrapper segment">
<search-bar @search="isCollapsed = false" />
</div>
<div
v-if="!$store.state.auth.authenticated"
class="ui basic signup segment"
>
<router-link
class="ui fluid tiny primary button"
:to="{name: 'login'}"
>
<translate translate-context="*/Login/*/Verb">
Login
</translate>
</router-link>
<div class="ui small hidden divider" />
<router-link
class="ui fluid tiny button"
:to="{path: '/signup'}"
>
<translate translate-context="*/Signup/Link/Verb">
Create an account
</translate>
</router-link>
</div>
<nav
class="secondary"
role="navigation"
aria-labelledby="navigation-label"
>
<h1
id="navigation-label"
class="visually-hidden"
>
<translate translate-context="*/*/*">
Main navigation
</translate>
</h1>
<div class="ui small hidden divider" />
<section
:class="['ui', 'bottom', 'attached', {active: selectedTab === 'library'}, 'tab']"
:aria-label="labels.mainMenu"
>
<nav
class="ui vertical large fluid inverted menu"
role="navigation"
:aria-label="labels.mainMenu"
>
<div :class="[{collapsed: !exploreExpanded}, 'collapsible item']">
<h2
class="header"
role="button"
tabindex="0"
@click="exploreExpanded = true"
@focus="exploreExpanded = true"
>
<translate translate-context="*/*/*/Verb">
Explore
</translate>
<i
v-if="!exploreExpanded"
class="angle right icon"
/>
</h2>
<div class="menu">
<router-link
class="item"
:to="{name: 'search'}"
>
<i class="search icon" /><translate translate-context="Sidebar/Navigation/List item.Link/Verb">
Search
</translate>
</router-link>
<router-link
class="item"
:exact="true"
:to="{name: 'library.index'}"
>
<i class="music icon" /><translate translate-context="Sidebar/Navigation/List item.Link/Verb">
Browse
</translate>
</router-link>
<router-link
class="item"
:to="{name: 'library.podcasts.browse'}"
>
<i class="podcast icon" /><translate translate-context="*/*/*">
Podcasts
</translate>
</router-link>
<router-link
class="item"
:to="{name: 'library.albums.browse'}"
>
<i class="compact disc icon" /><translate translate-context="*/*/*">
Albums
</translate>
</router-link>
<router-link
class="item"
:to="{name: 'library.artists.browse'}"
>
<i class="user icon" /><translate translate-context="*/*/*">
Artists
</translate>
</router-link>
<router-link
class="item"
:to="{name: 'library.playlists.browse'}"
>
<i class="list icon" /><translate translate-context="*/*/*">
Playlists
</translate>
</router-link>
<router-link
class="item"
:to="{name: 'library.radios.browse'}"
>
<i class="feed icon" /><translate translate-context="*/*/*">
Radios
</translate>
</router-link>
</div>
</div>
<div
v-if="$store.state.auth.authenticated"
:class="[{collapsed: !myLibraryExpanded}, 'collapsible item']"
>
<h3
class="header"
role="button"
tabindex="0"
@click="myLibraryExpanded = true"
@focus="myLibraryExpanded = true"
>
<translate translate-context="*/*/*/Noun">
My Library
</translate>
<i
v-if="!myLibraryExpanded"
class="angle right icon"
/>
</h3>
<div class="menu">
<router-link
class="item"
:exact="true"
:to="{name: 'library.me'}"
>
<i class="music icon" /><translate translate-context="Sidebar/Navigation/List item.Link/Verb">
Browse
</translate>
</router-link>
<router-link
class="item"
:to="{name: 'library.albums.me'}"
>
<i class="compact disc icon" /><translate translate-context="*/*/*">
Albums
</translate>
</router-link>
<router-link
class="item"
:to="{name: 'library.artists.me'}"
>
<i class="user icon" /><translate translate-context="*/*/*">
Artists
</translate>
</router-link>
<router-link
class="item"
:to="{name: 'library.playlists.me'}"
>
<i class="list icon" /><translate translate-context="*/*/*">
Playlists
</translate>
</router-link>
<router-link
class="item"
:to="{name: 'library.radios.me'}"
>
<i class="feed icon" /><translate translate-context="*/*/*">
Radios
</translate>
</router-link>
<router-link
class="item"
:to="{name: 'favorites'}"
>
<i class="heart icon" /><translate translate-context="Sidebar/Favorites/List item.Link/Noun">
Favorites
</translate>
</router-link>
</div>
</div>
<router-link
v-if="$store.state.auth.authenticated"
class="header item"
:to="{name: 'subscriptions'}"
>
<translate translate-context="*/*/*">
Channels
</translate>
</router-link>
<div class="item">
<h3 class="header">
<translate translate-context="Footer/About/List item.Link">
More
</translate>
</h3>
<div class="menu">
<router-link
class="item"
to="/about"
>
<i class="info icon" /><translate translate-context="Sidebar/*/List item.Link">
About this pod
</translate>
</router-link>
</div>
</div>
<div
v-if="!production"
class="item"
>
<a
role="button"
href=""
class="link item"
@click.prevent="$emit('show:set-instance-modal')"
>Switch instance</a>
</div>
</nav>
</section>
</nav>
</aside>
</template>
<script>
2021-11-26 11:01:58 +00:00
import { mapState, mapActions, mapGetters } from 'vuex'
2022-02-21 14:07:07 +00:00
import UserModal from '@/components/common/UserModal.vue'
import Logo from '@/components/Logo.vue'
import SearchBar from '@/components/audio/SearchBar.vue'
import ThemesMixin from '@/components/mixins/Themes.vue'
import UserMenu from '@/components/common/UserMenu.vue'
import Modal from '@/components/semantic/Modal.vue'
2021-11-26 11:01:58 +00:00
import $ from 'jquery'
export default {
2021-11-26 11:01:58 +00:00
name: 'Sidebar',
components: {
SearchBar,
2021-11-26 11:01:58 +00:00
Logo,
UserMenu,
UserModal,
Modal
},
mixins: [ThemesMixin],
2021-11-26 11:01:58 +00:00
props: {
width: { type: Number, required: true }
},
2021-11-26 11:01:58 +00:00
data () {
return {
2021-11-26 11:01:58 +00:00
selectedTab: 'library',
isCollapsed: true,
fetchInterval: null,
exploreExpanded: false,
myLibraryExpanded: false,
2021-11-26 11:01:58 +00:00
showUserModal: false,
showLanguageModal: false,
showThemeModal: false,
languageSelection: this.$language.current,
themeSelection: this.$store.state.ui.theme
}
},
2021-11-26 11:01:58 +00:00
destroy () {
if (this.fetchInterval) {
clearInterval(this.fetchInterval)
}
},
computed: {
...mapState({
queue: state => state.queue,
url: state => state.route.path
}),
2021-11-26 11:01:58 +00:00
...mapGetters({
additionalNotifications: 'ui/additionalNotifications'
}),
labels () {
const mainMenu = this.$pgettext('Sidebar/*/Hidden text', 'Main menu')
const selectTrack = this.$pgettext('Sidebar/Player/Hidden text', 'Play this track')
const pendingFollows = this.$pgettext('Sidebar/Notifications/Hidden text', 'Pending follow requests')
const pendingReviewEdits = this.$pgettext('Sidebar/Moderation/Hidden text', 'Pending review edits')
const language = this.$pgettext(
'Sidebar/Settings/Dropdown.Label/Short, Verb',
'Language')
const theme = this.$pgettext(
'Sidebar/Settings/Dropdown.Label/Short, Verb',
'Theme')
2018-07-01 19:50:50 +00:00
return {
pendingFollows,
mainMenu,
selectTrack,
pendingReviewEdits,
2021-11-26 11:01:58 +00:00
language,
theme,
addContent: this.$pgettext('*/Library/*/Verb', 'Add content'),
administration: this.$pgettext('Sidebar/Admin/Title/Noun', 'Administration')
}
2018-07-17 11:09:13 +00:00
},
2021-11-26 11:01:58 +00:00
logoUrl () {
2018-07-17 11:09:13 +00:00
if (this.$store.state.auth.authenticated) {
2021-11-26 11:01:58 +00:00
return 'library.index'
2018-07-17 11:09:13 +00:00
} else {
2021-11-26 11:01:58 +00:00
return 'index'
2018-07-17 11:09:13 +00:00
}
},
focusedMenu () {
2021-11-26 11:01:58 +00:00
const mapping = {
search: 'exploreExpanded',
'library.index': 'exploreExpanded',
'library.podcasts.browse': 'exploreExpanded',
'library.albums.browse': 'exploreExpanded',
'library.albums.detail': 'exploreExpanded',
'library.artists.browse': 'exploreExpanded',
'library.artists.detail': 'exploreExpanded',
'library.tracks.detail': 'exploreExpanded',
'library.playlists.browse': 'exploreExpanded',
'library.playlists.detail': 'exploreExpanded',
'library.radios.browse': 'exploreExpanded',
'library.radios.detail': 'exploreExpanded',
'library.me': 'myLibraryExpanded',
'library.albums.me': 'myLibraryExpanded',
'library.artists.me': 'myLibraryExpanded',
'library.playlists.me': 'myLibraryExpanded',
'library.radios.me': 'myLibraryExpanded',
favorites: 'myLibraryExpanded'
}
2021-11-26 11:01:58 +00:00
const m = mapping[this.$route.name]
if (m) {
return m
}
if (this.$store.state.auth.authenticated) {
return 'myLibraryExpanded'
} else {
return 'exploreExpanded'
}
2020-03-18 10:57:33 +00:00
},
moderationNotifications () {
return (
this.$store.state.ui.notifications.pendingReviewEdits +
this.$store.state.ui.notifications.pendingReviewReports +
this.$store.state.ui.notifications.pendingReviewRequests
)
},
2021-11-26 11:01:58 +00:00
production () {
2022-02-24 10:52:34 +00:00
return import.meta.env.PROD
}
},
watch: {
2021-11-26 11:01:58 +00:00
url: function () {
this.isCollapsed = true
},
2021-11-26 11:01:58 +00:00
'$store.state.moderation.lastUpdate': function () {
this.applyContentFilters()
},
2021-11-26 11:01:58 +00:00
'$store.state.auth.authenticated': {
immediate: true,
handler (v) {
if (v) {
this.$nextTick(() => {
this.setupDropdown('.user-dropdown')
this.setupDropdown('.admin-dropdown')
})
2021-11-26 11:01:58 +00:00
} else {
this.$nextTick(() => {
this.setupDropdown('.user-dropdown')
})
}
}
},
2021-11-26 11:01:58 +00:00
'$store.state.auth.availablePermissions': {
immediate: true,
handler (v) {
this.$nextTick(() => {
this.setupDropdown('.admin-dropdown')
})
},
2021-11-26 11:01:58 +00:00
deep: true
},
focusedMenu: {
immediate: true,
handler (n) {
if (n) {
this[n] = true
}
}
},
myLibraryExpanded (v) {
if (v) {
this.exploreExpanded = false
}
},
exploreExpanded (v) {
if (v) {
this.myLibraryExpanded = false
}
2019-02-14 09:49:06 +00:00
},
2021-11-26 11:01:58 +00:00
languageSelection: function (v) {
this.$store.dispatch('ui/currentLanguage', v)
this.$refs.languageModal.closeModal()
},
themeSelection: function (v) {
this.$store.dispatch('ui/theme', v)
this.$refs.themeModal.closeModal()
}
},
mounted () {
this.$nextTick(() => {
document.getElementById('fake-sidebar').classList.add('loaded')
})
},
methods: {
...mapActions({
cleanTrack: 'queue/cleanTrack'
}),
applyContentFilters () {
const artistIds = this.$store.getters['moderation/artistFilters']().map((f) => {
return f.target.id
})
if (artistIds.length === 0) {
return
}
const self = this
const tracks = this.tracks.slice().reverse()
tracks.forEach(async (t, i) => {
// we loop from the end because removing index from the start can lead to removing the wrong tracks
const realIndex = tracks.length - i - 1
const matchArtist = artistIds.indexOf(t.artist.id) > -1
if (matchArtist) {
return await self.cleanTrack(realIndex)
}
if (t.album && artistIds.indexOf(t.album.artist.id) > -1) {
return await self.cleanTrack(realIndex)
}
})
},
setupDropdown (selector) {
const self = this
$(self.$el).find(selector).dropdown({
selectOnKeydown: false,
action: function (text, value, $el) {
// used ton ensure focusing the dropdown and clicking via keyboard
// works as expected
const link = $($el).closest('a')
const url = link.attr('href')
if (url.startsWith('http')) {
window.open(url, '_blank').focus()
} else {
self.$router.push(url)
}
2021-11-26 11:01:58 +00:00
$(self.$el).find(selector).dropdown('hide')
}
})
}
}
}
</script>
2021-11-26 11:01:58 +00:00
<style>
[type="radio"] {
position: absolute;
opacity: 0;
cursor: pointer;
height: 0;
width: 0;
}
[type="radio"] + label::after {
content: "";
font-size: 1.4em;
}
[type="radio"]:checked + label::after {
margin-left: 10px;
content: "\2713"; /* Checkmark */
font-size: 1.4em;
}
[type="radio"]:checked + label {
font-weight: bold;
}
fieldset {
border: none;
}
.back {
font-size: 1.25em !important;
position: absolute;
top: 0.5rem;
left: 0.5rem;
width: 2.25rem !important;
height: 2.25rem !important;
padding: 0.625rem 0 0 0;
}
</style>