Playlist.vue 4.5 KB

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