Playlists.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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. !isSelected(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. isSelected(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("station", {
  93. station: state => state.station,
  94. privatePlaylistQueueSelected: state =>
  95. state.privatePlaylistQueueSelected,
  96. includedPlaylists: state => state.includedPlaylists,
  97. excludedPlaylists: state => state.excludedPlaylists
  98. }),
  99. ...mapGetters({
  100. socket: "websockets/getSocket"
  101. })
  102. },
  103. mounted() {
  104. /** Get playlists for user */
  105. this.socket.dispatch("playlists.indexMyPlaylists", true, res => {
  106. if (res.status === "success") this.playlists = res.data.playlists;
  107. this.orderOfPlaylists = this.calculatePlaylistOrder(); // order in regards to the database
  108. });
  109. this.socket.on("event:playlist.create", res => {
  110. this.playlists.push(res.data.playlist);
  111. });
  112. this.socket.on("event:playlist.delete", res => {
  113. this.playlists.forEach((playlist, index) => {
  114. if (playlist._id === res.data.playlistId) {
  115. this.playlists.splice(index, 1);
  116. }
  117. });
  118. });
  119. this.socket.on("event:playlist.addSong", res => {
  120. this.playlists.forEach((playlist, index) => {
  121. if (playlist._id === res.data.playlistId) {
  122. this.playlists[index].songs.push(res.data.song);
  123. }
  124. });
  125. });
  126. this.socket.on("event:playlist.removeSong", res => {
  127. this.playlists.forEach((playlist, index) => {
  128. if (playlist._id === res.data.playlistId) {
  129. this.playlists[index].songs.forEach((song, index2) => {
  130. if (song.youtubeId === res.data.youtubeId) {
  131. this.playlists[index].songs.splice(index2, 1);
  132. }
  133. });
  134. }
  135. });
  136. });
  137. this.socket.on("event:playlist.updateDisplayName", res => {
  138. this.playlists.forEach((playlist, index) => {
  139. if (playlist._id === res.data.playlistId) {
  140. this.playlists[index].displayName = res.data.displayName;
  141. }
  142. });
  143. });
  144. this.socket.on("event:playlist.updatePrivacy", res => {
  145. this.playlists.forEach((playlist, index) => {
  146. if (playlist._id === res.data.playlist._id) {
  147. this.playlists[index].privacy = res.data.playlist.privacy;
  148. }
  149. });
  150. });
  151. this.socket.on(
  152. "event:user.orderOfPlaylists.changed",
  153. orderOfPlaylists => {
  154. const sortedPlaylists = [];
  155. this.playlists.forEach(playlist => {
  156. sortedPlaylists[
  157. orderOfPlaylists.indexOf(playlist._id)
  158. ] = playlist;
  159. });
  160. this.playlists = sortedPlaylists;
  161. this.orderOfPlaylists = this.calculatePlaylistOrder();
  162. }
  163. );
  164. },
  165. methods: {
  166. edit(id) {
  167. this.editPlaylist(id);
  168. this.openModal({ sector: "station", modal: "editPlaylist" });
  169. },
  170. selectPlaylist(id) {
  171. if (this.station.type === "community" && this.station.partyMode) {
  172. new Toast(
  173. "Error: Party mode playlist selection not added yet."
  174. );
  175. } else {
  176. this.socket.dispatch(
  177. "stations.includePlaylist",
  178. this.station._id,
  179. id,
  180. res => {
  181. new Toast(res.message);
  182. }
  183. );
  184. }
  185. },
  186. deselectPlaylist(id) {
  187. if (this.station.type === "community" && this.station.partyMode) {
  188. new Toast(
  189. "Error: Party mode playlist selection not added yet."
  190. );
  191. } else {
  192. this.socket.dispatch(
  193. "stations.removeIncludedPlaylist",
  194. this.station._id,
  195. id,
  196. res => {
  197. new Toast(res.message);
  198. }
  199. );
  200. }
  201. },
  202. isSelected(id) {
  203. if (this.station.type === "community" && this.station.partyMode) {
  204. // Party mode playlist selection not added yet.
  205. return false;
  206. }
  207. // TODO Also change this once it changes for a station
  208. let selected = false;
  209. this.includedPlaylists.forEach(playlist => {
  210. if (playlist._id === id) selected = true;
  211. });
  212. return selected;
  213. },
  214. ...mapActions("station", ["updatePrivatePlaylistQueueSelected"]),
  215. ...mapActions("modalVisibility", ["openModal"]),
  216. ...mapActions("user/playlists", ["editPlaylist"])
  217. }
  218. };
  219. </script>
  220. <style lang="scss" scoped>
  221. #my-playlists {
  222. background-color: var(--white);
  223. margin-bottom: 20px;
  224. border-radius: 0 0 5px 5px;
  225. max-height: 100%;
  226. }
  227. .night-mode {
  228. #my-playlists {
  229. background-color: var(--dark-grey-3) !important;
  230. border: 0 !important;
  231. }
  232. .draggable-list-ghost {
  233. filter: brightness(95%);
  234. }
  235. }
  236. .nothing-here-text {
  237. margin-bottom: 10px;
  238. }
  239. .icons-group {
  240. display: flex;
  241. align-items: center;
  242. .edit-icon {
  243. color: var(--primary-color);
  244. }
  245. }
  246. .menu-list .playlist-item:not(:last-of-type) {
  247. margin-bottom: 10px;
  248. }
  249. .create-playlist {
  250. width: 100%;
  251. height: 40px;
  252. border-radius: 5px;
  253. border: 0;
  254. &:active,
  255. &:focus {
  256. border: 0;
  257. }
  258. }
  259. .draggable-list-transition-move {
  260. transition: transform 0.5s;
  261. }
  262. .draggable-list-ghost {
  263. opacity: 0.5;
  264. filter: brightness(95%);
  265. }
  266. </style>