mirror of
https://github.com/koel/koel
synced 2024-11-10 14:44:13 +00:00
Refactor
This commit is contained in:
parent
cd94c4e38a
commit
9537ad26b1
19 changed files with 33 additions and 64 deletions
|
@ -54,6 +54,10 @@ export default {
|
|||
},
|
||||
|
||||
watch: {
|
||||
/**
|
||||
* Whenever a new album is loaded into this component, we reset the "full wiki" state.
|
||||
* @return {Boolean}
|
||||
*/
|
||||
album () {
|
||||
this.showingFullWiki = false
|
||||
}
|
||||
|
|
|
@ -41,6 +41,10 @@ export default {
|
|||
},
|
||||
|
||||
watch: {
|
||||
/**
|
||||
* Whenever a new artist is loaded into this component, we reset the "full bio" state.
|
||||
* @return {Boolean}
|
||||
*/
|
||||
artist () {
|
||||
this.showingFullBio = false
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ export default {
|
|||
|
||||
computed: {
|
||||
latestVersionUrl () {
|
||||
return 'https://github.com/phanan/koel/releases/tag/' + this.sharedState.latestVersion
|
||||
return `https://github.com/phanan/koel/releases/tag/${this.sharedState.latestVersion}`
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -28,7 +28,6 @@ export default {
|
|||
|
||||
data () {
|
||||
return {
|
||||
newName: '',
|
||||
editing: false,
|
||||
active: false
|
||||
}
|
||||
|
|
|
@ -48,10 +48,10 @@ export default {
|
|||
store () {
|
||||
this.creating = false
|
||||
|
||||
playlistStore.store(this.newName).then(p => {
|
||||
playlistStore.store(this.newName).then(playlist => {
|
||||
this.newName = ''
|
||||
// Activate the new playlist right away
|
||||
this.$nextTick(() => router.go(`playlist/${p.id}`))
|
||||
this.$nextTick(() => router.go(`playlist/${playlist.id}`))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,9 +47,7 @@ export default {
|
|||
|
||||
watch: {
|
||||
songs () {
|
||||
if (!this.songs.length) {
|
||||
this.close()
|
||||
}
|
||||
this.songs.length || this.close()
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -65,10 +63,10 @@ export default {
|
|||
return
|
||||
}
|
||||
|
||||
playlistStore.store(this.newPlaylistName, this.songs).then(p => {
|
||||
playlistStore.store(this.newPlaylistName, this.songs).then(playlist => {
|
||||
this.newPlaylistName = ''
|
||||
// Activate the new playlist right away
|
||||
this.$nextTick(() => router.go(`playlist/${p.id}`))
|
||||
this.$nextTick(() => router.go(`playlist/${playlist.id}`))
|
||||
})
|
||||
|
||||
this.close()
|
||||
|
|
|
@ -36,8 +36,6 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import { map } from 'lodash'
|
||||
|
||||
import { pluralize } from '../../utils'
|
||||
import { queueStore, artistStore, sharedStore } from '../../stores'
|
||||
import { playback, download } from '../../services'
|
||||
|
@ -91,7 +89,7 @@ export default {
|
|||
* Allow dragging the album (actually, its songs).
|
||||
*/
|
||||
dragStart (e) {
|
||||
const songIds = map(this.album.songs, 'id')
|
||||
const songIds = this.album.songs.map(song => song.id)
|
||||
e.dataTransfer.setData('application/x-koel.text+plain', songIds)
|
||||
e.dataTransfer.effectAllowed = 'move'
|
||||
|
||||
|
|
|
@ -28,8 +28,6 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import { map } from 'lodash'
|
||||
|
||||
import { pluralize } from '../../utils'
|
||||
import { artistStore, queueStore, sharedStore } from '../../stores'
|
||||
import { playback, download } from '../../services'
|
||||
|
@ -80,7 +78,7 @@ export default {
|
|||
* Allow dragging the artist (actually, their songs).
|
||||
*/
|
||||
dragStart (e) {
|
||||
const songIds = map(this.artist.songs, 'id')
|
||||
const songIds = this.artist.songs.map(song => song.id)
|
||||
e.dataTransfer.setData('application/x-koel.text+plain', songIds)
|
||||
e.dataTransfer.effectAllowed = 'move'
|
||||
|
||||
|
|
|
@ -38,10 +38,7 @@ export default {
|
|||
|
||||
methods: {
|
||||
play () {
|
||||
if (!queueStore.contains(this.song)) {
|
||||
queueStore.queueAfterCurrent(this.song)
|
||||
}
|
||||
|
||||
queueStore.contains(this.song) || queueStore.queueAfterCurrent(this.song)
|
||||
playback.play(this.song)
|
||||
},
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
@dragstart="dragStart"
|
||||
@dragleave="dragLeave"
|
||||
@dragover.prevent="dragOver"
|
||||
@drop.stop.prevent="dropStop"
|
||||
@drop.stop.prevent="drop"
|
||||
@contextmenu.prevent="contextMenu"
|
||||
:class="{ selected: item.selected, playing: playing }"
|
||||
>
|
||||
|
@ -66,10 +66,7 @@ export default {
|
|||
* Play the song right away.
|
||||
*/
|
||||
playRightAwayyyyyyy () {
|
||||
if (!queueStore.contains(this.song)) {
|
||||
queueStore.queueAfterCurrent(this.song)
|
||||
}
|
||||
|
||||
queueStore.contains(this.song) || queueStore.queueAfterCurrent(this.song)
|
||||
playback.play(this.song)
|
||||
},
|
||||
|
||||
|
@ -126,7 +123,7 @@ export default {
|
|||
* Proxy the dropstop event to the parent song list component.
|
||||
* @param {Event} event
|
||||
*/
|
||||
dropStop (event) {
|
||||
drop (event) {
|
||||
this.parentSongList.handleDrop(this, event)
|
||||
},
|
||||
|
||||
|
|
|
@ -101,10 +101,7 @@ export default {
|
|||
playback.resume()
|
||||
break
|
||||
default:
|
||||
if (!queueStore.contains(this.songs[0])) {
|
||||
queueStore.queueAfterCurrent(this.songs[0])
|
||||
}
|
||||
|
||||
queueStore.contains(this.songs[0]) || queueStore.queueAfterCurrent(this.songs[0])
|
||||
playback.play(this.songs[0])
|
||||
break
|
||||
}
|
||||
|
@ -116,10 +113,7 @@ export default {
|
|||
* Trigger opening the "Edit Song" form/overlay.
|
||||
*/
|
||||
openEditForm () {
|
||||
if (this.songs.length) {
|
||||
event.emit('songs:edit', this.songs)
|
||||
}
|
||||
|
||||
this.songs.length || event.emit('songs:edit', this.songs)
|
||||
this.close()
|
||||
},
|
||||
|
||||
|
|
|
@ -46,10 +46,7 @@ export default {
|
|||
methods: {
|
||||
play () {
|
||||
if (this.correspondingSong) {
|
||||
if (!queueStore.contains(this.correspondingSong)) {
|
||||
queueStore.queueAfterCurrent(this.correspondingSong)
|
||||
}
|
||||
|
||||
queueStore.contains(this.correspondingSong) || queueStore.queueAfterCurrent(this.correspondingSong)
|
||||
playback.play(this.correspondingSong)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,7 +108,6 @@ export default {
|
|||
// Hide the typeahead results and reset the value if ESC is pressed.
|
||||
if (e.keyCode === 27) {
|
||||
this.showingResult = false
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,6 @@ export default {
|
|||
edit () {
|
||||
if (this.isCurrentUser) {
|
||||
router.go('profile')
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -67,9 +66,7 @@ export default {
|
|||
*/
|
||||
del () {
|
||||
alerts.confirm(`You’re about to unperson ${this.user.name}. Are you sure?`, () => {
|
||||
userStore.destroy(this.user).then(() => {
|
||||
this.$destroy(true)
|
||||
})
|
||||
userStore.destroy(this.user).then(() => this.$destroy(true))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,9 +11,7 @@ export const clickawayDirective = {
|
|||
}
|
||||
|
||||
document.addEventListener('click', e => {
|
||||
if (!el.contains(e.target)) {
|
||||
value()
|
||||
}
|
||||
el.contains(e.target) || value()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { event, $ } from '../utils'
|
||||
import { $ } from '../utils'
|
||||
import toTopButton from '../components/shared/to-top-button.vue'
|
||||
|
||||
/**
|
||||
|
|
|
@ -43,7 +43,6 @@ export const download = {
|
|||
*/
|
||||
fromPlaylist (playlist) {
|
||||
if (!playlistStore.getSongs(playlist).length) {
|
||||
console.warn('Empty playlist.')
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -32,9 +32,7 @@ export const playback = {
|
|||
/**
|
||||
* Listen to 'error' event on the audio player and play the next song if any.
|
||||
*/
|
||||
document.querySelector('.plyr').addEventListener('error', e => {
|
||||
this.playNext()
|
||||
}, true)
|
||||
document.querySelector('.plyr').addEventListener('error', () => this.playNext(), true)
|
||||
|
||||
/**
|
||||
* Listen to 'ended' event on the audio player and play the next song in the queue.
|
||||
|
@ -46,7 +44,6 @@ export const playback = {
|
|||
|
||||
if (preferences.repeatMode === 'REPEAT_ONE') {
|
||||
this.restart()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -67,8 +64,7 @@ export const playback = {
|
|||
return
|
||||
}
|
||||
|
||||
const preloader = document.createElement('audio')
|
||||
preloader.setAttribute('src', songStore.getSourceUrl(nextSong))
|
||||
document.createElement('audio').setAttribute('src', songStore.getSourceUrl(nextSong))
|
||||
|
||||
nextSong.preloaded = true
|
||||
})
|
||||
|
@ -78,9 +74,7 @@ export const playback = {
|
|||
* When user drags the volume control, this event will be triggered, and we
|
||||
* update the volume on the plyr object.
|
||||
*/
|
||||
this.volumeInput.addEventListener('input', e => {
|
||||
this.setVolume(e.target.value)
|
||||
})
|
||||
this.volumeInput.addEventListener('input', e => this.setVolume(e.target.value))
|
||||
|
||||
// On init, set the volume to the value found in the local storage.
|
||||
this.setVolume(preferences.volume)
|
||||
|
|
|
@ -86,9 +86,9 @@ export const albumStore = {
|
|||
*/
|
||||
add (albums) {
|
||||
albums = [].concat(albums)
|
||||
each(albums, a => {
|
||||
this.setupAlbum(a, a.artist)
|
||||
a.playCount = reduce(a.songs, (count, song) => count + song.playCount, 0)
|
||||
each(albums, album => {
|
||||
this.setupAlbum(album, album.artist)
|
||||
album.playCount = reduce(album.songs, (count, song) => count + song.playCount, 0)
|
||||
})
|
||||
|
||||
this.all = union(this.all, albums)
|
||||
|
@ -164,10 +164,7 @@ export const albumStore = {
|
|||
*/
|
||||
getMostPlayed (n = 6) {
|
||||
// Only non-unknown albums with actually play count are applicable.
|
||||
const applicable = filter(this.all, album => {
|
||||
return album.playCount && album.id !== 1
|
||||
})
|
||||
|
||||
const applicable = filter(this.all, album => album.playCount && album.id !== 1)
|
||||
return take(orderBy(applicable, 'playCount', 'desc'), n)
|
||||
},
|
||||
|
||||
|
@ -180,7 +177,6 @@ export const albumStore = {
|
|||
*/
|
||||
getRecentlyAdded (n = 6) {
|
||||
const applicable = filter(this.all, album => album.id !== 1)
|
||||
|
||||
return take(orderBy(applicable, 'created_at', 'desc'), n)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue