Newer
Older
Eliot Berriot
committed
<template>
<aside :class="['ui', 'vertical', 'left', 'visible', 'wide', {'collapsed': isCollapsed}, 'sidebar',]">
<header class="ui inverted segment header-wrapper">
<search-bar @search="isCollapsed = false">
<router-link :title="'Funkwhale'" :to="{name: logoUrl}">
Eliot Berriot
committed
<i class="logo bordered inverted orange big icon">
<logo class="logo"></logo>
</i>
slot="after"
@click="isCollapsed = !isCollapsed"
:class="['ui', 'basic', 'big', {'inverted': isCollapsed}, 'orange', 'icon', 'collapse', 'button']">
<i class="sidebar icon"></i></span>
Eliot Berriot
committed
</search-bar>
</header>
Eliot Berriot
committed
<div class="menu-area">
<div class="ui compact fluid two item inverted menu">
<a :class="[{active: selectedTab === 'library'}, 'item']" role="button" @click.prevent.stop="selectedTab = 'library'" data-tab="library"><translate>Browse</translate></a>
<a :class="[{active: selectedTab === 'queue'}, 'item']" role="button" @click.prevent.stop="selectedTab = 'queue'" data-tab="queue">
<translate>Queue</translate>
Eliot Berriot
committed
<template v-if="queue.tracks.length === 0">
<translate>(empty)</translate>
Eliot Berriot
committed
</template>
<translate v-else :translate-params="{index: queue.currentIndex + 1, length: queue.tracks.length}">
(%{ index } of %{ length })
</translate>
Eliot Berriot
committed
</a>
</div>
</div>
<div class="tabs">
<section :class="['ui', 'bottom', 'attached', {active: selectedTab === 'library'}, 'tab']" :aria-label="labels.mainMenu">
<nav class="ui inverted vertical large fluid menu" role="navigation" :aria-label="labels.mainMenu">
<header class="header"><translate>My account</translate></header>
<router-link class="item" v-if="$store.state.auth.authenticated" :to="{name: 'profile', params: {username: $store.state.auth.username}}">
<i class="user icon"></i>
<translate :translate-params="{username: $store.state.auth.username}">
Logged in as %{ username }
</translate>
<img class="ui right floated circular tiny avatar image" v-if="$store.state.auth.profile.avatar.square_crop" :src="$store.getters['instance/absoluteUrl']($store.state.auth.profile.avatar.square_crop)" />
<router-link class="item" v-if="$store.state.auth.authenticated" :to="{path: '/settings'}"><i class="setting icon"></i><translate>Settings</translate></router-link>
<router-link class="item" v-if="$store.state.auth.authenticated" :to="{name: 'notifications'}">
<i class="feed icon"></i>
<translate>Notifications</translate>
<div
v-if="$store.state.ui.notifications.inbox > 0"
:class="['ui', 'teal', 'label']">
{{ $store.state.ui.notifications.inbox }}</div>
</router-link>
<router-link class="item" v-if="$store.state.auth.authenticated" :to="{name: 'logout'}"><i class="sign out icon"></i><translate>Logout</translate></router-link>
<template v-else>
<router-link class="item" :to="{name: 'login'}"><i class="sign in icon"></i><translate>Login</translate></router-link>
<router-link class="item" :to="{path: '/signup'}">
<translate>Create an account</translate>
</router-link>
</template>
<header class="header"><translate>Music</translate></header>
<router-link class="item" :to="{path: '/library'}"><i class="sound icon"></i><translate>Browse library</translate></router-link>
<router-link class="item" v-if="$store.state.auth.authenticated" :to="{path: '/favorites'}"><i class="heart icon"></i><translate>Favorites</translate></router-link>
<a
@click="$store.commit('playlists/chooseTrack', null)"
v-if="$store.state.auth.authenticated"
class="item">
<i class="list icon"></i><translate>Playlists</translate>
<router-link
v-if="$store.state.auth.authenticated"
class="item" :to="{name: 'content.index'}"><i class="upload icon"></i><translate>Add content</translate></router-link>
Eliot Berriot
committed
<div class="item" v-if="$store.state.auth.availablePermissions['settings']">
<header class="header"><translate>Administration</translate></header>
<router-link
class="item"
:to="{path: '/manage/settings'}">
<i class="settings icon"></i><translate>Settings</translate>
:to="{name: 'manage.users.users.list'}">
<i class="users icon"></i><translate>Users</translate>
</nav>
</section>
Eliot Berriot
committed
<div v-if="queue.previousQueue " class="ui black icon message">
<i class="history icon"></i>
<div class="content">
<div class="header">
<translate>Do you want to restore your previous queue?</translate>
Eliot Berriot
committed
</div>
<p>
<translate
translate-plural="%{ count } tracks"
:translate-n="queue.previousQueue.tracks.length"
:translate-params="{count: queue.previousQueue.tracks.length}">
%{ count } track
</translate>
</p>
Eliot Berriot
committed
<div class="ui two buttons">
<div @click="queue.restore()" class="ui basic inverted green button"><translate>Yes</translate></div>
<div @click="queue.removePrevious()" class="ui basic inverted red button"><translate>No</translate></div>
Eliot Berriot
committed
</div>
</div>
</div>
<section :class="['ui', 'bottom', 'attached', {active: selectedTab === 'queue'}, 'tab']">
<table class="ui compact inverted very basic fixed single line unstackable table">
Eliot Berriot
committed
<draggable v-model="tracks" element="tbody" @update="reorder">
<tr
@click="$store.dispatch('queue/currentIndex', index)"
v-for="(track, index) in tracks"
:key="index"
:class="[{'active': index === queue.currentIndex}]">
<td class="right aligned">{{ index + 1}}</td>
<td class="center aligned">
<img class="ui mini image" v-if="track.album.cover && track.album.cover.original" :src="$store.getters['instance/absoluteUrl'](track.album.cover.small_square_crop)">
<img class="ui mini image" v-else src="../assets/audio/default-cover.png">
</td>
<td colspan="4">
<button class="title reset ellipsis" :aria-label="labels.selectTrack">
Eliot Berriot
committed
<strong>{{ track.title }}</strong><br />
{{ track.artist.name }}
</button>
</td>
<td>
<template v-if="$store.getters['favorites/isFavorite'](track.id)">
<i class="pink heart icon"></i>
</td>
<td>
<button :title="labels.removeFromQueue" @click.stop="cleanTrack(index)" :class="['ui', {'inverted': index != queue.currentIndex}, 'really', 'tiny', 'basic', 'circular', 'icon', 'button']">
Eliot Berriot
committed
<i class="trash icon"></i>
</button>
</td>
</tr>
</draggable>
Eliot Berriot
committed
</table>
<div v-if="$store.state.radios.running" class="ui black message">
Eliot Berriot
committed
<div class="content">
<div class="header">
<i class="feed icon"></i> <translate>You have a radio playing</translate>
Eliot Berriot
committed
</div>
<p><translate>New tracks will be appended here automatically.</translate></p>
<div @click="$store.dispatch('radios/stop')" class="ui basic inverted red button"><translate>Stop radio</translate></div>
Eliot Berriot
committed
</div>
</div>
</section>
Eliot Berriot
committed
</div>
<player @next="scrollToCurrent" @previous="scrollToCurrent"></player>
</aside>
Eliot Berriot
committed
</template>
<script>
import { mapState, mapActions } from "vuex"
import Player from "@/components/audio/Player"
import Logo from "@/components/Logo"
import SearchBar from "@/components/audio/SearchBar"
import backend from "@/audio/backend"
import draggable from "vuedraggable"
Eliot Berriot
committed
import $ from "jquery"
Eliot Berriot
committed
export default {
name: "sidebar",
Eliot Berriot
committed
components: {
Player,
SearchBar,
Eliot Berriot
committed
},
data() {
Eliot Berriot
committed
return {
selectedTab: "library",
backend: backend,
Eliot Berriot
committed
tracksChangeBuffer: null,
isCollapsed: true,
fetchInterval: null
Eliot Berriot
committed
}
},
destroy() {
if (this.fetchInterval) {
clearInterval(this.fetchInterval)
}
},
computed: {
...mapState({
queue: state => state.queue,
url: state => state.route.path
labels() {
let mainMenu = this.$gettext("Main menu")
let selectTrack = this.$gettext("Play this track")
let pendingFollows = this.$gettext("Pending follow requests")
pendingFollows,
mainMenu,
selectTrack
Eliot Berriot
committed
tracks: {
get() {
Eliot Berriot
committed
return this.$store.state.queue.tracks
},
set(value) {
Eliot Berriot
committed
this.tracksChangeBuffer = value
}
logoUrl() {
if (this.$store.state.auth.authenticated) {
return "library.index"
return "index"
methods: {
cleanTrack: "queue/cleanTrack"
reorder: function(event) {
this.$store.commit("queue/reorder", {
tracks: this.tracksChangeBuffer,
oldIndex: event.oldIndex,
newIndex: event.newIndex
})
Eliot Berriot
committed
},
scrollToCurrent() {
Eliot Berriot
committed
let current = $(this.$el).find('[data-tab="queue"] .active')[0]
if (!current) {
return
}
let container = $(this.$el).find(".tabs")[0]
Eliot Berriot
committed
// Position container at the top line then scroll current into view
container.scrollTop = 0
current.scrollIntoView(true)
// Scroll back nothing if element is at bottom of container else do it
// for half the height of the containers display area
var scrollBack =
container.scrollHeight - container.scrollTop <= container.clientHeight
? 0
: container.clientHeight / 2
Eliot Berriot
committed
container.scrollTop = container.scrollTop - scrollBack
},
watch: {
url: function() {
this.isCollapsed = true
Eliot Berriot
committed
},
selectedTab: function(newValue) {
if (newValue === "queue") {
Eliot Berriot
committed
this.scrollToCurrent()
}
},
"$store.state.queue.currentIndex": function() {
if (this.selectedTab !== "queue") {
Eliot Berriot
committed
this.scrollToCurrent()
}
}
Eliot Berriot
committed
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
@import "../style/vendor/media";
Eliot Berriot
committed
$sidebar-color: #3d3e3f;
Eliot Berriot
committed
.sidebar {
background: $sidebar-color;
@include media(">tablet") {
display: flex;
flex-direction: column;
justify-content: space-between;
}
@include media(">desktop") {
.collapse.button {
display: none !important;
}
}
@include media("<desktop") {
position: static !important;
width: 100% !important;
&.collapsed {
.menu-area,
.player-wrapper,
.tabs {
display: none;
}
}
}
Eliot Berriot
committed
> div {
margin: 0;
background-color: $sidebar-color;
}
.menu.vertical {
background: $sidebar-color;
Eliot Berriot
committed
}
}
.menu-area {
.menu .item:not(.active):not(:hover) {
Eliot Berriot
committed
}
.menu .item {
border-radius: 0;
}
.menu .item.active {
background-color: $sidebar-color;
&:hover {
background-color: rgba(255, 255, 255, 0.06);
Eliot Berriot
committed
}
.vertical.menu {
.item .item {
font-size: 1em;
> i.icon {
float: none;
margin: 0 0.5em 0 0;
}
&:not(.active) {
color: rgba(255, 255, 255, 0.75);
}
Eliot Berriot
committed
.tabs {
Eliot Berriot
committed
flex: 1;
display: flex;
flex-direction: column;
Eliot Berriot
committed
overflow-y: auto;
Eliot Berriot
committed
justify-content: space-between;
@include media("<desktop") {
Eliot Berriot
committed
max-height: 500px;
Eliot Berriot
committed
}
Eliot Berriot
committed
.ui.tab.active {
display: flex;
}
Eliot Berriot
committed
.tab[data-tab="queue"] {
Eliot Berriot
committed
flex-direction: column;
Eliot Berriot
committed
tr {
cursor: pointer;
}
Eliot Berriot
committed
}
Eliot Berriot
committed
.tab[data-tab="library"] {
flex-direction: column;
flex: 1 1 auto;
> .menu {
flex: 1;
flex-grow: 1;
}
> .player-wrapper {
width: 100%;
}
}
Eliot Berriot
committed
.sidebar .segment {
margin: 0;
border-radius: 0;
}
.ui.inverted.segment.header-wrapper {
padding: 0;
}
.logo {
cursor: pointer;
display: inline-block;
Eliot Berriot
committed
}
.ui.search {
.collapse.button,
.collapse.button:hover,
.collapse.button:active {
box-shadow: none !important;
margin: 0px;
display: flex;
flex-direction: column;
justify-content: center;
Eliot Berriot
committed
}
.ui.message.black {
background: $sidebar-color;
}
.ui.mini.image {
width: 100%;
}
</style>
<style lang="scss">
.sidebar {
.ui.search .input {
flex: 1;
.prompt {
border-radius: 0;
}
}
}
Eliot Berriot
committed
:not(.active) button.title {
outline-color: white;
}