MyPlaylists.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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(playlist._id)"
  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, mapGetters } from "vuex";
  67. import Toast from "toasters";
  68. import draggable from "vuedraggable";
  69. import PlaylistItem from "../../../../components/ui/PlaylistItem.vue";
  70. import SortablePlaylists from "../../../../mixins/SortablePlaylists.vue";
  71. export default {
  72. components: { PlaylistItem, draggable },
  73. mixins: [SortablePlaylists],
  74. data() {
  75. return {
  76. playlists: []
  77. };
  78. },
  79. computed: {
  80. ...mapState({
  81. station: state => state.station.station
  82. }),
  83. ...mapGetters({
  84. socket: "websockets/getSocket"
  85. })
  86. },
  87. mounted() {
  88. /** Get playlists for user */
  89. this.socket.dispatch("playlists.indexMyPlaylists", true, res => {
  90. if (res.status === "success") this.playlists = res.data;
  91. this.orderOfPlaylists = this.calculatePlaylistOrder(); // order in regards to the database
  92. });
  93. this.socket.on("event:playlist.create", playlist => {
  94. this.playlists.push(playlist);
  95. });
  96. this.socket.on("event:playlist.delete", playlistId => {
  97. this.playlists.forEach((playlist, index) => {
  98. if (playlist._id === playlistId) {
  99. this.playlists.splice(index, 1);
  100. }
  101. });
  102. });
  103. this.socket.on("event:playlist.addSong", data => {
  104. this.playlists.forEach((playlist, index) => {
  105. if (playlist._id === data.playlistId) {
  106. this.playlists[index].songs.push(data.song);
  107. }
  108. });
  109. });
  110. this.socket.on("event:playlist.removeSong", data => {
  111. this.playlists.forEach((playlist, index) => {
  112. if (playlist._id === data.playlistId) {
  113. this.playlists[index].songs.forEach((song, index2) => {
  114. if (song.songId === data.songId) {
  115. this.playlists[index].songs.splice(index2, 1);
  116. }
  117. });
  118. }
  119. });
  120. });
  121. this.socket.on("event:playlist.updateDisplayName", data => {
  122. this.playlists.forEach((playlist, index) => {
  123. if (playlist._id === data.playlistId) {
  124. this.playlists[index].displayName = data.displayName;
  125. }
  126. });
  127. });
  128. this.socket.on("event:playlist.updatePrivacy", data => {
  129. this.playlists.forEach((playlist, index) => {
  130. if (playlist._id === data.playlist._id) {
  131. this.playlists[index].privacy = data.playlist.privacy;
  132. }
  133. });
  134. });
  135. this.socket.on(
  136. "event:user.orderOfPlaylists.changed",
  137. orderOfPlaylists => {
  138. const sortedPlaylists = [];
  139. this.playlists.forEach(playlist => {
  140. sortedPlaylists[
  141. orderOfPlaylists.indexOf(playlist._id)
  142. ] = playlist;
  143. });
  144. this.playlists = sortedPlaylists;
  145. this.orderOfPlaylists = this.calculatePlaylistOrder();
  146. }
  147. );
  148. },
  149. methods: {
  150. edit(id) {
  151. this.editPlaylist(id);
  152. this.openModal({ sector: "station", modal: "editPlaylist" });
  153. },
  154. selectPlaylist(id) {
  155. this.socket.dispatch(
  156. "stations.selectPrivatePlaylist",
  157. this.station._id,
  158. id,
  159. res => {
  160. if (res.status === "failure")
  161. return new Toast({
  162. content: res.message,
  163. timeout: 8000
  164. });
  165. return new Toast({ content: res.message, timeout: 4000 });
  166. }
  167. );
  168. },
  169. deselectPlaylist(id) {
  170. this.socket.dispatch(
  171. "stations.deselectPrivatePlaylist",
  172. this.station._id,
  173. id,
  174. res => {
  175. if (res.status === "failure")
  176. return new Toast({
  177. content: res.message,
  178. timeout: 8000
  179. });
  180. return new Toast({ content: res.message, timeout: 4000 });
  181. }
  182. );
  183. },
  184. isNotSelected(id) {
  185. // TODO Also change this once it changes for a station
  186. if (
  187. this.station &&
  188. this.station.includedPlaylists.indexOf(id) !== -1
  189. )
  190. return false;
  191. return true;
  192. },
  193. ...mapActions("modalVisibility", ["openModal"]),
  194. ...mapActions("user/playlists", ["editPlaylist"])
  195. }
  196. };
  197. </script>
  198. <style lang="scss" scoped>
  199. #my-playlists {
  200. background-color: var(--white);
  201. margin-bottom: 20px;
  202. border-radius: 0 0 5px 5px;
  203. max-height: 100%;
  204. }
  205. .night-mode {
  206. #my-playlists {
  207. background-color: var(--dark-grey-3) !important;
  208. border: 0 !important;
  209. }
  210. .draggable-list-ghost {
  211. filter: brightness(95%);
  212. }
  213. }
  214. .nothing-here-text {
  215. margin-bottom: 10px;
  216. }
  217. .icons-group {
  218. display: flex;
  219. align-items: center;
  220. .edit-icon {
  221. color: var(--primary-color);
  222. }
  223. }
  224. .menu-list .playlist-item:not(:last-of-type) {
  225. margin-bottom: 10px;
  226. }
  227. .create-playlist {
  228. width: 100%;
  229. height: 40px;
  230. border-radius: 5px;
  231. border: 0;
  232. &:active,
  233. &:focus {
  234. border: 0;
  235. }
  236. }
  237. .draggable-list-transition-move {
  238. transition: transform 0.5s;
  239. }
  240. .draggable-list-ghost {
  241. opacity: 0.5;
  242. filter: brightness(95%);
  243. }
  244. </style>