/
Playlist_List.vue
93 lines (90 loc) · 2.02 KB
/
Playlist_List.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
<template>
<div>
<div class="playlist_info">
<div>
<h2>Your playlists</h2>
</div>
<button class="button is-success" @click="show_add">Create Playlist</button>
<!-- <button class="button is-success" @click="get_playlists">Load Playlist</button> -->
</div>
<div class="playlist_list" @reload="get_playlists">
<PLObject
v-for="playlist in user_playlists"
v-bind:playlist_name="playlist.name"
v-bind:nb_songs="playlist.songs.length"
v-bind:key="playlist._id"
v-bind:id="playlist._id"
>
</PLObject>
</div>
</div>
</template>
<script>
import PLObject from '@/components/objects/Playlist_object.vue'
import CreatePlaylist from '@/components/modals/CreatePlaylist_modal'
import PlaylistService from '@/services/PlaylistService'
export default {
name: 'Playlist_List',
data: function () {
return {
user_playlists: []
}
},
watch: {
// call again the method if the route changes
'$route': 'reload'
},
methods: {
reload () {
this.playlist_songs_id = []
this.get_playlists()
},
async get_playlists () {
console.log('get_playlists')
try {
const response = await PlaylistService.get_playlists()
this.user_playlists = response.data.playlists
// console.log(response)
this.$emit('close')
} catch (error) {
this.error = error.response.data.error
alert(this.error)
console.log(this.error)
console.log(error)
}
},
show_add: function (event) {
this.$modal.show(CreatePlaylist, {}, {
height: 'auto'
})
}
},
async mounted () {
this.get_playlists()
},
components: {
PLObject
}
}
</script>
<style scoped>
.playlist_list{
display: flex;
flex-wrap: wrap;
}
.playlist_info{
display: flex;
align-items: center;
margin: 2em;
}
.playlist_info h2{
font-size: 2em;
font-weight: bold;
}
.playlist_info p{
color: grey;
}
.playlist_info button{
margin-left: 1em;
}
</style>