Playlists.vue 2.3 KB

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