|
@@ -6,9 +6,9 @@
|
|
Playlists
|
|
Playlists
|
|
</p>
|
|
</p>
|
|
<ul class="menu-list">
|
|
<ul class="menu-list">
|
|
- <li v-for='playlist in playlists'>
|
|
|
|
|
|
+ <li v-for='playlist in playlistsArr'>
|
|
<div class='playlist'>
|
|
<div class='playlist'>
|
|
- <span class='icon is-small' @click='removeSongFromPlaylist(playlist._id)' v-if='playlistContains(playlist._id)'>
|
|
|
|
|
|
+ <span class='icon is-small' @click='removeSongFromPlaylist(playlist._id)' v-if='playlists[playlist._id].hasSong'>
|
|
<i class="material-icons">playlist_add_check</i>
|
|
<i class="material-icons">playlist_add_check</i>
|
|
</span>
|
|
</span>
|
|
<span class='icon is-small' @click='addSongToPlaylist(playlist._id)' v-else>
|
|
<span class='icon is-small' @click='addSongToPlaylist(playlist._id)' v-else>
|
|
@@ -32,47 +32,65 @@
|
|
export default {
|
|
export default {
|
|
data() {
|
|
data() {
|
|
return {
|
|
return {
|
|
- playlists: {}
|
|
|
|
|
|
+ playlists: {},
|
|
|
|
+ playlistsArr: [],
|
|
|
|
+ songId: null,
|
|
|
|
+ song: null
|
|
}
|
|
}
|
|
},
|
|
},
|
|
methods: {
|
|
methods: {
|
|
- playlistContains: function (playlistId) {
|
|
|
|
- let _this = this;
|
|
|
|
- let toReturn = false;
|
|
|
|
-
|
|
|
|
- let playlist = this.playlists.filter(playlist => {
|
|
|
|
- return playlist._id === playlistId;
|
|
|
|
- })[0];
|
|
|
|
-
|
|
|
|
- for (let i = 0; i < playlist.songs.length; i++) {
|
|
|
|
- if (playlist.songs[i].songId === _this.$parent.currentSong.songId) {
|
|
|
|
- toReturn = true;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return toReturn;
|
|
|
|
- },
|
|
|
|
addSongToPlaylist: function (playlistId) {
|
|
addSongToPlaylist: function (playlistId) {
|
|
let _this = this;
|
|
let _this = this;
|
|
this.socket.emit('playlists.addSongToPlaylist', this.$parent.currentSong.songId, playlistId, res => {
|
|
this.socket.emit('playlists.addSongToPlaylist', this.$parent.currentSong.songId, playlistId, res => {
|
|
Toast.methods.addToast(res.message, 4000);
|
|
Toast.methods.addToast(res.message, 4000);
|
|
- this.$parent.modals.addSongToPlaylist = false;
|
|
|
|
|
|
+ if (res.status === 'success') {
|
|
|
|
+ _this.playlists[playlistId].songs.push(_this.song);
|
|
|
|
+ }
|
|
|
|
+ _this.recalculatePlaylists();
|
|
|
|
+ //this.$parent.modals.addSongToPlaylist = false;
|
|
});
|
|
});
|
|
},
|
|
},
|
|
removeSongFromPlaylist: function (playlistId) {
|
|
removeSongFromPlaylist: function (playlistId) {
|
|
let _this = this;
|
|
let _this = this;
|
|
- this.socket.emit('playlists.removeSongFromPlaylist', this.$parent.currentSong.songId, playlistId, res => {
|
|
|
|
|
|
+ this.socket.emit('playlists.removeSongFromPlaylist', _this.songId, playlistId, res => {
|
|
Toast.methods.addToast(res.message, 4000);
|
|
Toast.methods.addToast(res.message, 4000);
|
|
- this.$parent.modals.addSongToPlaylist = false;
|
|
|
|
|
|
+ if (res.status === 'success') {
|
|
|
|
+ _this.playlists[playlistId].songs.forEach((song, index) => {
|
|
|
|
+ if (song.songId === _this.songId) _this.playlists[playlistId].songs.splice(index, 1);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ _this.recalculatePlaylists();
|
|
|
|
+ //this.$parent.modals.addSongToPlaylist = false;
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ recalculatePlaylists: function() {
|
|
|
|
+ let _this = this;
|
|
|
|
+ _this.playlistsArr = Object.values(_this.playlists).map((playlist) => {
|
|
|
|
+ let hasSong = false;
|
|
|
|
+ for (let i = 0; i < playlist.songs.length; i++) {
|
|
|
|
+ if (playlist.songs[i].songId === _this.songId) {
|
|
|
|
+ hasSong = true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ playlist.hasSong = hasSong;
|
|
|
|
+ _this.playlists[playlist._id] = playlist;
|
|
|
|
+ return playlist;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
},
|
|
},
|
|
ready: function () {
|
|
ready: function () {
|
|
let _this = this;
|
|
let _this = this;
|
|
|
|
+ this.songId = this.$parent.currentSong.songId;
|
|
|
|
+ this.song = this.$parent.currentSong;
|
|
io.getSocket((socket) => {
|
|
io.getSocket((socket) => {
|
|
_this.socket = socket;
|
|
_this.socket = socket;
|
|
_this.socket.emit('playlists.indexForUser', res => {
|
|
_this.socket.emit('playlists.indexForUser', res => {
|
|
- if (res.status === 'success') _this.playlists = res.data;
|
|
|
|
|
|
+ if (res.status === 'success') {
|
|
|
|
+ res.data.forEach((playlist) => {
|
|
|
|
+ _this.playlists[playlist._id] = playlist;
|
|
|
|
+ });
|
|
|
|
+ _this.recalculatePlaylists();
|
|
|
|
+ }
|
|
});
|
|
});
|
|
});
|
|
});
|
|
},
|
|
},
|