AddSongs.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. <a
  84. class="button is-info"
  85. @click.prevent="searchForSongs()"
  86. href="#"
  87. ><i class="material-icons icon-with-button">search</i
  88. >Search</a
  89. >
  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. <a
  127. class="button is-primary load-more-button"
  128. @click.prevent="loadMoreSongs()"
  129. href="#"
  130. >
  131. Load more...
  132. </a>
  133. </div>
  134. </div>
  135. </div>
  136. </template>
  137. <script>
  138. import { mapState, mapGetters } from "vuex";
  139. import SearchYoutube from "@/mixins/SearchYoutube.vue";
  140. import SearchMusare from "@/mixins/SearchMusare.vue";
  141. import SongItem from "@/components/SongItem.vue";
  142. import SearchQueryItem from "@/components/SearchQueryItem.vue";
  143. export default {
  144. components: { SearchQueryItem, SongItem },
  145. mixins: [SearchYoutube, SearchMusare],
  146. computed: {
  147. ...mapState("modals/editPlaylist", {
  148. playlist: state => state.playlist
  149. }),
  150. ...mapGetters({
  151. socket: "websockets/getSocket"
  152. })
  153. },
  154. watch: {
  155. "youtubeSearch.songs.results": function checkIfSongInPlaylist(songs) {
  156. songs.forEach((searchItem, index) =>
  157. this.playlist.songs.find(song => {
  158. if (song.youtubeId === searchItem.id)
  159. this.youtubeSearch.songs.results[
  160. index
  161. ].isAddedToQueue = true;
  162. return song.youtubeId === searchItem.id;
  163. })
  164. );
  165. },
  166. "musareSearch.results": function checkIfSongInPlaylist(songs) {
  167. songs.forEach((searchItem, index) =>
  168. this.playlist.songs.find(song => {
  169. if (song._id === searchItem._id)
  170. this.musareSearch.results[index].isAddedToQueue = true;
  171. return song._id === searchItem._id;
  172. })
  173. );
  174. },
  175. "playlist.songs": function checkIfSongInPlaylist() {
  176. this.youtubeSearch.songs.results.forEach((searchItem, index) =>
  177. this.playlist.songs.find(song => {
  178. this.youtubeSearch.songs.results[
  179. index
  180. ].isAddedToQueue = false;
  181. if (song.youtubeId === searchItem.id)
  182. this.youtubeSearch.songs.results[
  183. index
  184. ].isAddedToQueue = true;
  185. return song.youtubeId === searchItem.id;
  186. })
  187. );
  188. console.log(222);
  189. this.musareSearch.results.forEach((searchItem, index) =>
  190. this.playlist.songs.find(song => {
  191. this.musareSearch.results[index].isAddedToQueue = false;
  192. if (song.youtubeId === searchItem.youtubeId)
  193. this.musareSearch.results[index].isAddedToQueue = true;
  194. return song.youtubeId === searchItem.youtubeId;
  195. })
  196. );
  197. }
  198. }
  199. };
  200. </script>
  201. <style lang="scss" scoped>
  202. .youtube-tab {
  203. .song-query-results {
  204. padding: 10px;
  205. margin-top: 10px;
  206. border: 1px solid var(--light-grey-3);
  207. border-radius: 3px;
  208. max-width: 565px;
  209. max-height: 500px;
  210. overflow: auto;
  211. .search-query-item:not(:last-of-type) {
  212. margin-bottom: 10px;
  213. }
  214. }
  215. .load-more-button {
  216. width: 100%;
  217. margin-top: 10px;
  218. }
  219. }
  220. @media screen and (max-width: 1300px) {
  221. .youtube-tab .song-query-results,
  222. .section {
  223. max-width: 100% !important;
  224. }
  225. }
  226. </style>