PlaylistTabBase.vue 25 KB

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