Youtube.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <script setup lang="ts">
  2. import { storeToRefs } from "pinia";
  3. import { useEditSongStore } from "@/stores/editSong";
  4. import { useSearchYoutube } from "@/composables/useSearchYoutube";
  5. import SearchQueryItem from "../../../SearchQueryItem.vue";
  6. const props = defineProps({
  7. modalUuid: { type: String, required: true },
  8. modalModulePath: { type: String, default: "modals/editSong/MODAL_UUID" }
  9. });
  10. const editSongStore = useEditSongStore({ modalUuid: props.modalUuid });
  11. const { form, newSong } = storeToRefs(editSongStore);
  12. const { updateYoutubeId } = editSongStore;
  13. const { youtubeSearch, searchForSongs, loadMoreSongs } = useSearchYoutube();
  14. const selectSong = result => {
  15. updateYoutubeId(result.id);
  16. if (newSong)
  17. form.value.setValue({
  18. title: result.title,
  19. thumbnail: result.thumbnail
  20. });
  21. };
  22. </script>
  23. <template>
  24. <div class="youtube-tab">
  25. <label class="label"> Search for a song from YouTube </label>
  26. <div class="control is-grouped input-with-button">
  27. <p class="control is-expanded">
  28. <input
  29. class="input"
  30. type="text"
  31. placeholder="Enter your YouTube query here..."
  32. v-model="youtubeSearch.songs.query"
  33. autofocus
  34. @keyup.enter="searchForSongs()"
  35. />
  36. </p>
  37. <p class="control">
  38. <button
  39. class="button is-info"
  40. @click.prevent="searchForSongs()"
  41. >
  42. <i class="material-icons icon-with-button">search</i>Search
  43. </button>
  44. </p>
  45. </div>
  46. <div
  47. v-if="youtubeSearch.songs.results.length > 0"
  48. id="song-query-results"
  49. >
  50. <search-query-item
  51. v-for="result in youtubeSearch.songs.results"
  52. :key="result.id"
  53. :result="result"
  54. >
  55. <template #actions>
  56. <i
  57. class="material-icons icon-selected"
  58. v-if="result.id === form.inputs.youtubeId.value"
  59. key="selected"
  60. >radio_button_checked
  61. </i>
  62. <i
  63. class="material-icons icon-not-selected"
  64. v-else
  65. @click.prevent="selectSong(result)"
  66. key="not-selected"
  67. >radio_button_unchecked
  68. </i>
  69. </template>
  70. </search-query-item>
  71. <button
  72. class="button is-primary load-more-button"
  73. @click.prevent="loadMoreSongs()"
  74. >
  75. Load more...
  76. </button>
  77. </div>
  78. </div>
  79. </template>
  80. <style lang="less" scoped>
  81. .youtube-tab #song-query-results {
  82. height: calc(100% - 74px);
  83. overflow: auto;
  84. .search-query-item {
  85. .icon-selected {
  86. color: var(--green) !important;
  87. }
  88. .icon-not-selected {
  89. color: var(--grey) !important;
  90. }
  91. }
  92. .search-query-item:not(:last-of-type) {
  93. margin-bottom: 10px;
  94. }
  95. .load-more-button {
  96. width: 100%;
  97. margin-top: 10px;
  98. }
  99. }
  100. </style>