AddSongs.vue 5.4 KB

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