PlaylistTabBase.vue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182
  1. <script setup lang="ts">
  2. import { defineAsyncComponent, ref, reactive, computed, onMounted } from "vue";
  3. import Toast from "toasters";
  4. import { storeToRefs } from "pinia";
  5. import { useWebsocketsStore } from "@/stores/websockets";
  6. import { useStationStore } from "@/stores/station";
  7. import { useUserPlaylistsStore } from "@/stores/userPlaylists";
  8. import { useModalsStore } from "@/stores/modals";
  9. import { useManageStationStore } from "@/stores/manageStation";
  10. import { useConfigStore } from "@/stores/config";
  11. import { useSortablePlaylists } from "@/composables/useSortablePlaylists";
  12. const PlaylistItem = defineAsyncComponent(
  13. () => import("@/components/PlaylistItem.vue")
  14. );
  15. const QuickConfirm = defineAsyncComponent(
  16. () => import("@/components/QuickConfirm.vue")
  17. );
  18. const props = defineProps({
  19. modalUuid: { type: String, default: null },
  20. type: {
  21. type: String,
  22. default: ""
  23. },
  24. sector: {
  25. type: String,
  26. default: "manageStation"
  27. }
  28. });
  29. const emit = defineEmits(["selected"]);
  30. const configStore = useConfigStore();
  31. const { socket } = useWebsocketsStore();
  32. const stationStore = useStationStore();
  33. const tab = ref("current");
  34. const search = reactive({
  35. query: "",
  36. searchedQuery: "",
  37. page: 0,
  38. count: 0,
  39. resultsLeft: 0,
  40. pageSize: 0,
  41. results: []
  42. });
  43. const featuredPlaylists = ref([]);
  44. const tabs = ref({});
  45. const {
  46. DraggableList,
  47. drag,
  48. playlists,
  49. savePlaylistOrder,
  50. orderOfPlaylists,
  51. myUserId,
  52. calculatePlaylistOrder
  53. } = useSortablePlaylists();
  54. const { autoRequest, history, songsList } = storeToRefs(stationStore);
  55. const manageStationStore = useManageStationStore({
  56. modalUuid: props.modalUuid
  57. });
  58. const { autofill } = storeToRefs(manageStationStore);
  59. const station = computed({
  60. get() {
  61. if (props.sector === "manageStation") return manageStationStore.station;
  62. return stationStore.station;
  63. },
  64. set(value) {
  65. if (props.sector === "manageStation")
  66. manageStationStore.updateStation(value);
  67. else stationStore.updateStation(value);
  68. }
  69. });
  70. const blacklist = computed({
  71. get() {
  72. if (props.sector === "manageStation")
  73. return manageStationStore.blacklist;
  74. return stationStore.blacklist;
  75. },
  76. set(value) {
  77. if (props.sector === "manageStation")
  78. manageStationStore.setBlacklist(value);
  79. else stationStore.setBlacklist(value);
  80. }
  81. });
  82. const resultsLeftCount = computed(() => search.count - search.results.length);
  83. const nextPageResultsCount = computed(() =>
  84. Math.min(search.pageSize, resultsLeftCount.value)
  85. );
  86. const excludedYoutubeIds = computed(() => {
  87. if (!history.value) return [];
  88. const {
  89. autorequestDisallowRecentlyPlayedEnabled,
  90. autorequestDisallowRecentlyPlayedNumber
  91. } = station.value.requests;
  92. const mediaSources = new Set();
  93. if (
  94. autorequestDisallowRecentlyPlayedEnabled &&
  95. configStore.get("experimental.station_history")
  96. ) {
  97. history.value.forEach((historyItem, index) => {
  98. if (index < autorequestDisallowRecentlyPlayedNumber)
  99. mediaSources.add(historyItem.payload.song.mediaSource);
  100. });
  101. }
  102. if (songsList.value) {
  103. songsList.value.forEach(song => {
  104. mediaSources.add(song.mediaSource);
  105. });
  106. }
  107. if (station.value.currentSong) {
  108. mediaSources.add(station.value.currentSong.mediaSource);
  109. }
  110. return Array.from(mediaSources);
  111. });
  112. const totalUniqueAutorequestableYoutubeIds = computed(() => {
  113. if (!autoRequest.value) return [];
  114. const uniqueYoutubeIds = new Set();
  115. autoRequest.value.forEach(playlist => {
  116. playlist.songs.forEach(song => {
  117. uniqueYoutubeIds.add(song.mediaSource);
  118. });
  119. });
  120. return Array.from(uniqueYoutubeIds);
  121. });
  122. const actuallyAutorequestingYoutubeIds = computed(() => {
  123. const excluded = excludedYoutubeIds.value;
  124. const remaining = totalUniqueAutorequestableYoutubeIds.value.filter(
  125. mediaSource =>
  126. excluded.indexOf(mediaSource) === -1 &&
  127. !mediaSource.startsWith("spotify:")
  128. );
  129. return remaining;
  130. });
  131. const hasPermission = permission =>
  132. props.sector === "manageStation"
  133. ? manageStationStore.hasPermission(permission)
  134. : stationStore.hasPermission(permission);
  135. const { openModal } = useModalsStore();
  136. const { setPlaylists } = useUserPlaylistsStore();
  137. const {
  138. addAutorequestPlaylists,
  139. addPlaylistToAutoRequest,
  140. removePlaylistFromAutoRequest,
  141. updateAutorequestLocalStorage
  142. } = stationStore;
  143. const showTab = _tab => {
  144. if (tabs.value[`${_tab}-tab`])
  145. tabs.value[`${_tab}-tab`].scrollIntoView({ block: "nearest" });
  146. tab.value = _tab;
  147. };
  148. const label = (tense = "future", typeOverwrite = null, capitalize = false) => {
  149. let label = typeOverwrite || props.type;
  150. if (tense === "past") label = `${label}ed`;
  151. if (tense === "present") label = `${label}ing`;
  152. if (capitalize) label = `${label.charAt(0).toUpperCase()}${label.slice(1)}`;
  153. return label;
  154. };
  155. const selectedPlaylists = (typeOverwrite?: string) => {
  156. const type = typeOverwrite || props.type;
  157. if (type === "autofill") return autofill.value;
  158. if (type === "blacklist") return blacklist.value;
  159. if (type === "autorequest") return autoRequest.value;
  160. return [];
  161. };
  162. const isSelected = (playlistId, typeOverwrite?: string) => {
  163. const type = typeOverwrite || props.type;
  164. let selected = false;
  165. selectedPlaylists(type).forEach(playlist => {
  166. if (playlist._id === playlistId) selected = true;
  167. });
  168. return selected;
  169. };
  170. const deselectPlaylist = (playlistId, typeOverwrite?: string) => {
  171. const type = typeOverwrite || props.type;
  172. if (type === "autofill")
  173. return new Promise(resolve => {
  174. socket.dispatch(
  175. "stations.removeAutofillPlaylist",
  176. station.value._id,
  177. playlistId,
  178. res => {
  179. new Toast(res.message);
  180. resolve(true);
  181. }
  182. );
  183. });
  184. if (type === "blacklist")
  185. return new Promise(resolve => {
  186. socket.dispatch(
  187. "stations.removeBlacklistedPlaylist",
  188. station.value._id,
  189. playlistId,
  190. res => {
  191. new Toast(res.message);
  192. resolve(true);
  193. }
  194. );
  195. });
  196. if (type === "autorequest")
  197. return new Promise(resolve => {
  198. removePlaylistFromAutoRequest(playlistId);
  199. new Toast("Successfully deselected playlist.");
  200. resolve(true);
  201. });
  202. return false;
  203. };
  204. const selectPlaylist = async (playlist, typeOverwrite?: string) => {
  205. const type = typeOverwrite || props.type;
  206. if (isSelected(playlist._id, type))
  207. return new Toast(`Error: Playlist already ${label("past", type)}.`);
  208. if (type === "autofill")
  209. return new Promise(resolve => {
  210. socket.dispatch(
  211. "stations.autofillPlaylist",
  212. station.value._id,
  213. playlist._id,
  214. res => {
  215. new Toast(res.message);
  216. emit("selected");
  217. resolve(true);
  218. }
  219. );
  220. });
  221. if (type === "blacklist") {
  222. if (props.type !== "blacklist" && isSelected(playlist._id))
  223. await deselectPlaylist(playlist._id);
  224. return new Promise(resolve => {
  225. socket.dispatch(
  226. "stations.blacklistPlaylist",
  227. station.value._id,
  228. playlist._id,
  229. res => {
  230. new Toast(res.message);
  231. emit("selected");
  232. resolve(true);
  233. }
  234. );
  235. });
  236. }
  237. if (type === "autorequest")
  238. return new Promise(resolve => {
  239. addPlaylistToAutoRequest(playlist);
  240. new Toast("Successfully selected playlist to auto request songs.");
  241. emit("selected");
  242. resolve(true);
  243. });
  244. return false;
  245. };
  246. const searchForPlaylists = page => {
  247. if (search.page >= page || search.searchedQuery !== search.query) {
  248. search.results = [];
  249. search.page = 0;
  250. search.count = 0;
  251. search.resultsLeft = 0;
  252. search.pageSize = 0;
  253. }
  254. const { query } = search;
  255. const action =
  256. station.value.type === "official" && props.type !== "autorequest"
  257. ? "playlists.searchOfficial"
  258. : "playlists.searchCommunity";
  259. search.searchedQuery = search.query;
  260. socket.dispatch(action, query, page, res => {
  261. const { data } = res;
  262. if (res.status === "success") {
  263. const { count, pageSize, playlists } = data;
  264. search.results = [...search.results, ...playlists];
  265. search.page = page;
  266. search.count = count;
  267. search.resultsLeft = count - search.results.length;
  268. search.pageSize = pageSize;
  269. } else if (res.status === "error") {
  270. search.results = [];
  271. search.page = 0;
  272. search.count = 0;
  273. search.resultsLeft = 0;
  274. search.pageSize = 0;
  275. new Toast(res.message);
  276. }
  277. });
  278. };
  279. onMounted(() => {
  280. if (props.type === "autorequest" || station.value.type === "community")
  281. showTab("my-playlists");
  282. else showTab("search");
  283. socket.onConnect(() => {
  284. socket.dispatch("playlists.indexMyPlaylists", res => {
  285. if (res.status === "success") setPlaylists(res.data.playlists);
  286. orderOfPlaylists.value = calculatePlaylistOrder(); // order in regards to the database
  287. });
  288. socket.dispatch("playlists.indexFeaturedPlaylists", res => {
  289. if (res.status === "success")
  290. featuredPlaylists.value = res.data.playlists;
  291. });
  292. if (props.type === "autofill")
  293. socket.dispatch(
  294. `stations.getStationAutofillPlaylistsById`,
  295. station.value._id,
  296. res => {
  297. if (res.status === "success") {
  298. station.value.autofill.playlists = res.data.playlists;
  299. }
  300. }
  301. );
  302. socket.dispatch(
  303. `stations.getStationBlacklistById`,
  304. station.value._id,
  305. res => {
  306. if (res.status === "success") {
  307. station.value.blacklist = res.data.playlists;
  308. }
  309. }
  310. );
  311. const autorequestLocalStorageItem = localStorage.getItem(
  312. `autorequest-${station.value._id}`
  313. );
  314. if (
  315. autorequestLocalStorageItem &&
  316. station.value.requests &&
  317. station.value.requests.allowAutorequest &&
  318. autoRequest.value.length === 0
  319. ) {
  320. const autorequestParsedItem = JSON.parse(
  321. autorequestLocalStorageItem
  322. );
  323. const autorequestUpdatedAt = new Date(
  324. autorequestParsedItem.updatedAt
  325. );
  326. const fiveMinutesAgo = new Date(
  327. new Date().getTime() - 5 * 60 * 1000
  328. );
  329. if (autorequestUpdatedAt > fiveMinutesAgo) {
  330. const playlists = [];
  331. const promises = autorequestParsedItem.playlistIds.map(
  332. playlistId =>
  333. new Promise<void>(resolve => {
  334. socket.dispatch(
  335. "playlists.getPlaylist",
  336. playlistId,
  337. res => {
  338. if (res.status === "success") {
  339. playlists.push(res.data.playlist);
  340. }
  341. resolve();
  342. }
  343. );
  344. })
  345. );
  346. Promise.all(promises).then(() => {
  347. addAutorequestPlaylists(playlists);
  348. });
  349. } else updateAutorequestLocalStorage();
  350. }
  351. });
  352. });
  353. </script>
  354. <template>
  355. <div class="playlist-tab-base">
  356. <div v-if="$slots.info" class="top-info has-text-centered">
  357. <slot name="info" />
  358. </div>
  359. <div class="tabs-container">
  360. <div class="tab-selection">
  361. <button
  362. v-if="
  363. type === 'autorequest' || station.type === 'community'
  364. "
  365. class="button is-default"
  366. :ref="el => (tabs['my-playlists-tab'] = el)"
  367. :class="{ selected: tab === 'my-playlists' }"
  368. @click="showTab('my-playlists')"
  369. >
  370. My Playlists
  371. </button>
  372. <button
  373. class="button is-default"
  374. :ref="el => (tabs['search-tab'] = el)"
  375. :class="{ selected: tab === 'search' }"
  376. @click="showTab('search')"
  377. >
  378. Search
  379. </button>
  380. <button
  381. class="button is-default"
  382. :ref="el => (tabs['current-tab'] = el)"
  383. :class="{ selected: tab === 'current' }"
  384. @click="showTab('current')"
  385. >
  386. Current
  387. <span class="tag" v-if="selectedPlaylists().length > 0">{{
  388. selectedPlaylists().length
  389. }}</span>
  390. </button>
  391. </div>
  392. <div class="tab" v-show="tab === 'search'">
  393. <div v-if="featuredPlaylists.length > 0">
  394. <label class="label"> Featured playlists </label>
  395. <playlist-item
  396. v-for="featuredPlaylist in featuredPlaylists"
  397. :key="`featuredKey-${featuredPlaylist._id}`"
  398. :playlist="featuredPlaylist"
  399. :show-owner="true"
  400. >
  401. <template #item-icon>
  402. <i
  403. class="material-icons blacklisted-icon"
  404. v-if="
  405. isSelected(
  406. featuredPlaylist._id,
  407. 'blacklist'
  408. )
  409. "
  410. :content="`This playlist is currently ${label(
  411. 'past',
  412. 'blacklist'
  413. )}`"
  414. v-tippy
  415. >
  416. block
  417. </i>
  418. <i
  419. class="material-icons"
  420. v-else-if="isSelected(featuredPlaylist._id)"
  421. :content="`This playlist is currently ${label(
  422. 'past'
  423. )}`"
  424. v-tippy
  425. >
  426. play_arrow
  427. </i>
  428. <i
  429. class="material-icons"
  430. v-else
  431. :content="`This playlist is currently not ${label(
  432. 'past'
  433. )}`"
  434. v-tippy
  435. >
  436. {{
  437. type === "blacklist"
  438. ? "block"
  439. : "play_disabled"
  440. }}
  441. </i>
  442. </template>
  443. <template #actions>
  444. <i
  445. v-if="
  446. type !== 'blacklist' &&
  447. isSelected(
  448. featuredPlaylist._id,
  449. 'blacklist'
  450. )
  451. "
  452. class="material-icons stop-icon"
  453. :content="`This playlist is ${label(
  454. 'past',
  455. 'blacklist'
  456. )} in this station`"
  457. v-tippy="{ theme: 'info' }"
  458. >play_disabled</i
  459. >
  460. <quick-confirm
  461. v-if="
  462. type !== 'blacklist' &&
  463. isSelected(featuredPlaylist._id)
  464. "
  465. @confirm="
  466. deselectPlaylist(featuredPlaylist._id)
  467. "
  468. >
  469. <i
  470. class="material-icons stop-icon"
  471. :content="`Stop ${label(
  472. 'present'
  473. )} songs from this playlist`"
  474. v-tippy
  475. >
  476. stop
  477. </i>
  478. </quick-confirm>
  479. <i
  480. v-if="
  481. type !== 'blacklist' &&
  482. !isSelected(featuredPlaylist._id) &&
  483. !isSelected(
  484. featuredPlaylist._id,
  485. 'blacklist'
  486. )
  487. "
  488. @click="selectPlaylist(featuredPlaylist)"
  489. class="material-icons play-icon"
  490. :content="`${label(
  491. 'future',
  492. null,
  493. true
  494. )} songs from this playlist`"
  495. v-tippy
  496. >play_arrow</i
  497. >
  498. <quick-confirm
  499. v-if="
  500. type === 'blacklist' &&
  501. !isSelected(
  502. featuredPlaylist._id,
  503. 'blacklist'
  504. )
  505. "
  506. @confirm="
  507. selectPlaylist(
  508. featuredPlaylist,
  509. 'blacklist'
  510. )
  511. "
  512. >
  513. <i
  514. class="material-icons stop-icon"
  515. :content="`${label(
  516. 'future',
  517. null,
  518. true
  519. )} Playlist`"
  520. v-tippy
  521. >block</i
  522. >
  523. </quick-confirm>
  524. <quick-confirm
  525. v-if="
  526. type === 'blacklist' &&
  527. isSelected(
  528. featuredPlaylist._id,
  529. 'blacklist'
  530. )
  531. "
  532. @confirm="
  533. deselectPlaylist(featuredPlaylist._id)
  534. "
  535. >
  536. <i
  537. class="material-icons stop-icon"
  538. :content="`Stop ${label(
  539. 'present'
  540. )} songs from this playlist`"
  541. v-tippy
  542. >
  543. stop
  544. </i>
  545. </quick-confirm>
  546. <i
  547. v-if="featuredPlaylist.createdBy === myUserId"
  548. @click="
  549. openModal({
  550. modal: 'editPlaylist',
  551. props: {
  552. playlistId: featuredPlaylist._id
  553. }
  554. })
  555. "
  556. class="material-icons edit-icon"
  557. content="Edit Playlist"
  558. v-tippy
  559. >edit</i
  560. >
  561. <i
  562. v-if="
  563. featuredPlaylist.createdBy !== myUserId &&
  564. (featuredPlaylist.privacy === 'public' ||
  565. hasPermission('playlists.view.others'))
  566. "
  567. @click="
  568. openModal({
  569. modal: 'editPlaylist',
  570. props: {
  571. playlistId: featuredPlaylist._id
  572. }
  573. })
  574. "
  575. class="material-icons edit-icon"
  576. content="View Playlist"
  577. v-tippy
  578. >visibility</i
  579. >
  580. </template>
  581. </playlist-item>
  582. <br />
  583. </div>
  584. <label class="label">Search for a playlist</label>
  585. <div class="control is-grouped input-with-button">
  586. <p class="control is-expanded">
  587. <input
  588. class="input"
  589. type="text"
  590. placeholder="Enter your playlist query here..."
  591. v-model="search.query"
  592. @keyup.enter="searchForPlaylists(1)"
  593. />
  594. </p>
  595. <p class="control">
  596. <a class="button is-info" @click="searchForPlaylists(1)"
  597. ><i class="material-icons icon-with-button"
  598. >search</i
  599. >Search</a
  600. >
  601. </p>
  602. </div>
  603. <div v-if="search.results.length > 0">
  604. <playlist-item
  605. v-for="playlist in search.results"
  606. :key="`searchKey-${playlist._id}`"
  607. :playlist="playlist"
  608. :show-owner="true"
  609. >
  610. <template #item-icon>
  611. <i
  612. class="material-icons blacklisted-icon"
  613. v-if="isSelected(playlist._id, 'blacklist')"
  614. :content="`This playlist is currently ${label(
  615. 'past',
  616. 'blacklist'
  617. )}`"
  618. v-tippy
  619. >
  620. block
  621. </i>
  622. <i
  623. class="material-icons"
  624. v-else-if="isSelected(playlist._id)"
  625. :content="`This playlist is currently ${label(
  626. 'past'
  627. )}`"
  628. v-tippy
  629. >
  630. play_arrow
  631. </i>
  632. <i
  633. class="material-icons"
  634. v-else
  635. :content="`This playlist is currently not ${label(
  636. 'past'
  637. )}`"
  638. v-tippy
  639. >
  640. {{
  641. type === "blacklist"
  642. ? "block"
  643. : "play_disabled"
  644. }}
  645. </i>
  646. </template>
  647. <template #actions>
  648. <i
  649. v-if="
  650. type !== 'blacklist' &&
  651. isSelected(playlist._id, 'blacklist')
  652. "
  653. class="material-icons stop-icon"
  654. :content="`This playlist is ${label(
  655. 'past',
  656. 'blacklist'
  657. )} in this station`"
  658. v-tippy="{ theme: 'info' }"
  659. >play_disabled</i
  660. >
  661. <quick-confirm
  662. v-if="
  663. type !== 'blacklist' &&
  664. isSelected(playlist._id)
  665. "
  666. @confirm="deselectPlaylist(playlist._id)"
  667. >
  668. <i
  669. class="material-icons stop-icon"
  670. :content="`Stop ${label(
  671. 'present'
  672. )} songs from this playlist`"
  673. v-tippy
  674. >
  675. stop
  676. </i>
  677. </quick-confirm>
  678. <i
  679. v-if="
  680. type !== 'blacklist' &&
  681. !isSelected(playlist._id) &&
  682. !isSelected(playlist._id, 'blacklist')
  683. "
  684. @click="selectPlaylist(playlist)"
  685. class="material-icons play-icon"
  686. :content="`${label(
  687. 'future',
  688. null,
  689. true
  690. )} songs from this playlist`"
  691. v-tippy
  692. >play_arrow</i
  693. >
  694. <quick-confirm
  695. v-if="
  696. type === 'blacklist' &&
  697. !isSelected(playlist._id, 'blacklist')
  698. "
  699. @confirm="selectPlaylist(playlist, 'blacklist')"
  700. >
  701. <i
  702. class="material-icons stop-icon"
  703. :content="`${label(
  704. 'future',
  705. null,
  706. true
  707. )} Playlist`"
  708. v-tippy
  709. >block</i
  710. >
  711. </quick-confirm>
  712. <quick-confirm
  713. v-if="
  714. type === 'blacklist' &&
  715. isSelected(playlist._id, 'blacklist')
  716. "
  717. @confirm="deselectPlaylist(playlist._id)"
  718. >
  719. <i
  720. class="material-icons stop-icon"
  721. :content="`Stop ${label(
  722. 'present'
  723. )} songs from this playlist`"
  724. v-tippy
  725. >
  726. stop
  727. </i>
  728. </quick-confirm>
  729. <i
  730. v-if="playlist.createdBy === myUserId"
  731. @click="
  732. openModal({
  733. modal: 'editPlaylist',
  734. props: { playlistId: playlist._id }
  735. })
  736. "
  737. class="material-icons edit-icon"
  738. content="Edit Playlist"
  739. v-tippy
  740. >edit</i
  741. >
  742. <i
  743. v-if="
  744. playlist.createdBy !== myUserId &&
  745. (playlist.privacy === 'public' ||
  746. hasPermission('playlists.view.others'))
  747. "
  748. @click="
  749. openModal({
  750. modal: 'editPlaylist',
  751. props: { playlistId: playlist._id }
  752. })
  753. "
  754. class="material-icons edit-icon"
  755. content="View Playlist"
  756. v-tippy
  757. >visibility</i
  758. >
  759. </template>
  760. </playlist-item>
  761. <button
  762. v-if="resultsLeftCount > 0"
  763. class="button is-primary load-more-button"
  764. @click="searchForPlaylists(search.page + 1)"
  765. >
  766. Load {{ nextPageResultsCount }} more results
  767. </button>
  768. </div>
  769. </div>
  770. <div class="tab" v-show="tab === 'current'">
  771. <p
  772. class="has-text-centered scrollable-list"
  773. v-if="
  774. selectedPlaylists().length > 0 && type === 'autorequest'
  775. "
  776. >
  777. You are currently autorequesting a mix of
  778. {{ totalUniqueAutorequestableYoutubeIds.length }} different
  779. songs. Of these, we can currently autorequest
  780. {{ actuallyAutorequestingYoutubeIds.length }} songs.
  781. <br />
  782. Songs that
  783. <span
  784. v-if="
  785. station.requests
  786. .autorequestDisallowRecentlyPlayedEnabled
  787. "
  788. >were played recently or</span
  789. >
  790. are currently in the queue or playing will not be
  791. autorequested. Spotify songs will also not be autorequested.
  792. <br />
  793. <br />
  794. </p>
  795. <div v-if="selectedPlaylists().length > 0">
  796. <playlist-item
  797. v-for="playlist in selectedPlaylists()"
  798. :key="`key-${playlist._id}`"
  799. :playlist="playlist"
  800. :show-owner="true"
  801. >
  802. <template #item-icon>
  803. <i
  804. class="material-icons"
  805. :class="{
  806. 'blacklisted-icon': type === 'blacklist'
  807. }"
  808. :content="`This playlist is currently ${label(
  809. 'past'
  810. )}`"
  811. v-tippy
  812. >
  813. {{
  814. type === "blacklist"
  815. ? "block"
  816. : "play_arrow"
  817. }}
  818. </i>
  819. </template>
  820. <template #actions>
  821. <quick-confirm
  822. @confirm="deselectPlaylist(playlist._id)"
  823. >
  824. <i
  825. class="material-icons stop-icon"
  826. :content="`Stop ${label(
  827. 'present'
  828. )} songs from this playlist`"
  829. v-tippy
  830. >
  831. stop
  832. </i>
  833. </quick-confirm>
  834. <i
  835. v-if="playlist.createdBy === myUserId"
  836. @click="
  837. openModal({
  838. modal: 'editPlaylist',
  839. props: { playlistId: playlist._id }
  840. })
  841. "
  842. class="material-icons edit-icon"
  843. content="Edit Playlist"
  844. v-tippy
  845. >edit</i
  846. >
  847. <i
  848. v-if="
  849. playlist.createdBy !== myUserId &&
  850. (playlist.privacy === 'public' ||
  851. hasPermission('playlists.view.others'))
  852. "
  853. @click="
  854. openModal({
  855. modal: 'editPlaylist',
  856. props: { playlistId: playlist._id }
  857. })
  858. "
  859. class="material-icons edit-icon"
  860. content="View Playlist"
  861. v-tippy
  862. >visibility</i
  863. >
  864. </template>
  865. </playlist-item>
  866. </div>
  867. <p v-else class="has-text-centered scrollable-list">
  868. No playlists currently {{ label("present") }}.
  869. </p>
  870. </div>
  871. <div
  872. v-if="type === 'autorequest' || station.type === 'community'"
  873. class="tab"
  874. v-show="tab === 'my-playlists'"
  875. >
  876. <div
  877. class="menu-list scrollable-list"
  878. v-if="playlists.length > 0"
  879. >
  880. <draggable-list
  881. v-model:list="playlists"
  882. item-key="_id"
  883. @start="drag = true"
  884. @end="drag = false"
  885. @update="savePlaylistOrder"
  886. >
  887. <template #item="{ element }">
  888. <playlist-item :playlist="element">
  889. <template #item-icon>
  890. <i
  891. class="material-icons blacklisted-icon"
  892. v-if="
  893. isSelected(element._id, 'blacklist')
  894. "
  895. :content="`This playlist is currently ${label(
  896. 'past',
  897. 'blacklist'
  898. )}`"
  899. v-tippy
  900. >
  901. block
  902. </i>
  903. <i
  904. class="material-icons"
  905. v-else-if="isSelected(element._id)"
  906. :content="`This playlist is currently ${label(
  907. 'past'
  908. )}`"
  909. v-tippy
  910. >
  911. play_arrow
  912. </i>
  913. <i
  914. class="material-icons"
  915. v-else
  916. :content="`This playlist is currently not ${label(
  917. 'past'
  918. )}`"
  919. v-tippy
  920. >
  921. {{
  922. type === "blacklist"
  923. ? "block"
  924. : "play_disabled"
  925. }}
  926. </i>
  927. </template>
  928. <template #actions>
  929. <i
  930. v-if="
  931. type !== 'blacklist' &&
  932. isSelected(element._id, 'blacklist')
  933. "
  934. class="material-icons stop-icon"
  935. :content="`This playlist is ${label(
  936. 'past',
  937. 'blacklist'
  938. )} in this station`"
  939. v-tippy="{ theme: 'info' }"
  940. >play_disabled</i
  941. >
  942. <quick-confirm
  943. v-if="
  944. type !== 'blacklist' &&
  945. isSelected(element._id)
  946. "
  947. @confirm="deselectPlaylist(element._id)"
  948. >
  949. <i
  950. class="material-icons stop-icon"
  951. :content="`Stop ${label(
  952. 'present'
  953. )} songs from this playlist`"
  954. v-tippy
  955. >
  956. stop
  957. </i>
  958. </quick-confirm>
  959. <i
  960. v-if="
  961. type !== 'blacklist' &&
  962. !isSelected(element._id) &&
  963. !isSelected(
  964. element._id,
  965. 'blacklist'
  966. )
  967. "
  968. @click="selectPlaylist(element)"
  969. class="material-icons play-icon"
  970. :content="`${label(
  971. 'future',
  972. null,
  973. true
  974. )} songs from this playlist`"
  975. v-tippy
  976. >play_arrow</i
  977. >
  978. <quick-confirm
  979. v-if="
  980. type === 'blacklist' &&
  981. !isSelected(
  982. element._id,
  983. 'blacklist'
  984. )
  985. "
  986. @confirm="
  987. selectPlaylist(element, 'blacklist')
  988. "
  989. >
  990. <i
  991. class="material-icons stop-icon"
  992. :content="`${label(
  993. 'future',
  994. null,
  995. true
  996. )} Playlist`"
  997. v-tippy
  998. >block</i
  999. >
  1000. </quick-confirm>
  1001. <quick-confirm
  1002. v-if="
  1003. type === 'blacklist' &&
  1004. isSelected(element._id, 'blacklist')
  1005. "
  1006. @confirm="deselectPlaylist(element._id)"
  1007. >
  1008. <i
  1009. class="material-icons stop-icon"
  1010. :content="`Stop ${label(
  1011. 'present'
  1012. )} songs from this playlist`"
  1013. v-tippy
  1014. >
  1015. stop
  1016. </i>
  1017. </quick-confirm>
  1018. <i
  1019. @click="
  1020. openModal({
  1021. modal: 'editPlaylist',
  1022. props: {
  1023. playlistId: element._id
  1024. }
  1025. })
  1026. "
  1027. class="material-icons edit-icon"
  1028. content="Edit Playlist"
  1029. v-tippy
  1030. >edit</i
  1031. >
  1032. </template>
  1033. </playlist-item>
  1034. </template>
  1035. </draggable-list>
  1036. </div>
  1037. <p v-else class="has-text-centered scrollable-list">
  1038. You don't have any playlists
  1039. </p>
  1040. <button
  1041. class="button is-primary"
  1042. id="create-new-playlist-button"
  1043. @click="openModal('createPlaylist')"
  1044. >
  1045. Create new playlist
  1046. </button>
  1047. </div>
  1048. </div>
  1049. </div>
  1050. </template>
  1051. <style lang="less" scoped>
  1052. .night-mode {
  1053. .tabs-container .tab-selection .button {
  1054. background: var(--dark-grey) !important;
  1055. color: var(--white) !important;
  1056. }
  1057. }
  1058. .blacklisted-icon {
  1059. color: var(--dark-red);
  1060. }
  1061. .playlist-tab-base {
  1062. .top-info {
  1063. font-size: 15px;
  1064. margin-bottom: 15px;
  1065. }
  1066. .tabs-container {
  1067. .tab-selection {
  1068. display: flex;
  1069. overflow-x: auto;
  1070. .button {
  1071. border-radius: 0;
  1072. border: 0;
  1073. text-transform: uppercase;
  1074. font-size: 14px;
  1075. color: var(--dark-grey-3);
  1076. background-color: var(--light-grey-2);
  1077. flex-grow: 1;
  1078. height: 32px;
  1079. &:not(:first-of-type) {
  1080. margin-left: 5px;
  1081. }
  1082. }
  1083. .selected {
  1084. background-color: var(--primary-color) !important;
  1085. color: var(--white) !important;
  1086. font-weight: 600;
  1087. }
  1088. }
  1089. .tab {
  1090. padding: 15px 0;
  1091. border-radius: 0;
  1092. .playlist-item:not(:last-of-type) {
  1093. margin-bottom: 10px;
  1094. }
  1095. .load-more-button {
  1096. width: 100%;
  1097. margin-top: 10px;
  1098. }
  1099. }
  1100. }
  1101. }
  1102. .draggable-list-transition-move {
  1103. transition: transform 0.5s;
  1104. }
  1105. .draggable-list-ghost {
  1106. opacity: 0.5;
  1107. filter: brightness(95%);
  1108. }
  1109. </style>