Search.vue 3.3 KB

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