Request.vue 9.3 KB

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