Youtube.vue 2.7 KB

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