Playlists.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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. "
  28. @click="selectPlaylist(playlist._id)"
  29. class="material-icons play-icon"
  30. :content="
  31. station.partyMode
  32. ? 'Request songs from this playlist'
  33. : 'Play songs from this playlist'
  34. "
  35. v-tippy
  36. >play_arrow</i
  37. >
  38. <i
  39. v-if="
  40. station.type === 'community' &&
  41. !isNotSelected(playlist._id)
  42. "
  43. @click="deselectPlaylist(playlist._id)"
  44. class="material-icons stop-icon"
  45. :content="
  46. station.partyMode
  47. ? 'Stop requesting songs from this playlist'
  48. : 'Stop playing songs from this playlist'
  49. "
  50. v-tippy
  51. >stop</i
  52. >
  53. <i
  54. @click="edit(playlist._id)"
  55. class="material-icons edit-icon"
  56. content="Edit Playlist"
  57. v-tippy
  58. >edit</i
  59. >
  60. </div>
  61. </playlist-item>
  62. </transition-group>
  63. </draggable>
  64. <p v-else class="nothing-here-text scrollable-list">
  65. No Playlists found
  66. </p>
  67. <a
  68. class="button create-playlist tab-actionable-button"
  69. href="#"
  70. @click="openModal({ sector: 'station', modal: 'createPlaylist' })"
  71. >
  72. <i class="material-icons icon-with-button">create</i>
  73. <span class="optional-desktop-only-text"> Create Playlist </span>
  74. </a>
  75. </div>
  76. </template>
  77. <script>
  78. import { mapState, mapActions, mapGetters } from "vuex";
  79. import Toast from "toasters";
  80. import draggable from "vuedraggable";
  81. import PlaylistItem from "@/components/PlaylistItem.vue";
  82. import SortablePlaylists from "@/mixins/SortablePlaylists.vue";
  83. export default {
  84. components: { PlaylistItem, draggable },
  85. mixins: [SortablePlaylists],
  86. data() {
  87. return {
  88. playlists: []
  89. };
  90. },
  91. computed: {
  92. ...mapState({
  93. station: state => state.station.station,
  94. privatePlaylistQueueSelected: state =>
  95. state.station.privatePlaylistQueueSelected
  96. }),
  97. ...mapGetters({
  98. socket: "websockets/getSocket"
  99. })
  100. },
  101. mounted() {
  102. /** Get playlists for user */
  103. this.socket.dispatch("playlists.indexMyPlaylists", true, res => {
  104. if (res.status === "success") this.playlists = res.data.playlists;
  105. this.orderOfPlaylists = this.calculatePlaylistOrder(); // order in regards to the database
  106. });
  107. this.socket.on("event:playlist.create", playlist => {
  108. this.playlists.push(playlist);
  109. });
  110. this.socket.on("event:playlist.delete", playlistId => {
  111. this.playlists.forEach((playlist, index) => {
  112. if (playlist._id === playlistId) {
  113. this.playlists.splice(index, 1);
  114. }
  115. });
  116. });
  117. this.socket.on("event:playlist.addSong", data => {
  118. this.playlists.forEach((playlist, index) => {
  119. if (playlist._id === data.playlistId) {
  120. this.playlists[index].songs.push(data.song);
  121. }
  122. });
  123. });
  124. this.socket.on("event:playlist.removeSong", data => {
  125. this.playlists.forEach((playlist, index) => {
  126. if (playlist._id === data.playlistId) {
  127. this.playlists[index].songs.forEach((song, index2) => {
  128. if (song.youtubeId === data.youtubeId) {
  129. this.playlists[index].songs.splice(index2, 1);
  130. }
  131. });
  132. }
  133. });
  134. });
  135. this.socket.on("event:playlist.updateDisplayName", data => {
  136. this.playlists.forEach((playlist, index) => {
  137. if (playlist._id === data.playlistId) {
  138. this.playlists[index].displayName = data.displayName;
  139. }
  140. });
  141. });
  142. this.socket.on("event:playlist.updatePrivacy", data => {
  143. this.playlists.forEach((playlist, index) => {
  144. if (playlist._id === data.playlist._id) {
  145. this.playlists[index].privacy = data.playlist.privacy;
  146. }
  147. });
  148. });
  149. this.socket.on(
  150. "event:user.orderOfPlaylists.changed",
  151. orderOfPlaylists => {
  152. const sortedPlaylists = [];
  153. this.playlists.forEach(playlist => {
  154. sortedPlaylists[
  155. orderOfPlaylists.indexOf(playlist._id)
  156. ] = playlist;
  157. });
  158. this.playlists = sortedPlaylists;
  159. this.orderOfPlaylists = this.calculatePlaylistOrder();
  160. }
  161. );
  162. },
  163. methods: {
  164. edit(id) {
  165. this.editPlaylist(id);
  166. this.openModal({ sector: "station", modal: "editPlaylist" });
  167. },
  168. selectPlaylist(id) {
  169. if (this.station.type === "community" && this.station.partyMode) {
  170. if (this.isNotSelected(id)) {
  171. this.updatePrivatePlaylistQueueSelected(id);
  172. this.$parent.$parent.addFirstPrivatePlaylistSongToQueue();
  173. new Toast(
  174. "Successfully selected playlist to auto request songs."
  175. );
  176. } else {
  177. new Toast("Error: Playlist already selected.");
  178. }
  179. } else {
  180. this.socket.dispatch(
  181. "stations.selectPrivatePlaylist",
  182. this.station._id,
  183. id,
  184. res => {
  185. if (res.status === "error") {
  186. new Toast(res.message);
  187. } else {
  188. this.station.includedPlaylists.push(id);
  189. new Toast(res.message);
  190. }
  191. }
  192. );
  193. }
  194. },
  195. deselectPlaylist(id) {
  196. if (this.station.type === "community" && this.station.partyMode) {
  197. this.updatePrivatePlaylistQueueSelected(null);
  198. new Toast("Successfully deselected playlist.");
  199. } else {
  200. this.socket.dispatch(
  201. "stations.deselectPrivatePlaylist",
  202. this.station._id,
  203. id,
  204. res => {
  205. if (res.status === "error")
  206. return new Toast(res.message);
  207. this.station.includedPlaylists.splice(
  208. this.station.includedPlaylists.indexOf(id),
  209. 1
  210. );
  211. return new Toast(res.message);
  212. }
  213. );
  214. }
  215. },
  216. isNotSelected(id) {
  217. if (this.station.type === "community" && this.station.partyMode) {
  218. return this.privatePlaylistQueueSelected !== id;
  219. }
  220. // TODO Also change this once it changes for a station
  221. if (
  222. this.station &&
  223. this.station.includedPlaylists.indexOf(id) !== -1
  224. )
  225. return false;
  226. return true;
  227. },
  228. ...mapActions("station", ["updatePrivatePlaylistQueueSelected"]),
  229. ...mapActions("modalVisibility", ["openModal"]),
  230. ...mapActions("user/playlists", ["editPlaylist"])
  231. }
  232. };
  233. </script>
  234. <style lang="scss" scoped>
  235. #my-playlists {
  236. background-color: var(--white);
  237. margin-bottom: 20px;
  238. border-radius: 0 0 5px 5px;
  239. max-height: 100%;
  240. }
  241. .night-mode {
  242. #my-playlists {
  243. background-color: var(--dark-grey-3) !important;
  244. border: 0 !important;
  245. }
  246. .draggable-list-ghost {
  247. filter: brightness(95%);
  248. }
  249. }
  250. .nothing-here-text {
  251. margin-bottom: 10px;
  252. }
  253. .icons-group {
  254. display: flex;
  255. align-items: center;
  256. .edit-icon {
  257. color: var(--primary-color);
  258. }
  259. }
  260. .menu-list .playlist-item:not(:last-of-type) {
  261. margin-bottom: 10px;
  262. }
  263. .create-playlist {
  264. width: 100%;
  265. height: 40px;
  266. border-radius: 5px;
  267. border: 0;
  268. &:active,
  269. &:focus {
  270. border: 0;
  271. }
  272. }
  273. .draggable-list-transition-move {
  274. transition: transform 0.5s;
  275. }
  276. .draggable-list-ghost {
  277. opacity: 0.5;
  278. filter: brightness(95%);
  279. }
  280. </style>