Request.vue 9.0 KB

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