Request.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  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 showTab = _tab => {
  90. tabs.value[`${_tab}-tab`].scrollIntoView({ block: "nearest" });
  91. tab.value = _tab;
  92. };
  93. const addSongToQueue = (youtubeId: string, index?: number) => {
  94. socket.dispatch(
  95. "stations.addToQueue",
  96. station.value._id,
  97. youtubeId,
  98. res => {
  99. if (res.status !== "success") new Toast(`Error: ${res.message}`);
  100. else {
  101. if (index)
  102. youtubeSearch.value.songs.results[index].isAddedToQueue =
  103. true;
  104. new Toast(res.message);
  105. }
  106. }
  107. );
  108. };
  109. onMounted(async () => {
  110. sitename.value = await lofig.get("siteSettings.sitename");
  111. lofig.get("experimental").then(experimental => {
  112. if (
  113. experimental &&
  114. Object.hasOwn(experimental, "disable_youtube_search") &&
  115. experimental.disable_youtube_search
  116. ) {
  117. experimentalDisableYoutubeSearch.value = true;
  118. }
  119. });
  120. showTab("songs");
  121. });
  122. </script>
  123. <template>
  124. <div class="station-playlists">
  125. <p
  126. class="top-info has-text-centered"
  127. v-if="
  128. tab !== 'songs' ||
  129. (station.requests.allowAutorequest && !disableAutoRequest)
  130. "
  131. >
  132. Add songs to the queue or automatically request songs from playlists
  133. </p>
  134. <div class="tabs-container">
  135. <div
  136. class="tab-selection"
  137. v-if="
  138. tab !== 'songs' ||
  139. (station.requests.allowAutorequest && !disableAutoRequest)
  140. "
  141. >
  142. <button
  143. class="button is-default"
  144. :ref="el => (tabs['songs-tab'] = el)"
  145. :class="{ selected: tab === 'songs' }"
  146. @click="showTab('songs')"
  147. >
  148. Songs
  149. </button>
  150. <button
  151. v-if="
  152. station.requests.allowAutorequest && !disableAutoRequest
  153. "
  154. class="button is-default"
  155. :ref="el => (tabs['autorequest-tab'] = el)"
  156. :class="{ selected: tab === 'autorequest' }"
  157. @click="showTab('autorequest')"
  158. >
  159. Autorequest
  160. </button>
  161. <button
  162. v-else-if="station.requests.allowAutorequest"
  163. class="button is-default disabled"
  164. content="Only available on station pages"
  165. v-tippy
  166. >
  167. Autorequest
  168. </button>
  169. </div>
  170. <div class="tab" v-show="tab === 'songs'">
  171. <div class="musare-songs">
  172. <label class="label">
  173. Search for a song on {{ sitename }}
  174. </label>
  175. <div class="control is-grouped input-with-button">
  176. <p class="control is-expanded">
  177. <input
  178. class="input"
  179. type="text"
  180. placeholder="Enter your song query here..."
  181. v-model="musareSearch.query"
  182. @keyup.enter="searchForMusareSongs(1)"
  183. />
  184. </p>
  185. <p class="control">
  186. <a
  187. class="button is-info"
  188. @click="searchForMusareSongs(1)"
  189. ><i class="material-icons icon-with-button"
  190. >search</i
  191. >Search</a
  192. >
  193. </p>
  194. </div>
  195. <div v-if="musareSearch.results.length > 0">
  196. <song-item
  197. v-for="song in musareSearch.results"
  198. :key="song._id"
  199. :song="song"
  200. >
  201. <template #actions>
  202. <transition
  203. name="musare-search-query-actions"
  204. mode="out-in"
  205. >
  206. <i
  207. v-if="
  208. songsInQueue.indexOf(
  209. song.youtubeId
  210. ) !== -1
  211. "
  212. class="material-icons added-to-playlist-icon"
  213. content="Song is already in queue"
  214. v-tippy
  215. >done</i
  216. >
  217. <i
  218. v-else
  219. class="material-icons add-to-queue-icon"
  220. @click="addSongToQueue(song.youtubeId)"
  221. content="Add Song to Queue"
  222. v-tippy
  223. >queue</i
  224. >
  225. </transition>
  226. </template>
  227. </song-item>
  228. <button
  229. v-if="musareResultsLeftCount > 0"
  230. class="button is-primary load-more-button"
  231. @click="searchForMusareSongs(musareSearch.page + 1)"
  232. >
  233. Load {{ nextPageMusareResultsCount }} more results
  234. </button>
  235. </div>
  236. </div>
  237. <div class="youtube-direct">
  238. <label class="label"> Add a YouTube song from a URL </label>
  239. <div class="control is-grouped input-with-button">
  240. <p class="control is-expanded">
  241. <input
  242. class="input"
  243. type="text"
  244. placeholder="Enter your YouTube song URL here..."
  245. v-model="youtubeDirect"
  246. @keyup.enter="addToQueue(station._id)"
  247. />
  248. </p>
  249. <p class="control">
  250. <a
  251. class="button is-info"
  252. @click="addToQueue(station._id)"
  253. ><i class="material-icons icon-with-button"
  254. >add</i
  255. >Add</a
  256. >
  257. </p>
  258. </div>
  259. </div>
  260. <div
  261. class="youtube-search"
  262. v-if="!experimentalDisableYoutubeSearch"
  263. >
  264. <label class="label"> Search for a song on YouTube </label>
  265. <div class="control is-grouped input-with-button">
  266. <p class="control is-expanded">
  267. <input
  268. class="input"
  269. type="text"
  270. placeholder="Enter your YouTube query here..."
  271. v-model="youtubeSearch.songs.query"
  272. autofocus
  273. @keyup.enter="searchForSongs()"
  274. />
  275. </p>
  276. <p class="control">
  277. <a
  278. class="button is-info"
  279. @click.prevent="searchForSongs()"
  280. ><i class="material-icons icon-with-button"
  281. >search</i
  282. >Search</a
  283. >
  284. </p>
  285. </div>
  286. <div
  287. v-if="youtubeSearch.songs.results.length > 0"
  288. id="song-query-results"
  289. >
  290. <search-query-item
  291. v-for="(result, index) in youtubeSearch.songs
  292. .results"
  293. :key="result.id"
  294. :result="result"
  295. >
  296. <template #actions>
  297. <transition
  298. name="youtube-search-query-actions"
  299. mode="out-in"
  300. >
  301. <i
  302. v-if="
  303. songsInQueue.indexOf(result.id) !==
  304. -1
  305. "
  306. class="material-icons added-to-playlist-icon"
  307. content="Song is already in queue"
  308. v-tippy
  309. >done</i
  310. >
  311. <i
  312. v-else
  313. class="material-icons add-to-queue-icon"
  314. @click="
  315. addSongToQueue(result.id, index)
  316. "
  317. content="Add Song to Queue"
  318. v-tippy
  319. >queue</i
  320. >
  321. </transition>
  322. </template>
  323. </search-query-item>
  324. <a
  325. class="button is-primary load-more-button"
  326. @click.prevent="loadMoreSongs()"
  327. >
  328. Load more...
  329. </a>
  330. </div>
  331. </div>
  332. </div>
  333. <playlist-tab-base
  334. v-if="!disableAutoRequest"
  335. class="tab"
  336. v-show="tab === 'autorequest'"
  337. :type="'autorequest'"
  338. :sector="sector"
  339. :modal-uuid="modalUuid"
  340. />
  341. </div>
  342. </div>
  343. </template>
  344. <style lang="less" scoped>
  345. .night-mode {
  346. .tabs-container .tab-selection .button {
  347. background: var(--dark-grey) !important;
  348. color: var(--white) !important;
  349. }
  350. }
  351. :deep(#create-new-playlist-button) {
  352. width: 100%;
  353. }
  354. .station-playlists {
  355. .top-info {
  356. font-size: 15px;
  357. margin-bottom: 15px;
  358. }
  359. .tabs-container {
  360. .tab-selection {
  361. margin-bottom: 10px;
  362. display: flex;
  363. overflow-x: auto;
  364. .button {
  365. border-radius: 0;
  366. border: 0;
  367. text-transform: uppercase;
  368. font-size: 14px;
  369. color: var(--dark-grey-3);
  370. background-color: var(--light-grey-2);
  371. flex-grow: 1;
  372. height: 32px;
  373. &:not(:first-of-type) {
  374. margin-left: 5px;
  375. }
  376. }
  377. .selected {
  378. background-color: var(--primary-color) !important;
  379. color: var(--white) !important;
  380. font-weight: 600;
  381. }
  382. }
  383. .tab {
  384. padding-bottom: 10px;
  385. border-radius: 0;
  386. .item.item-draggable:not(:last-of-type) {
  387. margin-bottom: 10px;
  388. }
  389. .load-more-button {
  390. width: 100%;
  391. margin-top: 10px;
  392. }
  393. }
  394. }
  395. }
  396. .youtube-search {
  397. margin-top: 10px;
  398. .search-query-item:not(:last-of-type) {
  399. margin-bottom: 10px;
  400. }
  401. }
  402. </style>