Playlist.vue 4.3 KB

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