MyPlaylists.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <template>
  2. <div id="my-playlists">
  3. <ul class="menu-list scrollable-list" v-if="playlists.length > 0">
  4. <li v-for="(playlist, index) in playlists" :key="index">
  5. <playlist-item :playlist="playlist">
  6. <div class="icons-group" slot="actions">
  7. <button
  8. v-if="
  9. station.type === 'community' &&
  10. isNotSelected(playlist._id) &&
  11. !station.partyMode
  12. "
  13. class="button is-primary"
  14. @click="selectPlaylist(playlist._id)"
  15. >
  16. <i class="material-icons">play_arrow</i>
  17. </button>
  18. <button
  19. v-if="
  20. station.type === 'community' &&
  21. !isNotSelected(playlist._id) &&
  22. !station.partyMode
  23. "
  24. class="button is-danger"
  25. @click="deselectPlaylist()"
  26. >
  27. <i class="material-icons">stop</i>
  28. </button>
  29. <button
  30. class="button is-primary"
  31. @click="edit(playlist._id)"
  32. >
  33. <i class="material-icons">edit</i>
  34. </button>
  35. </div>
  36. </playlist-item>
  37. </li>
  38. </ul>
  39. <p v-else class="nothing-here-text scrollable-list">
  40. No Playlists found
  41. </p>
  42. <a
  43. class="button create-playlist tab-actionable-button"
  44. href="#"
  45. @click="openModal({ sector: 'station', modal: 'createPlaylist' })"
  46. >Create Playlist</a
  47. >
  48. </div>
  49. </template>
  50. <script>
  51. import { mapState, mapActions } from "vuex";
  52. import Toast from "toasters";
  53. import PlaylistItem from "../../../../components/ui/PlaylistItem.vue";
  54. import io from "../../../../io";
  55. export default {
  56. components: { PlaylistItem },
  57. data() {
  58. return {
  59. playlists: []
  60. };
  61. },
  62. computed: {
  63. ...mapState("modals", {
  64. modals: state => state.modals.station
  65. }),
  66. ...mapState({
  67. station: state => state.station.station
  68. })
  69. },
  70. mounted() {
  71. io.getSocket(socket => {
  72. this.socket = socket;
  73. /** Get playlists for user */
  74. this.socket.emit("playlists.indexForUser", res => {
  75. if (res.status === "success") this.playlists = res.data;
  76. });
  77. this.socket.on("event:playlist.create", playlist => {
  78. this.playlists.push(playlist);
  79. });
  80. this.socket.on("event:playlist.delete", playlistId => {
  81. this.playlists.forEach((playlist, index) => {
  82. if (playlist._id === playlistId) {
  83. this.playlists.splice(index, 1);
  84. }
  85. });
  86. });
  87. this.socket.on("event:playlist.addSong", data => {
  88. this.playlists.forEach((playlist, index) => {
  89. if (playlist._id === data.playlistId) {
  90. this.playlists[index].songs.push(data.song);
  91. }
  92. });
  93. });
  94. this.socket.on("event:playlist.removeSong", data => {
  95. this.playlists.forEach((playlist, index) => {
  96. if (playlist._id === data.playlistId) {
  97. this.playlists[index].songs.forEach((song, index2) => {
  98. if (song._id === data.songId) {
  99. this.playlists[index].songs.splice(index2, 1);
  100. }
  101. });
  102. }
  103. });
  104. });
  105. this.socket.on("event:playlist.updateDisplayName", data => {
  106. this.playlists.forEach((playlist, index) => {
  107. if (playlist._id === data.playlistId) {
  108. this.playlists[index].displayName = data.displayName;
  109. }
  110. });
  111. });
  112. });
  113. },
  114. methods: {
  115. edit(id) {
  116. this.editPlaylist(id);
  117. this.openModal({ sector: "station", modal: "editPlaylist" });
  118. },
  119. selectPlaylist(id) {
  120. this.socket.emit(
  121. "stations.selectPrivatePlaylist",
  122. this.station._id,
  123. id,
  124. res => {
  125. if (res.status === "failure")
  126. return new Toast({
  127. content: res.message,
  128. timeout: 8000
  129. });
  130. return new Toast({ content: res.message, timeout: 4000 });
  131. }
  132. );
  133. },
  134. deselectPlaylist() {
  135. this.socket.emit(
  136. "stations.deselectPrivatePlaylist",
  137. this.station._id,
  138. res => {
  139. if (res.status === "failure")
  140. return new Toast({
  141. content: res.message,
  142. timeout: 8000
  143. });
  144. return new Toast({ content: res.message, timeout: 4000 });
  145. }
  146. );
  147. },
  148. isNotSelected(id) {
  149. // TODO Also change this once it changes for a station
  150. if (this.station && this.station.privatePlaylist === id)
  151. return false;
  152. return true;
  153. },
  154. ...mapActions("modals", ["openModal"]),
  155. ...mapActions("user/playlists", ["editPlaylist"])
  156. }
  157. };
  158. </script>
  159. <style lang="scss" scoped>
  160. @import "../../../../styles/global.scss";
  161. #my-playlists {
  162. background-color: #fff;
  163. margin-bottom: 20px;
  164. border-radius: 0 0 5px 5px;
  165. max-height: 100%;
  166. .nothing-here-text {
  167. margin-bottom: 10px;
  168. }
  169. .icons-group {
  170. display: flex;
  171. align-items: center;
  172. button:not(:first-of-type) {
  173. margin-left: 5px;
  174. }
  175. }
  176. }
  177. .night-mode {
  178. #my-playlists {
  179. background-color: $night-mode-bg-secondary !important;
  180. border: 0 !important;
  181. }
  182. }
  183. .menu-list li {
  184. align-items: center;
  185. &:not(:last-of-type) {
  186. margin-bottom: 10px;
  187. }
  188. }
  189. .create-playlist {
  190. width: 100%;
  191. height: 40px;
  192. border-radius: 5px;
  193. background-color: rgba(3, 169, 244, 1);
  194. color: $white !important;
  195. border: 0;
  196. &:active,
  197. &:focus {
  198. border: 0;
  199. }
  200. &:focus {
  201. background-color: $primary-color;
  202. }
  203. }
  204. </style>