Playlists.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <script setup lang="ts">
  2. import { defineAsyncComponent, onMounted } from "vue";
  3. import { useSortablePlaylists } from "@/composables/useSortablePlaylists";
  4. import { useModalsStore } from "@/stores/modals";
  5. const PlaylistItem = defineAsyncComponent(
  6. () => import("@/components/PlaylistItem.vue")
  7. );
  8. const props = defineProps({
  9. userId: { type: String, default: "" },
  10. username: { type: String, default: "" }
  11. });
  12. const { Draggable, drag, userId, isCurrentUser, playlists, savePlaylistOrder } =
  13. useSortablePlaylists();
  14. const { openModal } = useModalsStore();
  15. onMounted(() => {
  16. userId.value = props.userId;
  17. });
  18. </script>
  19. <template>
  20. <div class="content playlists-tab">
  21. <div v-if="playlists.length > 0">
  22. <h4 class="section-title">
  23. {{ isCurrentUser ? "My" : null }}
  24. Playlists
  25. </h4>
  26. <p class="section-description">
  27. View
  28. {{
  29. isCurrentUser ? "and manage your personal" : `${username}'s`
  30. }}
  31. playlists
  32. </p>
  33. <hr class="section-horizontal-rule" />
  34. <draggable
  35. :component-data="{
  36. name: !drag ? 'draggable-list-transition' : null
  37. }"
  38. name="profile-playlists"
  39. v-if="playlists.length > 0"
  40. v-model:list="playlists"
  41. item-key="_id"
  42. @start="drag = true"
  43. @end="drag = false"
  44. @update="savePlaylistOrder"
  45. >
  46. <template #item="{ element }">
  47. <playlist-item
  48. v-if="
  49. element.privacy === 'public' ||
  50. (element.privacy === 'private' &&
  51. element.createdBy === userId)
  52. "
  53. :playlist="element"
  54. :class="{
  55. 'is-draggable': isCurrentUser
  56. }"
  57. >
  58. <template #actions>
  59. <i
  60. v-if="isCurrentUser"
  61. @click="
  62. openModal({
  63. modal: 'editPlaylist',
  64. data: { playlistId: element._id }
  65. })
  66. "
  67. class="material-icons edit-icon"
  68. content="Edit Playlist"
  69. v-tippy
  70. >edit</i
  71. >
  72. <i
  73. v-else
  74. @click="
  75. openModal({
  76. modal: 'editPlaylist',
  77. data: { playlistId: element._id }
  78. })
  79. "
  80. class="material-icons view-icon"
  81. content="View Playlist"
  82. v-tippy
  83. >visibility</i
  84. >
  85. </template>
  86. </playlist-item>
  87. </template>
  88. </draggable>
  89. <button
  90. v-if="isCurrentUser"
  91. class="button is-primary"
  92. id="create-new-playlist-button"
  93. @click="openModal('createPlaylist')"
  94. >
  95. Create new playlist
  96. </button>
  97. </div>
  98. <div v-else>
  99. <h5>No playlists here.</h5>
  100. </div>
  101. </div>
  102. </template>