Playlists.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <div class="content playlists-tab">
  3. <div v-if="playlists.length > 0">
  4. <h4 class="section-title">
  5. {{ myUserId === userId ? "My" : null }}
  6. Playlists
  7. </h4>
  8. <p class="section-description">
  9. View
  10. {{
  11. userId === myUserId
  12. ? "and manage your personal"
  13. : `${username}'s`
  14. }}
  15. playlists
  16. </p>
  17. <hr class="section-horizontal-rule" />
  18. <draggable
  19. tag="transition-group"
  20. :component-data="{
  21. name: !drag ? 'draggable-list-transition' : null
  22. }"
  23. v-if="playlists.length > 0"
  24. v-model="playlists"
  25. item-key="_id"
  26. v-bind="dragOptions"
  27. @start="drag = true"
  28. @end="drag = false"
  29. @change="savePlaylistOrder"
  30. >
  31. <template #item="{ element }">
  32. <playlist-item
  33. v-if="
  34. element.privacy === 'public' ||
  35. (element.privacy === 'private' &&
  36. element.createdBy === userId)
  37. "
  38. :playlist="element"
  39. :class="{
  40. item: true,
  41. 'item-draggable': myUserId === userId
  42. }"
  43. >
  44. <template #actions>
  45. <i
  46. v-if="myUserId === userId"
  47. @click="
  48. openModal({
  49. modal: 'editPlaylist',
  50. data: { playlistId: element._id }
  51. })
  52. "
  53. class="material-icons edit-icon"
  54. content="Edit Playlist"
  55. v-tippy
  56. >edit</i
  57. >
  58. <i
  59. v-else
  60. @click="
  61. openModal({
  62. modal: 'editPlaylist',
  63. data: { playlistId: element._id }
  64. })
  65. "
  66. class="material-icons view-icon"
  67. content="View Playlist"
  68. v-tippy
  69. >visibility</i
  70. >
  71. </template>
  72. </playlist-item>
  73. </template>
  74. </draggable>
  75. <button
  76. v-if="myUserId === userId"
  77. class="button is-primary"
  78. id="create-new-playlist-button"
  79. @click="openModal('createPlaylist')"
  80. >
  81. Create new playlist
  82. </button>
  83. </div>
  84. <div v-else>
  85. <h5>No playlists here.</h5>
  86. </div>
  87. </div>
  88. </template>
  89. <script>
  90. import { mapActions, mapGetters } from "vuex";
  91. import PlaylistItem from "@/components/PlaylistItem.vue";
  92. import SortablePlaylists from "@/mixins/SortablePlaylists.vue";
  93. import ws from "@/ws";
  94. export default {
  95. components: {
  96. PlaylistItem
  97. },
  98. mixins: [SortablePlaylists],
  99. props: {
  100. userId: {
  101. type: String,
  102. default: ""
  103. },
  104. username: {
  105. type: String,
  106. default: ""
  107. }
  108. },
  109. computed: {
  110. ...mapGetters({
  111. socket: "websockets/getSocket"
  112. })
  113. },
  114. mounted() {
  115. if (
  116. this.$route.query.tab === "recent-activity" ||
  117. this.$route.query.tab === "playlists"
  118. )
  119. this.tab = this.$route.query.tab;
  120. if (this.myUserId !== this.userId) {
  121. ws.onConnect(() =>
  122. this.socket.dispatch(
  123. "apis.joinRoom",
  124. `profile.${this.userId}.playlists`,
  125. () => {}
  126. )
  127. );
  128. }
  129. ws.onConnect(() =>
  130. this.socket.dispatch("playlists.indexForUser", this.userId, res => {
  131. if (res.status === "success")
  132. this.setPlaylists(res.data.playlists);
  133. this.orderOfPlaylists = this.calculatePlaylistOrder(); // order in regards to the database
  134. })
  135. );
  136. },
  137. beforeUnmount() {
  138. this.socket.dispatch(
  139. "apis.leaveRoom",
  140. `profile.${this.userId}.playlists`,
  141. () => {}
  142. );
  143. },
  144. methods: {
  145. ...mapActions("modalVisibility", ["openModal"]),
  146. ...mapActions("user/playlists", ["setPlaylists"])
  147. }
  148. };
  149. </script>