Request.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  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.youtubeId)
  80. .concat(station.value.currentSong.youtubeId);
  81. return songsList.value.map(song => song.youtubeId);
  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 = (youtubeId: string, index?: number) => {
  99. socket.dispatch(
  100. "stations.addToQueue",
  101. station.value._id,
  102. youtubeId,
  103. res => {
  104. if (res.status !== "success") new Toast(`Error: ${res.message}`);
  105. else {
  106. if (index)
  107. youtubeSearch.value.songs.results[index].isAddedToQueue =
  108. true;
  109. new Toast(res.message);
  110. }
  111. }
  112. );
  113. };
  114. onMounted(async () => {
  115. sitename.value = await lofig.get("siteSettings.sitename");
  116. lofig.get("experimental").then(experimental => {
  117. if (
  118. experimental &&
  119. Object.hasOwn(experimental, "disable_youtube_search") &&
  120. experimental.disable_youtube_search
  121. ) {
  122. experimentalDisableYoutubeSearch.value = true;
  123. }
  124. });
  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 {{ 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.youtubeId
  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="addSongToQueue(song.youtubeId)"
  233. content="Add Song to Queue"
  234. v-tippy
  235. >queue</i
  236. >
  237. </transition>
  238. </template>
  239. </song-item>
  240. <button
  241. v-if="musareResultsLeftCount > 0"
  242. class="button is-primary load-more-button"
  243. @click="searchForMusareSongs(musareSearch.page + 1)"
  244. >
  245. Load {{ nextPageMusareResultsCount }} more results
  246. </button>
  247. </div>
  248. </div>
  249. <div class="youtube-direct">
  250. <label class="label"> Add a YouTube song from a URL </label>
  251. <div class="control is-grouped input-with-button">
  252. <p class="control is-expanded">
  253. <input
  254. class="input"
  255. type="text"
  256. placeholder="Enter your YouTube song URL here..."
  257. v-model="youtubeDirect"
  258. @keyup.enter="addToQueue(station._id)"
  259. />
  260. </p>
  261. <p class="control">
  262. <a
  263. class="button is-info"
  264. @click="addToQueue(station._id)"
  265. ><i class="material-icons icon-with-button"
  266. >add</i
  267. >Add</a
  268. >
  269. </p>
  270. </div>
  271. </div>
  272. <div
  273. class="youtube-search"
  274. v-if="!experimentalDisableYoutubeSearch"
  275. >
  276. <label class="label"> Search for a song on YouTube </label>
  277. <div class="control is-grouped input-with-button">
  278. <p class="control is-expanded">
  279. <input
  280. class="input"
  281. type="text"
  282. placeholder="Enter your YouTube query here..."
  283. v-model="youtubeSearch.songs.query"
  284. autofocus
  285. @keyup.enter="searchForSongs()"
  286. />
  287. </p>
  288. <p class="control">
  289. <a
  290. class="button is-info"
  291. @click.prevent="searchForSongs()"
  292. ><i class="material-icons icon-with-button"
  293. >search</i
  294. >Search</a
  295. >
  296. </p>
  297. </div>
  298. <div
  299. v-if="youtubeSearch.songs.results.length > 0"
  300. id="song-query-results"
  301. >
  302. <search-query-item
  303. v-for="(result, index) in youtubeSearch.songs
  304. .results"
  305. :key="result.id"
  306. :result="result"
  307. >
  308. <template #actions>
  309. <transition
  310. name="youtube-search-query-actions"
  311. mode="out-in"
  312. >
  313. <i
  314. v-if="
  315. songsInQueue.indexOf(result.id) !==
  316. -1
  317. "
  318. class="material-icons added-to-playlist-icon"
  319. content="Song is already in queue"
  320. v-tippy
  321. >done</i
  322. >
  323. <i
  324. v-else
  325. class="material-icons add-to-queue-icon"
  326. @click="
  327. addSongToQueue(result.id, index)
  328. "
  329. content="Add Song to Queue"
  330. v-tippy
  331. >queue</i
  332. >
  333. </transition>
  334. </template>
  335. </search-query-item>
  336. <a
  337. class="button is-primary load-more-button"
  338. @click.prevent="loadMoreSongs()"
  339. >
  340. Load more...
  341. </a>
  342. </div>
  343. </div>
  344. </div>
  345. <playlist-tab-base
  346. v-if="!disableAutoRequest"
  347. class="tab"
  348. v-show="tab === 'autorequest'"
  349. :type="'autorequest'"
  350. :sector="sector"
  351. :modal-uuid="modalUuid"
  352. />
  353. </div>
  354. </div>
  355. </template>
  356. <style lang="less" scoped>
  357. .night-mode {
  358. .tabs-container .tab-selection .button {
  359. background: var(--dark-grey) !important;
  360. color: var(--white) !important;
  361. }
  362. }
  363. :deep(#create-new-playlist-button) {
  364. width: 100%;
  365. }
  366. .station-playlists {
  367. .top-info {
  368. font-size: 15px;
  369. margin-bottom: 15px;
  370. }
  371. .tabs-container {
  372. .tab-selection {
  373. margin-bottom: 10px;
  374. display: flex;
  375. overflow-x: auto;
  376. .button {
  377. border-radius: 0;
  378. border: 0;
  379. text-transform: uppercase;
  380. font-size: 14px;
  381. color: var(--dark-grey-3);
  382. background-color: var(--light-grey-2);
  383. flex-grow: 1;
  384. height: 32px;
  385. &:not(:first-of-type) {
  386. margin-left: 5px;
  387. }
  388. }
  389. .selected {
  390. background-color: var(--primary-color) !important;
  391. color: var(--white) !important;
  392. font-weight: 600;
  393. }
  394. }
  395. .tab {
  396. padding-bottom: 10px;
  397. border-radius: 0;
  398. .item.item-draggable:not(:last-of-type) {
  399. margin-bottom: 10px;
  400. }
  401. .load-more-button {
  402. width: 100%;
  403. margin-top: 10px;
  404. }
  405. }
  406. }
  407. }
  408. .youtube-direct {
  409. margin-top: 10px;
  410. }
  411. .youtube-search {
  412. margin-top: 10px;
  413. .search-query-item:not(:last-of-type) {
  414. margin-bottom: 10px;
  415. }
  416. }
  417. </style>