/
artist.vue
177 lines (156 loc) · 4.54 KB
/
artist.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<template>
<section id="artistWrapper">
<h1 class="heading">
<span class="overview">
<img :src="image" width="64" height="64" class="cover">
{{ artist.name }}
<controls-toggler :showing-controls="showingControls" @toggleControls="toggleControls"/>
<span class="meta" v-show="artist.songs.length">
{{ artist.albums.length | pluralize('album') }}
•
{{ artist.songs.length | pluralize('song') }}
•
{{ fmtLength }}
<template v-if="sharedState.useLastfm">
•
<a class="info" href @click.prevent="showInfo" title="View artist's extra information">Info</a>
</template>
<template v-if="sharedState.allowDownload">
•
<a class="download" href @click.prevent="download" title="Download all songs by this artist">
Download All
</a>
</template>
</span>
</span>
<song-list-controls
v-show="artist.songs.length && (!isPhone || showingControls)"
@shuffleAll="shuffleAll"
@shuffleSelected="shuffleSelected"
:config="songListControlConfig"
:selectedSongs="selectedSongs"
/>
</h1>
<song-list :items="artist.songs" type="artist" ref="songList"/>
<section class="info-wrapper" v-if="sharedState.useLastfm && info.showing">
<a href class="close" @click.prevent="info.showing = false"><i class="fa fa-times"></i></a>
<div class="inner">
<div class="loading" v-if="info.loading"><sound-bar/></div>
<artist-info :artist="artist" mode="full" v-else/>
</div>
</section>
</section>
</template>
<script>
import { pluralize, event } from '../../../utils'
import { sharedStore, artistStore } from '../../../stores'
import { playback, download, artistInfo as artistInfoService } from '../../../services'
import router from '../../../router'
import hasSongList from '../../../mixins/has-song-list'
import artistAttributes from '../../../mixins/artist-attributes'
import artistInfo from '../extra/artist-info.vue'
import soundBar from '../../shared/sound-bar.vue'
export default {
name: 'main-wrapper--main-content--artist',
mixins: [hasSongList, artistAttributes],
components: { artistInfo, soundBar },
filters: { pluralize },
data () {
return {
sharedState: sharedStore.state,
artist: artistStore.stub,
info: {
showing: false,
loading: true
}
}
},
watch: {
/**
* Watch the artist's album count.
* If this is changed to 0, the user has edit the songs by this artist
* and move all of them to another artist (thus delete this artist entirely).
* We should then go back to the artist list.
*/
'artist.albums.length' (newVal) {
if (!newVal) {
router.go('artists')
}
}
},
created () {
/**
* Listen to 'main-content-view:load' event to load the requested artist
* into view if applicable.
*
* @param {String} view The view's name
* @param {Object} artist
*/
event.on('main-content-view:load', (view, artist) => {
if (view === 'artist') {
this.info.showing = false
this.artist = artist
// #530
this.$nextTick(() => this.$refs.songList && this.$refs.songList.sort())
}
})
},
methods: {
/**
* Shuffle the songs by the current artist.
* Overriding the mixin.
*/
shuffleAll () {
playback.queueAndPlay(this.artist.songs, true)
},
/**
* Download all songs by the artist.
*/
download () {
download.fromArtist(this.artist)
},
async showInfo () {
this.info.showing = true
if (!this.artist.info) {
this.info.loading = true
try {
await artistInfoService.fetch(this.artist)
} catch (e) {
} finally {
this.info.loading = false
}
} else {
this.info.loading = false
}
}
}
}
</script>
<style lang="scss" scoped>
@import "../../../../sass/partials/_vars.scss";
@import "../../../../sass/partials/_mixins.scss";
#artistWrapper {
button.play-shuffle {
i {
margin-right: 0 !important;
}
}
.heading {
.overview {
position: relative;
padding-left: 84px;
@media only screen and (max-width : 768px) {
padding-left: 0;
}
}
.cover {
position: absolute;
left: 0;
@media only screen and (max-width : 768px) {
display: none;
}
}
}
@include artist-album-info-wrapper();
}
</style>