AddSongs.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <template>
  2. <div class="youtube-tab section">
  3. <div>
  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. v-model="musareSearch.query"
  12. @keyup.enter="searchForMusareSongs(1)"
  13. />
  14. </p>
  15. <p class="control">
  16. <a class="button is-info" @click="searchForMusareSongs(1)"
  17. ><i class="material-icons icon-with-button">search</i
  18. >Search</a
  19. >
  20. </p>
  21. </div>
  22. <div
  23. v-if="musareSearch.results.length > 0"
  24. class="song-query-results"
  25. >
  26. <song-item
  27. v-for="(song, index) in musareSearch.results"
  28. :key="song._id"
  29. :song="song"
  30. >
  31. <template #actions>
  32. <transition
  33. name="musare-search-query-actions"
  34. mode="out-in"
  35. >
  36. <i
  37. v-if="song.isAddedToQueue"
  38. class="material-icons added-to-playlist-icon"
  39. content="Song is already in playlist"
  40. v-tippy
  41. >done</i
  42. >
  43. <i
  44. v-else
  45. class="material-icons add-to-playlist-icon"
  46. content="Add Song to Playlist"
  47. v-tippy
  48. @click="
  49. addMusareSongToPlaylist(
  50. song.youtubeId,
  51. index
  52. )
  53. "
  54. >playlist_add</i
  55. >
  56. </transition>
  57. </template>
  58. </song-item>
  59. <button
  60. v-if="resultsLeftCount > 0"
  61. class="button is-primary load-more-button"
  62. @click="searchForMusareSongs(musareSearch.page + 1)"
  63. >
  64. Load {{ nextPageResultsCount }} more results
  65. </button>
  66. </div>
  67. </div>
  68. <br v-if="musareSearch.results.length > 0" />
  69. <div>
  70. <label class="label"> Search for a song from YouTube </label>
  71. <div class="control is-grouped input-with-button">
  72. <p class="control is-expanded">
  73. <input
  74. class="input"
  75. type="text"
  76. placeholder="Enter your YouTube query here..."
  77. v-model="youtubeSearch.songs.query"
  78. autofocus
  79. @keyup.enter="searchForSongs()"
  80. />
  81. </p>
  82. <p class="control">
  83. <button
  84. class="button is-info"
  85. @click.prevent="searchForSongs()"
  86. >
  87. <i class="material-icons icon-with-button">search</i
  88. >Search
  89. </button>
  90. </p>
  91. </div>
  92. <div
  93. v-if="youtubeSearch.songs.results.length > 0"
  94. class="song-query-results"
  95. >
  96. <search-query-item
  97. v-for="(result, index) in youtubeSearch.songs.results"
  98. :key="result.id"
  99. :result="result"
  100. >
  101. <template #actions>
  102. <transition
  103. name="youtube-search-query-actions"
  104. mode="out-in"
  105. >
  106. <i
  107. v-if="result.isAddedToQueue"
  108. class="material-icons added-to-playlist-icon"
  109. content="Song is already in playlist"
  110. v-tippy
  111. >done</i
  112. >
  113. <i
  114. v-else
  115. class="material-icons add-to-playlist-icon"
  116. content="Add Song to Playlist"
  117. v-tippy
  118. @click="
  119. addYouTubeSongToPlaylist(result.id, index)
  120. "
  121. >playlist_add</i
  122. >
  123. </transition>
  124. </template>
  125. </search-query-item>
  126. <button
  127. class="button is-primary load-more-button"
  128. @click.prevent="loadMoreSongs()"
  129. >
  130. Load more...
  131. </button>
  132. </div>
  133. </div>
  134. </div>
  135. </template>
  136. <script>
  137. import { mapState, mapGetters } from "vuex";
  138. import SearchYoutube from "@/mixins/SearchYoutube.vue";
  139. import SearchMusare from "@/mixins/SearchMusare.vue";
  140. import SongItem from "@/components/SongItem.vue";
  141. import SearchQueryItem from "@/components/SearchQueryItem.vue";
  142. export default {
  143. components: { SearchQueryItem, SongItem },
  144. mixins: [SearchYoutube, SearchMusare],
  145. computed: {
  146. ...mapState("modals/editPlaylist", {
  147. playlist: state => state.playlist
  148. }),
  149. ...mapGetters({
  150. socket: "websockets/getSocket"
  151. })
  152. },
  153. watch: {
  154. "youtubeSearch.songs.results": function checkIfSongInPlaylist(songs) {
  155. songs.forEach((searchItem, index) =>
  156. this.playlist.songs.find(song => {
  157. if (song.youtubeId === searchItem.id)
  158. this.youtubeSearch.songs.results[
  159. index
  160. ].isAddedToQueue = true;
  161. return song.youtubeId === searchItem.id;
  162. })
  163. );
  164. },
  165. "musareSearch.results": function checkIfSongInPlaylist(songs) {
  166. songs.forEach((searchItem, index) =>
  167. this.playlist.songs.find(song => {
  168. if (song._id === searchItem._id)
  169. this.musareSearch.results[index].isAddedToQueue = true;
  170. return song._id === searchItem._id;
  171. })
  172. );
  173. },
  174. "playlist.songs": function checkIfSongInPlaylist() {
  175. this.youtubeSearch.songs.results.forEach((searchItem, index) =>
  176. this.playlist.songs.find(song => {
  177. this.youtubeSearch.songs.results[
  178. index
  179. ].isAddedToQueue = false;
  180. if (song.youtubeId === searchItem.id)
  181. this.youtubeSearch.songs.results[
  182. index
  183. ].isAddedToQueue = true;
  184. return song.youtubeId === searchItem.id;
  185. })
  186. );
  187. console.log(222);
  188. this.musareSearch.results.forEach((searchItem, index) =>
  189. this.playlist.songs.find(song => {
  190. this.musareSearch.results[index].isAddedToQueue = false;
  191. if (song.youtubeId === searchItem.youtubeId)
  192. this.musareSearch.results[index].isAddedToQueue = true;
  193. return song.youtubeId === searchItem.youtubeId;
  194. })
  195. );
  196. }
  197. }
  198. };
  199. </script>
  200. <style lang="scss" scoped>
  201. .youtube-tab {
  202. .song-query-results {
  203. margin-top: 10px;
  204. max-width: 565px;
  205. .search-query-item:not(:last-of-type) {
  206. margin-bottom: 10px;
  207. }
  208. }
  209. .load-more-button {
  210. width: 100%;
  211. margin-top: 10px;
  212. }
  213. }
  214. @media screen and (max-width: 1300px) {
  215. .youtube-tab .song-query-results,
  216. .section {
  217. max-width: 100% !important;
  218. }
  219. }
  220. </style>