Request.vue 9.7 KB

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