Request.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. <script setup lang="ts">
  2. import { defineAsyncComponent, ref, computed, onMounted, watch } from "vue";
  3. import Toast from "toasters";
  4. import { useWebsocketsStore } from "@/stores/websockets";
  5. import { useConfigStore } from "@/stores/config";
  6. import { useStationStore } from "@/stores/station";
  7. import { useManageStationStore } from "@/stores/manageStation";
  8. import { useSearchYoutube } from "@/composables/useSearchYoutube";
  9. import { useSearchMusare } from "@/composables/useSearchMusare";
  10. import { useYoutubeDirect } from "@/composables/useYoutubeDirect";
  11. import { useSoundcloudDirect } from "@/composables/useSoundcloudDirect";
  12. const SongItem = defineAsyncComponent(
  13. () => import("@/components/SongItem.vue")
  14. );
  15. const SearchQueryItem = defineAsyncComponent(
  16. () => import("@/components/SearchQueryItem.vue")
  17. );
  18. const PlaylistTabBase = defineAsyncComponent(
  19. () => import("@/components/PlaylistTabBase.vue")
  20. );
  21. const props = defineProps({
  22. modalUuid: { type: String, default: null },
  23. sector: { type: String, default: "station" },
  24. disableAutoRequest: { type: Boolean, default: false }
  25. });
  26. const { youtubeSearch, searchForSongs, loadMoreSongs } = useSearchYoutube();
  27. const { musareSearch, searchForMusareSongs } = useSearchMusare();
  28. const { youtubeDirect, addToQueue } = useYoutubeDirect();
  29. const { soundcloudDirect, addToQueue: soundcloudAddToQueue } =
  30. useSoundcloudDirect();
  31. const { socket } = useWebsocketsStore();
  32. const configStore = useConfigStore();
  33. const stationStore = useStationStore();
  34. const manageStationStore = useManageStationStore({
  35. modalUuid: props.modalUuid
  36. });
  37. const tab = ref("songs");
  38. const tabs = ref({});
  39. const station = computed({
  40. get() {
  41. if (props.sector === "manageStation") return manageStationStore.station;
  42. return stationStore.station;
  43. },
  44. set(value) {
  45. if (props.sector === "manageStation")
  46. manageStationStore.updateStation(value);
  47. else stationStore.updateStation(value);
  48. }
  49. });
  50. // const blacklist = computed({
  51. // get() {
  52. // if (props.sector === "manageStation") return manageStationStore.blacklist;
  53. // return stationStore.blacklist;
  54. // },
  55. // set(value) {
  56. // if (props.sector === "manageStation")
  57. // manageStationStore.setBlacklist(value);
  58. // else stationStore.setBlacklist(value);
  59. // }
  60. // });
  61. const songsList = computed({
  62. get() {
  63. if (props.sector === "manageStation")
  64. return manageStationStore.songsList;
  65. return stationStore.songsList;
  66. },
  67. set(value) {
  68. if (props.sector === "manageStation")
  69. manageStationStore.updateSongsList(value);
  70. else stationStore.updateSongsList(value);
  71. }
  72. });
  73. const musareResultsLeftCount = computed(
  74. () => musareSearch.value.count - musareSearch.value.results.length
  75. );
  76. const nextPageMusareResultsCount = computed(() =>
  77. Math.min(musareSearch.value.pageSize, musareResultsLeftCount.value)
  78. );
  79. const songsInQueue = computed(() => {
  80. if (station.value.currentSong)
  81. return songsList.value
  82. .map(song => song.mediaSource)
  83. .concat(station.value.currentSong.mediaSource);
  84. return songsList.value.map(song => song.mediaSource);
  85. });
  86. // const currentUserQueueSongs = computed(
  87. // () =>
  88. // songsList.value.filter(
  89. // queueSong => queueSong.requestedBy === userId.value
  90. // ).length
  91. // );
  92. const autorequestPlaylistCount = computed(() => {
  93. if (props.sector === "station") return stationStore.autoRequest.length;
  94. return 0;
  95. });
  96. const showTab = _tab => {
  97. const tabElement = tabs.value[`${_tab}-tab`];
  98. if (tabElement) tabElement.scrollIntoView({ block: "nearest" });
  99. tab.value = _tab;
  100. };
  101. const addSongToQueue = (mediaSource: string, index?: number) => {
  102. socket.dispatch(
  103. "stations.addToQueue",
  104. station.value._id,
  105. mediaSource,
  106. "manual",
  107. res => {
  108. if (res.status !== "success") new Toast(`Error: ${res.message}`);
  109. else {
  110. if (index)
  111. youtubeSearch.value.songs.results[index].isAddedToQueue =
  112. true;
  113. new Toast(res.message);
  114. }
  115. }
  116. );
  117. };
  118. watch(
  119. () => props.disableAutoRequest,
  120. value => {
  121. if (value && tab.value === "autorequest") showTab("songs");
  122. }
  123. );
  124. onMounted(async () => {
  125. showTab("songs");
  126. });
  127. </script>
  128. <template>
  129. <div class="station-playlists">
  130. <p
  131. class="top-info has-text-centered"
  132. v-if="
  133. tab !== 'songs' ||
  134. (station.requests.allowAutorequest && !disableAutoRequest)
  135. "
  136. >
  137. Add songs to the queue or automatically request songs from playlists
  138. </p>
  139. <div class="tabs-container">
  140. <div
  141. class="tab-selection"
  142. v-if="
  143. tab !== 'songs' ||
  144. (station.requests.allowAutorequest && !disableAutoRequest)
  145. "
  146. >
  147. <button
  148. class="button is-default"
  149. :ref="el => (tabs['songs-tab'] = el)"
  150. :class="{ selected: tab === 'songs' }"
  151. @click="showTab('songs')"
  152. >
  153. Songs
  154. </button>
  155. <button
  156. v-if="
  157. station.requests.allowAutorequest && !disableAutoRequest
  158. "
  159. class="button is-default"
  160. :ref="el => (tabs['autorequest-tab'] = el)"
  161. :class="{ selected: tab === 'autorequest' }"
  162. @click="showTab('autorequest')"
  163. >
  164. Autorequest
  165. <span
  166. v-tippy
  167. content="You are autorequesting playlists"
  168. class="tag has-icon"
  169. v-if="autorequestPlaylistCount > 0"
  170. ><i class="material-icons">play_arrow</i></span
  171. >
  172. </button>
  173. <button
  174. v-else-if="station.requests.allowAutorequest"
  175. class="button is-default disabled"
  176. content="Only available on station pages"
  177. v-tippy
  178. >
  179. Autorequest
  180. </button>
  181. </div>
  182. <div class="tab" v-show="tab === 'songs'">
  183. <div class="musare-songs">
  184. <label class="label">
  185. Search for a song on {{ configStore.get("sitename") }}
  186. </label>
  187. <div class="control is-grouped input-with-button">
  188. <p class="control is-expanded">
  189. <input
  190. class="input"
  191. type="text"
  192. placeholder="Enter your song query here..."
  193. v-model="musareSearch.query"
  194. @keyup.enter="searchForMusareSongs(1)"
  195. />
  196. </p>
  197. <p class="control">
  198. <a
  199. class="button is-info"
  200. @click="searchForMusareSongs(1)"
  201. ><i class="material-icons icon-with-button"
  202. >search</i
  203. >Search</a
  204. >
  205. </p>
  206. </div>
  207. <div v-if="musareSearch.results.length > 0">
  208. <song-item
  209. v-for="song in musareSearch.results"
  210. :key="song._id"
  211. :song="song"
  212. >
  213. <template #actions>
  214. <transition
  215. name="musare-search-query-actions"
  216. mode="out-in"
  217. >
  218. <i
  219. v-if="
  220. songsInQueue.indexOf(
  221. song.mediaSource
  222. ) !== -1
  223. "
  224. class="material-icons added-to-playlist-icon"
  225. content="Song is already in queue"
  226. v-tippy
  227. >done</i
  228. >
  229. <i
  230. v-else
  231. class="material-icons add-to-queue-icon"
  232. @click="
  233. addSongToQueue(song.mediaSource)
  234. "
  235. content="Add Song to Queue"
  236. v-tippy
  237. >queue</i
  238. >
  239. </transition>
  240. </template>
  241. </song-item>
  242. <button
  243. v-if="musareResultsLeftCount > 0"
  244. class="button is-primary load-more-button"
  245. @click="searchForMusareSongs(musareSearch.page + 1)"
  246. >
  247. Load {{ nextPageMusareResultsCount }} more results
  248. </button>
  249. </div>
  250. </div>
  251. <div class="youtube-direct">
  252. <label class="label"> Add a YouTube song from a URL </label>
  253. <div class="control is-grouped input-with-button">
  254. <p class="control is-expanded">
  255. <input
  256. class="input"
  257. type="text"
  258. placeholder="Enter your YouTube song URL here..."
  259. v-model="youtubeDirect"
  260. @keyup.enter="addToQueue(station._id)"
  261. />
  262. </p>
  263. <p class="control">
  264. <a
  265. class="button is-info"
  266. @click="addToQueue(station._id)"
  267. ><i class="material-icons icon-with-button"
  268. >add</i
  269. >Add</a
  270. >
  271. </p>
  272. </div>
  273. </div>
  274. <div
  275. class="youtube-search"
  276. v-if="
  277. !configStore.get('experimental.disable_youtube_search')
  278. "
  279. >
  280. <label class="label"> Search for a song on YouTube </label>
  281. <div class="control is-grouped input-with-button">
  282. <p class="control is-expanded">
  283. <input
  284. class="input"
  285. type="text"
  286. placeholder="Enter your YouTube query here..."
  287. v-model="youtubeSearch.songs.query"
  288. autofocus
  289. @keyup.enter="searchForSongs()"
  290. />
  291. </p>
  292. <p class="control">
  293. <a
  294. class="button is-info"
  295. @click.prevent="searchForSongs()"
  296. ><i class="material-icons icon-with-button"
  297. >search</i
  298. >Search</a
  299. >
  300. </p>
  301. </div>
  302. <div
  303. v-if="youtubeSearch.songs.results.length > 0"
  304. id="song-query-results"
  305. >
  306. <search-query-item
  307. v-for="(result, index) in youtubeSearch.songs
  308. .results"
  309. :key="result.id"
  310. :result="result"
  311. >
  312. <template #actions>
  313. <transition
  314. name="youtube-search-query-actions"
  315. mode="out-in"
  316. >
  317. <i
  318. v-if="
  319. songsInQueue.indexOf(result.id) !==
  320. -1
  321. "
  322. class="material-icons added-to-playlist-icon"
  323. content="Song is already in queue"
  324. v-tippy
  325. >done</i
  326. >
  327. <i
  328. v-else
  329. class="material-icons add-to-queue-icon"
  330. @click="
  331. addSongToQueue(result.id, index)
  332. "
  333. content="Add Song to Queue"
  334. v-tippy
  335. >queue</i
  336. >
  337. </transition>
  338. </template>
  339. </search-query-item>
  340. <a
  341. class="button is-primary load-more-button"
  342. @click.prevent="loadMoreSongs()"
  343. >
  344. Load more...
  345. </a>
  346. </div>
  347. </div>
  348. <div
  349. v-if="configStore.get('experimental.soundcloud')"
  350. class="soundcloud-direct"
  351. >
  352. <label class="label">
  353. Add a SoundCloud song from a URL
  354. </label>
  355. <div class="control is-grouped input-with-button">
  356. <p class="control is-expanded">
  357. <input
  358. class="input"
  359. type="text"
  360. placeholder="Enter your SoundCloud song URL here..."
  361. v-model="soundcloudDirect"
  362. @keyup.enter="soundcloudAddToQueue(station._id)"
  363. />
  364. </p>
  365. <p class="control">
  366. <a
  367. class="button is-info"
  368. @click="soundcloudAddToQueue(station._id)"
  369. ><i class="material-icons icon-with-button"
  370. >add</i
  371. >Add</a
  372. >
  373. </p>
  374. </div>
  375. </div>
  376. </div>
  377. <playlist-tab-base
  378. v-if="!disableAutoRequest"
  379. class="tab"
  380. v-show="tab === 'autorequest'"
  381. :type="'autorequest'"
  382. :sector="sector"
  383. :modal-uuid="modalUuid"
  384. />
  385. </div>
  386. </div>
  387. </template>
  388. <style lang="less" scoped>
  389. .night-mode {
  390. .tabs-container .tab-selection .button {
  391. background: var(--dark-grey) !important;
  392. color: var(--white) !important;
  393. }
  394. }
  395. :deep(#create-new-playlist-button) {
  396. width: 100%;
  397. }
  398. .station-playlists {
  399. .top-info {
  400. font-size: 15px;
  401. margin-bottom: 15px;
  402. }
  403. .tabs-container {
  404. .tab-selection {
  405. margin-bottom: 10px;
  406. display: flex;
  407. overflow-x: auto;
  408. .button {
  409. border-radius: 0;
  410. border: 0;
  411. text-transform: uppercase;
  412. font-size: 14px;
  413. color: var(--dark-grey-3);
  414. background-color: var(--light-grey-2);
  415. flex-grow: 1;
  416. height: 32px;
  417. &:not(:first-of-type) {
  418. margin-left: 5px;
  419. }
  420. }
  421. .selected {
  422. background-color: var(--primary-color) !important;
  423. color: var(--white) !important;
  424. font-weight: 600;
  425. }
  426. }
  427. .tab {
  428. padding-bottom: 10px;
  429. border-radius: 0;
  430. .item.item-draggable:not(:last-of-type) {
  431. margin-bottom: 10px;
  432. }
  433. .load-more-button {
  434. width: 100%;
  435. margin-top: 10px;
  436. }
  437. }
  438. }
  439. }
  440. .youtube-direct {
  441. margin-top: 10px;
  442. }
  443. .youtube-search {
  444. margin-top: 10px;
  445. .search-query-item:not(:last-of-type) {
  446. margin-bottom: 10px;
  447. }
  448. }
  449. </style>