MyPlaylists.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <div id="my-playlists">
  3. <aside v-if="playlists.length > 0" class="menu">
  4. <ul class="menu-list">
  5. <li v-for="(playlist, index) in playlists" :key="index">
  6. <playlist-item :playlist="playlist">
  7. <div class="icons-group" slot="actions">
  8. <button
  9. v-if="
  10. station.type === 'community' &&
  11. isNotSelected(playlist._id) &&
  12. !station.partyMode
  13. "
  14. class="button is-primary"
  15. @click="selectPlaylist(playlist._id)"
  16. >
  17. <i class="material-icons">play_arrow</i>
  18. </button>
  19. <button
  20. class="button is-primary"
  21. @click="edit(playlist._id)"
  22. >
  23. <i class="material-icons">edit</i>
  24. </button>
  25. </div>
  26. </playlist-item>
  27. </li>
  28. </ul>
  29. </aside>
  30. <p v-else class="nothing-here">
  31. No Playlists found
  32. </p>
  33. <a
  34. class="button create-playlist"
  35. href="#"
  36. @click="openModal({ sector: 'station', modal: 'createPlaylist' })"
  37. >Create Playlist</a
  38. >
  39. </div>
  40. </template>
  41. <script>
  42. import { mapState, mapActions } from "vuex";
  43. import Toast from "toasters";
  44. import PlaylistItem from "../../../../components/ui/PlaylistItem.vue";
  45. import io from "../../../../io";
  46. export default {
  47. components: { PlaylistItem },
  48. data() {
  49. return {
  50. playlists: []
  51. };
  52. },
  53. computed: {
  54. ...mapState("modals", {
  55. modals: state => state.modals.station
  56. }),
  57. ...mapState({
  58. station: state => state.station.station
  59. })
  60. },
  61. mounted() {
  62. io.getSocket(socket => {
  63. this.socket = socket;
  64. /** Get playlists for user */
  65. this.socket.emit("playlists.indexForUser", res => {
  66. if (res.status === "success") this.playlists = res.data;
  67. });
  68. this.socket.on("event:playlist.create", playlist => {
  69. this.playlists.push(playlist);
  70. });
  71. this.socket.on("event:playlist.delete", playlistId => {
  72. this.playlists.forEach((playlist, index) => {
  73. if (playlist._id === playlistId) {
  74. this.playlists.splice(index, 1);
  75. }
  76. });
  77. });
  78. this.socket.on("event:playlist.addSong", data => {
  79. this.playlists.forEach((playlist, index) => {
  80. if (playlist._id === data.playlistId) {
  81. this.playlists[index].songs.push(data.song);
  82. }
  83. });
  84. });
  85. this.socket.on("event:playlist.removeSong", data => {
  86. this.playlists.forEach((playlist, index) => {
  87. if (playlist._id === data.playlistId) {
  88. this.playlists[index].songs.forEach((song, index2) => {
  89. if (song._id === data.songId) {
  90. this.playlists[index].songs.splice(index2, 1);
  91. }
  92. });
  93. }
  94. });
  95. });
  96. this.socket.on("event:playlist.updateDisplayName", data => {
  97. this.playlists.forEach((playlist, index) => {
  98. if (playlist._id === data.playlistId) {
  99. this.playlists[index].displayName = data.displayName;
  100. }
  101. });
  102. });
  103. });
  104. },
  105. methods: {
  106. edit(id) {
  107. this.editPlaylist(id);
  108. this.openModal({ sector: "station", modal: "editPlaylist" });
  109. },
  110. selectPlaylist(id) {
  111. this.socket.emit(
  112. "stations.selectPrivatePlaylist",
  113. this.station._id,
  114. id,
  115. res => {
  116. if (res.status === "failure")
  117. return new Toast({
  118. content: res.message,
  119. timeout: 8000
  120. });
  121. return new Toast({ content: res.message, timeout: 4000 });
  122. }
  123. );
  124. },
  125. isNotSelected(id) {
  126. // TODO Also change this once it changes for a station
  127. if (this.station && this.station.privatePlaylist === id)
  128. return false;
  129. return true;
  130. },
  131. ...mapActions("modals", ["openModal"]),
  132. ...mapActions("user/playlists", ["editPlaylist"])
  133. }
  134. };
  135. </script>
  136. <style lang="scss" scoped>
  137. @import "../../../../styles/global.scss";
  138. #my-playlists {
  139. background-color: #fff;
  140. border: 1px solid $light-grey-2;
  141. margin-bottom: 20px;
  142. padding: 10px;
  143. border-radius: 0 0 5px 5px;
  144. .nothing-here {
  145. margin-bottom: 10px;
  146. }
  147. .icons-group {
  148. display: flex;
  149. align-items: center;
  150. button:not(:first-of-type) {
  151. margin-left: 5px;
  152. }
  153. }
  154. }
  155. .night-mode {
  156. #my-playlists {
  157. background-color: $night-mode-bg-secondary !important;
  158. border: 0 !important;
  159. }
  160. }
  161. .menu-list li {
  162. align-items: center;
  163. }
  164. .create-playlist {
  165. width: 100%;
  166. height: 40px;
  167. border-radius: 5px;
  168. background-color: rgba(3, 169, 244, 1);
  169. color: $white !important;
  170. border: 0;
  171. &:active,
  172. &:focus {
  173. border: 0;
  174. }
  175. &:focus {
  176. background-color: $primary-color;
  177. }
  178. }
  179. </style>