Playlist.vue 4.3 KB

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