Request.vue 8.9 KB

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