Request.vue 10 KB

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