Playlists.vue 2.5 KB

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