Playlist.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <template>
  2. <div class="sidebar" transition="slide">
  3. <div class="inner-wrapper">
  4. <div class="title">Playlists</div>
  5. <aside class="menu" v-if="playlists.length > 0">
  6. <ul class="menu-list">
  7. <li v-for="(playlist, index) in playlists" :key="index">
  8. <span>{{ playlist.displayName }}</span>
  9. <!--Will play playlist in community station Kris-->
  10. <div class="icons-group">
  11. <a
  12. href="#"
  13. v-on:click="selectPlaylist(playlist._id)"
  14. v-if="isNotSelected(playlist._id) && !$parent.station.partyMode"
  15. >
  16. <i class="material-icons">play_arrow</i>
  17. </a>
  18. <a href="#" v-on:click="edit(playlist._id)">
  19. <i class="material-icons">edit</i>
  20. </a>
  21. </div>
  22. </li>
  23. </ul>
  24. </aside>
  25. <div class="none-found" v-else>No Playlists found</div>
  26. <a
  27. class="button create-playlist"
  28. href="#"
  29. v-on:click="toggleModal({ sector: 'station', modal: 'createPlaylist' })"
  30. >Create Playlist</a>
  31. </div>
  32. </div>
  33. </template>
  34. <script>
  35. import { mapActions } from "vuex";
  36. import { Toast } from "vue-roaster";
  37. import { Edit } from "../Modals/Playlists/Edit.vue";
  38. import io from "../../io";
  39. export default {
  40. data() {
  41. return {
  42. playlists: []
  43. };
  44. },
  45. methods: {
  46. edit: function(id) {
  47. this.editPlaylist(id);
  48. this.toggleModal({ sector: "station", modal: "editPlaylist" });
  49. },
  50. selectPlaylist: function(id) {
  51. this.socket.emit(
  52. "stations.selectPrivatePlaylist",
  53. this.$parent.station._id,
  54. id,
  55. res => {
  56. if (res.status === "failure")
  57. return Toast.methods.addToast(res.message, 8000);
  58. Toast.methods.addToast(res.message, 4000);
  59. }
  60. );
  61. },
  62. isNotSelected: function(id) {
  63. let _this = this;
  64. //TODO Also change this once it changes for a station
  65. if (_this.$parent.station && _this.$parent.station.privatePlaylist === id)
  66. return false;
  67. return true;
  68. },
  69. ...mapActions("modals", ["toggleModal"]),
  70. ...mapActions("user/playlists", ["editPlaylist"])
  71. },
  72. mounted: function() {
  73. // TODO: Update when playlist is removed/created
  74. let _this = this;
  75. io.getSocket(socket => {
  76. _this.socket = socket;
  77. _this.socket.emit("playlists.indexForUser", res => {
  78. if (res.status == "success") _this.playlists = res.data;
  79. });
  80. _this.socket.on("event:playlist.create", playlist => {
  81. _this.playlists.push(playlist);
  82. });
  83. _this.socket.on("event:playlist.delete", playlistId => {
  84. _this.playlists.forEach((playlist, index) => {
  85. if (playlist._id === playlistId) {
  86. _this.playlists.splice(index, 1);
  87. }
  88. });
  89. });
  90. _this.socket.on("event:playlist.addSong", data => {
  91. _this.playlists.forEach((playlist, index) => {
  92. if (playlist._id === data.playlistId) {
  93. _this.playlists[index].songs.push(data.song);
  94. }
  95. });
  96. });
  97. _this.socket.on("event:playlist.removeSong", data => {
  98. _this.playlists.forEach((playlist, index) => {
  99. if (playlist._id === data.playlistId) {
  100. _this.playlists[index].songs.forEach((song, index2) => {
  101. if (song._id === data.songId) {
  102. _this.playlists[index].songs.splice(index2, 1);
  103. }
  104. });
  105. }
  106. });
  107. });
  108. _this.socket.on("event:playlist.updateDisplayName", data => {
  109. _this.playlists.forEach((playlist, index) => {
  110. if (playlist._id === data.playlistId) {
  111. _this.playlists[index].displayName = data.displayName;
  112. }
  113. });
  114. });
  115. });
  116. }
  117. };
  118. </script>
  119. <style lang='scss' scoped>
  120. .sidebar {
  121. position: fixed;
  122. z-index: 1;
  123. top: 0;
  124. right: 0;
  125. width: 300px;
  126. height: 100vh;
  127. background-color: #fff;
  128. box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12);
  129. }
  130. .icons-group a {
  131. display: flex;
  132. align-items: center;
  133. }
  134. .menu-list li {
  135. align-items: center;
  136. }
  137. .inner-wrapper {
  138. top: 64px;
  139. position: relative;
  140. }
  141. .slide-transition {
  142. transition: transform 0.6s ease-in-out;
  143. transform: translateX(0);
  144. }
  145. .slide-enter,
  146. .slide-leave {
  147. transform: translateX(100%);
  148. }
  149. .title {
  150. background-color: rgb(3, 169, 244);
  151. text-align: center;
  152. padding: 10px;
  153. color: white;
  154. font-weight: 600;
  155. }
  156. .create-playlist {
  157. width: 100%;
  158. margin-top: 20px;
  159. height: 40px;
  160. border-radius: 0;
  161. background: rgba(3, 169, 244, 1);
  162. color: #fff !important;
  163. border: 0;
  164. &:active,
  165. &:focus {
  166. border: 0;
  167. }
  168. }
  169. .create-playlist:focus {
  170. background: #029ce3;
  171. }
  172. .none-found {
  173. text-align: center;
  174. }
  175. </style>