MyPlaylists.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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", true, 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.songId === 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. this.socket.on("event:playlist.updatePrivacy", data => {
  113. this.playlists.forEach((playlist, index) => {
  114. if (playlist._id === data.playlistId) {
  115. this.playlists[index].privacy = data.privacy;
  116. }
  117. });
  118. });
  119. });
  120. },
  121. methods: {
  122. edit(id) {
  123. this.editPlaylist(id);
  124. this.openModal({ sector: "station", modal: "editPlaylist" });
  125. },
  126. selectPlaylist(id) {
  127. this.socket.emit(
  128. "stations.selectPrivatePlaylist",
  129. this.station._id,
  130. id,
  131. res => {
  132. if (res.status === "failure")
  133. return new Toast({
  134. content: res.message,
  135. timeout: 8000
  136. });
  137. return new Toast({ content: res.message, timeout: 4000 });
  138. }
  139. );
  140. },
  141. deselectPlaylist() {
  142. this.socket.emit(
  143. "stations.deselectPrivatePlaylist",
  144. this.station._id,
  145. res => {
  146. if (res.status === "failure")
  147. return new Toast({
  148. content: res.message,
  149. timeout: 8000
  150. });
  151. return new Toast({ content: res.message, timeout: 4000 });
  152. }
  153. );
  154. },
  155. isNotSelected(id) {
  156. // TODO Also change this once it changes for a station
  157. if (this.station && this.station.privatePlaylist === id)
  158. return false;
  159. return true;
  160. },
  161. ...mapActions("modals", ["openModal"]),
  162. ...mapActions("user/playlists", ["editPlaylist"])
  163. }
  164. };
  165. </script>
  166. <style lang="scss" scoped>
  167. @import "../../../../styles/global.scss";
  168. #my-playlists {
  169. background-color: #fff;
  170. margin-bottom: 20px;
  171. border-radius: 0 0 5px 5px;
  172. max-height: 100%;
  173. .nothing-here-text {
  174. margin-bottom: 10px;
  175. }
  176. .icons-group {
  177. display: flex;
  178. align-items: center;
  179. button:not(:first-of-type) {
  180. margin-left: 5px;
  181. }
  182. }
  183. }
  184. .night-mode {
  185. #my-playlists {
  186. background-color: $night-mode-bg-secondary !important;
  187. border: 0 !important;
  188. }
  189. }
  190. .menu-list li {
  191. align-items: center;
  192. &:not(:last-of-type) {
  193. margin-bottom: 10px;
  194. }
  195. }
  196. .create-playlist {
  197. width: 100%;
  198. height: 40px;
  199. border-radius: 5px;
  200. background-color: rgba(3, 169, 244, 1);
  201. color: $white !important;
  202. border: 0;
  203. &:active,
  204. &:focus {
  205. border: 0;
  206. }
  207. &:focus {
  208. background-color: $primary-color;
  209. }
  210. }
  211. </style>