Request.vue 11 KB

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