Playlist.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. ...mapState({
  59. station: state => state.station.station
  60. })
  61. },
  62. methods: {
  63. edit(id) {
  64. this.editPlaylist(id);
  65. this.openModal({ sector: "station", modal: "editPlaylist" });
  66. },
  67. selectPlaylist(id) {
  68. this.socket.emit(
  69. "stations.selectPrivatePlaylist",
  70. this.station._id,
  71. id,
  72. res => {
  73. if (res.status === "failure")
  74. return Toast.methods.addToast(res.message, 8000);
  75. return Toast.methods.addToast(res.message, 4000);
  76. }
  77. );
  78. },
  79. isNotSelected(id) {
  80. // TODO Also change this once it changes for a station
  81. if (this.station && this.station.privatePlaylist === id)
  82. return false;
  83. return true;
  84. },
  85. ...mapActions("modals", ["openModal"]),
  86. ...mapActions("user/playlists", ["editPlaylist"])
  87. },
  88. mounted() {
  89. // TODO: Update when playlist is removed/created
  90. io.getSocket(socket => {
  91. this.socket = socket;
  92. this.socket.emit("playlists.indexForUser", res => {
  93. if (res.status === "success") this.playlists = res.data;
  94. });
  95. this.socket.on("event:playlist.create", playlist => {
  96. this.playlists.push(playlist);
  97. });
  98. this.socket.on("event:playlist.delete", playlistId => {
  99. this.playlists.forEach((playlist, index) => {
  100. if (playlist._id === playlistId) {
  101. this.playlists.splice(index, 1);
  102. }
  103. });
  104. });
  105. this.socket.on("event:playlist.addSong", data => {
  106. this.playlists.forEach((playlist, index) => {
  107. if (playlist._id === data.playlistId) {
  108. this.playlists[index].songs.push(data.song);
  109. }
  110. });
  111. });
  112. this.socket.on("event:playlist.removeSong", data => {
  113. this.playlists.forEach((playlist, index) => {
  114. if (playlist._id === data.playlistId) {
  115. this.playlists[index].songs.forEach((song, index2) => {
  116. if (song._id === data.songId) {
  117. this.playlists[index].songs.splice(index2, 1);
  118. }
  119. });
  120. }
  121. });
  122. });
  123. this.socket.on("event:playlist.updateDisplayName", data => {
  124. this.playlists.forEach((playlist, index) => {
  125. if (playlist._id === data.playlistId) {
  126. this.playlists[index].displayName = data.displayName;
  127. }
  128. });
  129. });
  130. });
  131. }
  132. };
  133. </script>
  134. <style lang="scss" scoped>
  135. @import "styles/global.scss";
  136. .sidebar {
  137. position: fixed;
  138. z-index: 1;
  139. top: 0;
  140. right: 0;
  141. width: 300px;
  142. height: 100vh;
  143. background-color: $white;
  144. box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.16),
  145. 0 2px 10px 0 rgba(0, 0, 0, 0.12);
  146. }
  147. .icons-group a {
  148. display: flex;
  149. align-items: center;
  150. }
  151. .menu-list li {
  152. align-items: center;
  153. }
  154. .inner-wrapper {
  155. top: 60px;
  156. position: relative;
  157. }
  158. .slide-transition {
  159. transition: transform 0.6s ease-in-out;
  160. transform: translateX(0);
  161. }
  162. .slide-enter,
  163. .slide-leave {
  164. transform: translateX(100%);
  165. }
  166. .title {
  167. background-color: rgb(3, 169, 244);
  168. text-align: center;
  169. padding: 10px;
  170. color: $white;
  171. font-weight: 600;
  172. }
  173. .create-playlist {
  174. width: 100%;
  175. margin-top: 20px;
  176. height: 40px;
  177. border-radius: 0;
  178. background: rgba(3, 169, 244, 1);
  179. color: $white !important;
  180. border: 0;
  181. &:active,
  182. &:focus {
  183. border: 0;
  184. }
  185. }
  186. .create-playlist:focus {
  187. background: $primary-color;
  188. }
  189. .none-found {
  190. text-align: center;
  191. }
  192. </style>