YoutubeSearch.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <div class="youtube-search">
  3. <label class="label"> Search for a song from YouTube </label>
  4. <div class="control is-grouped input-with-button">
  5. <p class="control is-expanded">
  6. <input
  7. class="input"
  8. type="text"
  9. placeholder="Enter your YouTube query here..."
  10. v-model="search.songs.query"
  11. autofocus
  12. @keyup.enter="searchForSongs()"
  13. />
  14. </p>
  15. <p class="control">
  16. <a
  17. class="button is-info"
  18. @click.prevent="searchForSongs()"
  19. href="#"
  20. ><i class="material-icons icon-with-button">search</i
  21. >Search</a
  22. >
  23. </p>
  24. </div>
  25. <div v-if="search.songs.results.length > 0" id="song-query-results">
  26. <search-query-item
  27. v-for="(result, index) in search.songs.results"
  28. :key="index"
  29. :result="result"
  30. >
  31. <div slot="actions">
  32. <transition name="search-query-actions" mode="out-in">
  33. <a
  34. class="button is-success"
  35. v-if="result.isAddedToQueue"
  36. href="#"
  37. key="added-to-queue"
  38. >
  39. <i class="material-icons icon-with-button">done</i>
  40. Added to queue
  41. </a>
  42. <a
  43. class="button is-dark"
  44. v-else
  45. @click.prevent="addSongToQueue(result.id, index)"
  46. href="#"
  47. key="add-to-queue"
  48. >
  49. <i class="material-icons icon-with-button">add</i>
  50. Add to queue
  51. </a>
  52. </transition>
  53. </div>
  54. </search-query-item>
  55. <a
  56. class="button is-default load-more-button"
  57. @click.prevent="loadMoreSongs()"
  58. href="#"
  59. >
  60. Load more...
  61. </a>
  62. </div>
  63. </div>
  64. </template>
  65. <script>
  66. import { mapState, mapGetters } from "vuex";
  67. import Toast from "toasters";
  68. import SearchYoutube from "@/mixins/SearchYoutube.vue";
  69. import SearchQueryItem from "../../../SearchQueryItem.vue";
  70. export default {
  71. components: {
  72. SearchQueryItem
  73. },
  74. mixins: [SearchYoutube],
  75. computed: {
  76. ...mapState("modals/editStation", {
  77. station: state => state.station,
  78. originalStation: state => state.originalStation
  79. }),
  80. ...mapGetters({
  81. socket: "websockets/getSocket"
  82. })
  83. },
  84. methods: {
  85. addSongToQueue(youtubeId, index) {
  86. if (this.station.type === "community") {
  87. this.socket.dispatch(
  88. "stations.addToQueue",
  89. this.station._id,
  90. youtubeId,
  91. data => {
  92. if (data.status !== "success")
  93. new Toast(`Error: ${data.message}`);
  94. else {
  95. this.search.songs.results[
  96. index
  97. ].isAddedToQueue = true;
  98. new Toast(data.message);
  99. }
  100. }
  101. );
  102. } else {
  103. this.socket.dispatch("songs.request", youtubeId, data => {
  104. if (data.status !== "success")
  105. new Toast(`Error: ${data.message}`);
  106. else {
  107. this.search.songs.results[index].isAddedToQueue = true;
  108. new Toast(data.message);
  109. }
  110. });
  111. }
  112. }
  113. }
  114. };
  115. </script>