AddSongToPlaylist.vue 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <modal title='Add Song To Playlist'>
  3. <div slot='body'>
  4. <aside class="menu">
  5. <p class="menu-label">
  6. Playlists
  7. </p>
  8. <ul class="menu-list">
  9. <li v-for='playlist in playlists'>
  10. <div class='playlist'>
  11. <span class='icon is-small' @click='removeSongFromPlaylist(playlist._id)' v-if='playlistContains(playlist._id)'>
  12. <i class="material-icons">playlist_add_check</i>
  13. </span>
  14. <span class='icon is-small' @click='addSongToPlaylist(playlist._id)' v-else>
  15. <i class="material-icons">playlist_add</i>
  16. </span>
  17. {{ playlist.displayName }}
  18. </div>
  19. </li>
  20. </ul>
  21. </aside>
  22. </div>
  23. </modal>
  24. </template>
  25. <script>
  26. import { Toast } from 'vue-roaster';
  27. import Modal from './Modal.vue';
  28. import io from '../../io';
  29. import auth from '../../auth';
  30. export default {
  31. data() {
  32. return {
  33. playlists: {}
  34. }
  35. },
  36. methods: {
  37. playlistContains: function (playlistId) {
  38. let _this = this;
  39. let toReturn = false;
  40. let playlist = this.playlists.filter(playlist => {
  41. return playlist._id === playlistId;
  42. })[0];
  43. for (let i = 0; i < playlist.songs.length; i++) {
  44. if (playlist.songs[i].songId === _this.$parent.currentSong.songId) {
  45. toReturn = true;
  46. }
  47. }
  48. return toReturn;
  49. },
  50. addSongToPlaylist: function (playlistId) {
  51. let _this = this;
  52. this.socket.emit('playlists.addSongToPlaylist', this.$parent.currentSong.songId, playlistId, res => {
  53. Toast.methods.addToast(res.message, 4000);
  54. this.$parent.modals.addSongToPlaylist = false;
  55. });
  56. },
  57. removeSongFromPlaylist: function (playlistId) {
  58. let _this = this;
  59. this.socket.emit('playlists.removeSongFromPlaylist', this.$parent.currentSong.songId, playlistId, res => {
  60. Toast.methods.addToast(res.message, 4000);
  61. this.$parent.modals.addSongToPlaylist = false;
  62. });
  63. }
  64. },
  65. ready: function () {
  66. let _this = this;
  67. io.getSocket((socket) => {
  68. _this.socket = socket;
  69. _this.socket.emit('playlists.indexForUser', res => {
  70. if (res.status === 'success') _this.playlists = res.data;
  71. });
  72. });
  73. },
  74. events: {
  75. closeModal: function () {
  76. this.$parent.modals.addSongToPlaylist = !this.$parent.modals.addSongToPlaylist;
  77. }
  78. },
  79. components: { Modal }
  80. }
  81. </script>
  82. <style type='scss' scoped>
  83. .icon.is-small {
  84. margin-right: 10px !important;
  85. }
  86. </style>