MyPlaylists.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <template>
  2. <div id="my-playlists">
  3. <draggable
  4. class="menu-list scrollable-list"
  5. v-if="playlists.length > 0"
  6. v-model="playlists"
  7. v-bind="dragOptions"
  8. @start="drag = true"
  9. @end="drag = false"
  10. @change="savePlaylistOrder"
  11. >
  12. <transition-group
  13. type="transition"
  14. :name="!drag ? 'draggable-list-transition' : null"
  15. >
  16. <playlist-item
  17. :playlist="playlist"
  18. v-for="(playlist, index) in playlists"
  19. :key="'key-' + index"
  20. class="item-draggable"
  21. >
  22. <div class="icons-group" slot="actions">
  23. <i
  24. v-if="
  25. station.type === 'community' &&
  26. isNotSelected(playlist._id) &&
  27. !station.partyMode
  28. "
  29. @click="selectPlaylist(playlist._id)"
  30. class="material-icons play-icon"
  31. >play_arrow</i
  32. >
  33. <i
  34. v-if="
  35. station.type === 'community' &&
  36. !isNotSelected(playlist._id) &&
  37. !station.partyMode
  38. "
  39. @click="deselectPlaylist()"
  40. class="material-icons stop-icon"
  41. >stop</i
  42. >
  43. <i
  44. @click="edit(playlist._id)"
  45. class="material-icons edit-icon"
  46. >edit</i
  47. >
  48. </div>
  49. </playlist-item>
  50. </transition-group>
  51. </draggable>
  52. <p v-else class="nothing-here-text scrollable-list">
  53. No Playlists found
  54. </p>
  55. <a
  56. class="button create-playlist tab-actionable-button"
  57. href="#"
  58. @click="openModal({ sector: 'station', modal: 'createPlaylist' })"
  59. >
  60. <i class="material-icons icon-with-button">create</i>
  61. <span class="optional-desktop-only-text"> Create Playlist </span>
  62. </a>
  63. </div>
  64. </template>
  65. <script>
  66. import { mapState, mapActions } from "vuex";
  67. import Toast from "toasters";
  68. import draggable from "vuedraggable";
  69. import io from "../../../../io";
  70. import PlaylistItem from "../../../../components/ui/PlaylistItem.vue";
  71. import SortablePlaylists from "../../../../mixins/SortablePlaylists.vue";
  72. export default {
  73. components: { PlaylistItem, draggable },
  74. mixins: [SortablePlaylists],
  75. data() {
  76. return {
  77. playlists: []
  78. };
  79. },
  80. computed: mapState({
  81. station: state => state.station.station
  82. }),
  83. mounted() {
  84. io.getSocket(socket => {
  85. this.socket = socket;
  86. /** Get playlists for user */
  87. this.socket.emit("playlists.indexMyPlaylists", true, res => {
  88. if (res.status === "success") this.playlists = res.data;
  89. this.orderOfPlaylists = this.calculatePlaylistOrder(); // order in regards to the database
  90. });
  91. this.socket.on("event:playlist.create", playlist => {
  92. this.playlists.push(playlist);
  93. });
  94. this.socket.on("event:playlist.delete", playlistId => {
  95. this.playlists.forEach((playlist, index) => {
  96. if (playlist._id === playlistId) {
  97. this.playlists.splice(index, 1);
  98. }
  99. });
  100. });
  101. this.socket.on("event:playlist.addSong", data => {
  102. this.playlists.forEach((playlist, index) => {
  103. if (playlist._id === data.playlistId) {
  104. this.playlists[index].songs.push(data.song);
  105. }
  106. });
  107. });
  108. this.socket.on("event:playlist.removeSong", data => {
  109. this.playlists.forEach((playlist, index) => {
  110. if (playlist._id === data.playlistId) {
  111. this.playlists[index].songs.forEach((song, index2) => {
  112. if (song.songId === data.songId) {
  113. this.playlists[index].songs.splice(index2, 1);
  114. }
  115. });
  116. }
  117. });
  118. });
  119. this.socket.on("event:playlist.updateDisplayName", data => {
  120. this.playlists.forEach((playlist, index) => {
  121. if (playlist._id === data.playlistId) {
  122. this.playlists[index].displayName = data.displayName;
  123. }
  124. });
  125. });
  126. this.socket.on("event:playlist.updatePrivacy", data => {
  127. this.playlists.forEach((playlist, index) => {
  128. if (playlist._id === data.playlist._id) {
  129. this.playlists[index].privacy = data.playlist.privacy;
  130. }
  131. });
  132. });
  133. this.socket.on(
  134. "event:user.orderOfPlaylists.changed",
  135. orderOfPlaylists => {
  136. const sortedPlaylists = [];
  137. this.playlists.forEach(playlist => {
  138. sortedPlaylists[
  139. orderOfPlaylists.indexOf(playlist._id)
  140. ] = playlist;
  141. });
  142. this.playlists = sortedPlaylists;
  143. this.orderOfPlaylists = this.calculatePlaylistOrder();
  144. }
  145. );
  146. });
  147. },
  148. methods: {
  149. edit(id) {
  150. this.editPlaylist(id);
  151. this.openModal({ sector: "station", modal: "editPlaylist" });
  152. },
  153. selectPlaylist(id) {
  154. this.socket.emit(
  155. "stations.selectPrivatePlaylist",
  156. this.station._id,
  157. id,
  158. res => {
  159. if (res.status === "failure")
  160. return new Toast({
  161. content: res.message,
  162. timeout: 8000
  163. });
  164. return new Toast({ content: res.message, timeout: 4000 });
  165. }
  166. );
  167. },
  168. deselectPlaylist() {
  169. this.socket.emit(
  170. "stations.deselectPrivatePlaylist",
  171. this.station._id,
  172. res => {
  173. if (res.status === "failure")
  174. return new Toast({
  175. content: res.message,
  176. timeout: 8000
  177. });
  178. return new Toast({ content: res.message, timeout: 4000 });
  179. }
  180. );
  181. },
  182. isNotSelected(id) {
  183. // TODO Also change this once it changes for a station
  184. if (this.station && this.station.privatePlaylist === id)
  185. return false;
  186. return true;
  187. },
  188. ...mapActions("modalVisibility", ["openModal"]),
  189. ...mapActions("user/playlists", ["editPlaylist"])
  190. }
  191. };
  192. </script>
  193. <style lang="scss" scoped>
  194. @import "../../../../styles/global.scss";
  195. #my-playlists {
  196. background-color: var(--white);
  197. margin-bottom: 20px;
  198. border-radius: 0 0 5px 5px;
  199. max-height: 100%;
  200. }
  201. .night-mode {
  202. #my-playlists {
  203. background-color: var(--dark-grey-3) !important;
  204. border: 0 !important;
  205. }
  206. .draggable-list-ghost {
  207. filter: brightness(95%);
  208. }
  209. }
  210. .nothing-here-text {
  211. margin-bottom: 10px;
  212. }
  213. .icons-group {
  214. display: flex;
  215. align-items: center;
  216. .edit-icon {
  217. color: var(--station-theme);
  218. }
  219. }
  220. .menu-list .playlist-item:not(:last-of-type) {
  221. margin-bottom: 10px;
  222. }
  223. .create-playlist {
  224. width: 100%;
  225. height: 40px;
  226. border-radius: 5px;
  227. border: 0;
  228. &:active,
  229. &:focus {
  230. border: 0;
  231. }
  232. }
  233. .draggable-list-transition-move {
  234. transition: transform 0.5s;
  235. }
  236. .draggable-list-ghost {
  237. opacity: 0.5;
  238. filter: brightness(95%);
  239. }
  240. </style>