index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. <template>
  2. <modal
  3. v-if="station"
  4. :title="
  5. !isOwnerOrAdmin() && station.partyMode
  6. ? 'Add Song to Queue'
  7. : 'Manage Station'
  8. "
  9. class="manage-station-modal"
  10. >
  11. <template #body>
  12. <div class="custom-modal-body" v-if="station && station._id">
  13. <div class="left-section">
  14. <div class="section tabs-container">
  15. <div class="tab-selection">
  16. <button
  17. v-if="isOwnerOrAdmin()"
  18. class="button is-default"
  19. :class="{ selected: tab === 'settings' }"
  20. @click="showTab('settings')"
  21. >
  22. Settings
  23. </button>
  24. <button
  25. v-if="
  26. isOwnerOrAdmin() ||
  27. (loggedIn &&
  28. station.type === 'community' &&
  29. station.partyMode &&
  30. ((station.locked &&
  31. isOwnerOrAdmin()) ||
  32. !station.locked))
  33. "
  34. class="button is-default"
  35. :class="{ selected: tab === 'playlists' }"
  36. @click="showTab('playlists')"
  37. >
  38. Playlists
  39. </button>
  40. <button
  41. v-if="
  42. loggedIn &&
  43. station.type === 'community' &&
  44. station.partyMode &&
  45. ((station.locked && isOwnerOrAdmin()) ||
  46. !station.locked)
  47. "
  48. class="button is-default"
  49. :class="{ selected: tab === 'search' }"
  50. @click="showTab('search')"
  51. >
  52. Search
  53. </button>
  54. <button
  55. v-if="isOwnerOrAdmin()"
  56. class="button is-default"
  57. :class="{ selected: tab === 'blacklist' }"
  58. @click="showTab('blacklist')"
  59. >
  60. Blacklist
  61. </button>
  62. </div>
  63. <settings
  64. v-if="isOwnerOrAdmin()"
  65. class="tab"
  66. v-show="tab === 'settings'"
  67. />
  68. <playlists
  69. v-if="
  70. isOwnerOrAdmin() ||
  71. (loggedIn &&
  72. station.type === 'community' &&
  73. station.partyMode &&
  74. ((station.locked && isOwnerOrAdmin()) ||
  75. !station.locked))
  76. "
  77. class="tab"
  78. v-show="tab === 'playlists'"
  79. />
  80. <search
  81. v-if="
  82. loggedIn &&
  83. station.type === 'community' &&
  84. station.partyMode &&
  85. ((station.locked && isOwnerOrAdmin()) ||
  86. !station.locked)
  87. "
  88. class="tab"
  89. v-show="tab === 'search'"
  90. />
  91. <blacklist
  92. v-if="isOwnerOrAdmin()"
  93. class="tab"
  94. v-show="tab === 'blacklist'"
  95. />
  96. </div>
  97. </div>
  98. <div class="right-section">
  99. <div class="section">
  100. <div class="queue-title">
  101. <h4 class="section-title">Queue</h4>
  102. <i
  103. v-if="isOwnerOrAdmin() && stationPaused"
  104. @click="resumeStation()"
  105. class="material-icons resume-station"
  106. content="Resume Station"
  107. v-tippy
  108. >
  109. play_arrow
  110. </i>
  111. <i
  112. v-if="isOwnerOrAdmin() && !stationPaused"
  113. @click="pauseStation()"
  114. class="material-icons pause-station"
  115. content="Pause Station"
  116. v-tippy
  117. >
  118. pause
  119. </i>
  120. <confirm
  121. v-if="isOwnerOrAdmin()"
  122. @confirm="skipStation()"
  123. >
  124. <i
  125. class="material-icons skip-station"
  126. content="Force Skip Station"
  127. v-tippy
  128. >
  129. skip_next
  130. </i>
  131. </confirm>
  132. </div>
  133. <hr class="section-horizontal-rule" />
  134. <song-item
  135. v-if="currentSong._id"
  136. :song="currentSong"
  137. :large-thumbnail="true"
  138. :requested-by="
  139. station.type === 'community' &&
  140. station.partyMode === true
  141. "
  142. header="Currently Playing.."
  143. class="currently-playing"
  144. />
  145. <queue sector="manageStation" />
  146. </div>
  147. </div>
  148. </div>
  149. </template>
  150. <template #footer>
  151. <a
  152. class="button is-default"
  153. v-if="isOwnerOrAdmin() && !station.partyMode"
  154. @click="stationPlaylist()"
  155. >
  156. View Station Playlist
  157. </a>
  158. <button
  159. class="button is-primary tab-actionable-button"
  160. v-if="loggedIn && station.type === 'official'"
  161. @click="openModal('requestSong')"
  162. >
  163. <i class="material-icons icon-with-button">queue</i>
  164. <span class="optional-desktop-only-text"> Request Song </span>
  165. </button>
  166. <div v-if="isOwnerOrAdmin()" class="right">
  167. <confirm @confirm="clearAndRefillStationQueue()">
  168. <a class="button is-danger">
  169. Clear and refill station queue
  170. </a>
  171. </confirm>
  172. <confirm
  173. v-if="station && station.type === 'community'"
  174. @confirm="removeStation()"
  175. >
  176. <button class="button is-danger">Delete station</button>
  177. </confirm>
  178. </div>
  179. </template>
  180. </modal>
  181. </template>
  182. <script>
  183. import { mapState, mapGetters, mapActions } from "vuex";
  184. import Toast from "toasters";
  185. import Confirm from "@/components/Confirm.vue";
  186. import Queue from "@/components/Queue.vue";
  187. import SongItem from "@/components/SongItem.vue";
  188. import Modal from "../../Modal.vue";
  189. import Settings from "./Tabs/Settings.vue";
  190. import Playlists from "./Tabs/Playlists.vue";
  191. import Search from "./Tabs/Search.vue";
  192. import Blacklist from "./Tabs/Blacklist.vue";
  193. export default {
  194. components: {
  195. Modal,
  196. Confirm,
  197. Queue,
  198. SongItem,
  199. Settings,
  200. Playlists,
  201. Search,
  202. Blacklist
  203. },
  204. props: {
  205. stationId: { type: String, default: "" },
  206. sector: { type: String, default: "admin" }
  207. },
  208. computed: {
  209. ...mapState({
  210. loggedIn: state => state.user.auth.loggedIn,
  211. userId: state => state.user.auth.userId,
  212. role: state => state.user.auth.role
  213. }),
  214. ...mapState("modals/manageStation", {
  215. tab: state => state.tab,
  216. station: state => state.station,
  217. originalStation: state => state.originalStation,
  218. songsList: state => state.songsList,
  219. includedPlaylists: state => state.includedPlaylists,
  220. excludedPlaylists: state => state.excludedPlaylists,
  221. stationPaused: state => state.stationPaused,
  222. currentSong: state => state.currentSong
  223. }),
  224. ...mapGetters({
  225. socket: "websockets/getSocket"
  226. })
  227. },
  228. mounted() {
  229. this.socket.dispatch(`stations.getStationById`, this.stationId, res => {
  230. if (res.status === "success") {
  231. const { station } = res.data;
  232. this.editStation(station);
  233. if (!this.isOwnerOrAdmin() && this.station.partyMode)
  234. this.showTab("search");
  235. const currentSong = res.data.station.currentSong
  236. ? res.data.station.currentSong
  237. : {};
  238. this.updateCurrentSong(currentSong);
  239. this.updateStationPaused(res.data.station.paused);
  240. this.socket.dispatch(
  241. "stations.getStationIncludedPlaylistsById",
  242. this.stationId,
  243. res => {
  244. if (res.status === "success")
  245. this.setIncludedPlaylists(res.data.playlists);
  246. }
  247. );
  248. this.socket.dispatch(
  249. "stations.getStationExcludedPlaylistsById",
  250. this.stationId,
  251. res => {
  252. if (res.status === "success")
  253. this.setExcludedPlaylists(res.data.playlists);
  254. }
  255. );
  256. this.socket.dispatch(
  257. "stations.getQueue",
  258. this.stationId,
  259. res => {
  260. if (res.status === "success")
  261. this.updateSongsList(res.data.queue);
  262. }
  263. );
  264. this.socket.dispatch(
  265. "apis.joinRoom",
  266. `manage-station.${this.stationId}`
  267. );
  268. this.socket.on(
  269. "event:station.updateName",
  270. res => {
  271. this.station.name = res.data.name;
  272. },
  273. { modal: "manageStation" }
  274. );
  275. this.socket.on(
  276. "event:station.updateDisplayName",
  277. res => {
  278. this.station.displayName = res.data.displayName;
  279. },
  280. { modal: "manageStation" }
  281. );
  282. this.socket.on(
  283. "event:station.updateDescription",
  284. res => {
  285. this.station.description = res.data.description;
  286. },
  287. { modal: "manageStation" }
  288. );
  289. this.socket.on(
  290. "event:partyMode.updated",
  291. res => {
  292. if (this.station.type === "community")
  293. this.station.partyMode = res.data.partyMode;
  294. },
  295. { modal: "manageStation" }
  296. );
  297. this.socket.on(
  298. "event:playMode.updated",
  299. res => {
  300. this.station.playMode = res.data.playMode;
  301. },
  302. { modal: "manageStation" }
  303. );
  304. this.socket.on(
  305. "event:station.themeUpdated",
  306. res => {
  307. const { theme } = res.data;
  308. this.station.theme = theme;
  309. },
  310. { modal: "manageStation" }
  311. );
  312. this.socket.on(
  313. "event:station.updatePrivacy",
  314. res => {
  315. this.station.privacy = res.data.privacy;
  316. },
  317. { modal: "manageStation" }
  318. );
  319. this.socket.on(
  320. "event:queueLockToggled",
  321. res => {
  322. this.station.locked = res.data.locked;
  323. },
  324. { modal: "manageStation" }
  325. );
  326. this.socket.on(
  327. "event:station.includedPlaylist",
  328. res => {
  329. const { playlist } = res.data;
  330. this.includedPlaylists.push(playlist);
  331. },
  332. { modal: "manageStation" }
  333. );
  334. this.socket.on(
  335. "event:station.excludedPlaylist",
  336. res => {
  337. const { playlist } = res.data;
  338. this.excludedPlaylists.push(playlist);
  339. },
  340. { modal: "manageStation" }
  341. );
  342. this.socket.on(
  343. "event:station.removedIncludedPlaylist",
  344. res => {
  345. const { playlistId } = res.data;
  346. const playlistIndex = this.includedPlaylists
  347. .map(playlist => playlist._id)
  348. .indexOf(playlistId);
  349. if (playlistIndex >= 0)
  350. this.includedPlaylists.splice(playlistIndex, 1);
  351. },
  352. { modal: "manageStation" }
  353. );
  354. this.socket.on(
  355. "event:station.removedExcludedPlaylist",
  356. res => {
  357. const { playlistId } = res.data;
  358. const playlistIndex = this.excludedPlaylists
  359. .map(playlist => playlist._id)
  360. .indexOf(playlistId);
  361. if (playlistIndex >= 0)
  362. this.excludedPlaylists.splice(playlistIndex, 1);
  363. },
  364. { modal: "manageStation" }
  365. );
  366. } else {
  367. new Toast(`Station with that ID not found`);
  368. this.closeModal("manageStation");
  369. }
  370. });
  371. this.socket.on(
  372. "event:queue.update",
  373. res => this.updateSongsList(res.data.queue),
  374. { modal: "manageStation" }
  375. );
  376. this.socket.on(
  377. "event:queue.repositionSong",
  378. res => this.repositionSongInList(res.data.song),
  379. { modal: "manageStation" }
  380. );
  381. this.socket.on(
  382. "event:stations.pause",
  383. () => this.updateStationPaused(true),
  384. { modal: "manageStation" }
  385. );
  386. this.socket.on(
  387. "event:stations.resume",
  388. () => this.updateStationPaused(false),
  389. { modal: "manageStation" }
  390. );
  391. this.socket.on(
  392. "event:songs.next",
  393. res => {
  394. const { currentSong } = res.data;
  395. this.updateCurrentSong(currentSong || {});
  396. },
  397. { modal: "manageStation" }
  398. );
  399. },
  400. beforeDestroy() {
  401. this.repositionSongInList([]);
  402. this.clearStation();
  403. this.showTab("settings");
  404. },
  405. methods: {
  406. isOwner() {
  407. return this.loggedIn && this.userId === this.station.owner;
  408. },
  409. isAdmin() {
  410. return this.loggedIn && this.role === "admin";
  411. },
  412. isOwnerOrAdmin() {
  413. return this.isOwner() || this.isAdmin();
  414. },
  415. removeStation() {
  416. this.socket.dispatch("stations.remove", this.station._id, res => {
  417. new Toast(res.message);
  418. if (res.status === "success") {
  419. this.closeModal("manageStation");
  420. }
  421. });
  422. },
  423. resumeStation() {
  424. this.socket.dispatch("stations.resume", this.station._id, res => {
  425. if (res.status !== "success")
  426. new Toast(`Error: ${res.message}`);
  427. else new Toast("Successfully resumed the station.");
  428. });
  429. },
  430. pauseStation() {
  431. this.socket.dispatch("stations.pause", this.station._id, res => {
  432. if (res.status !== "success")
  433. new Toast(`Error: ${res.message}`);
  434. else new Toast("Successfully paused the station.");
  435. });
  436. },
  437. skipStation() {
  438. this.socket.dispatch(
  439. "stations.forceSkip",
  440. this.station._id,
  441. res => {
  442. if (res.status !== "success")
  443. new Toast(`Error: ${res.message}`);
  444. else
  445. new Toast(
  446. "Successfully skipped the station's current song."
  447. );
  448. }
  449. );
  450. },
  451. clearAndRefillStationQueue() {
  452. this.socket.dispatch(
  453. "stations.clearAndRefillStationQueue",
  454. this.station._id,
  455. res => {
  456. if (res.status !== "success")
  457. new Toast({
  458. content: `Error: ${res.message}`,
  459. timeout: 8000
  460. });
  461. else new Toast({ content: res.message, timeout: 4000 });
  462. }
  463. );
  464. },
  465. stationPlaylist() {
  466. this.socket.dispatch(
  467. "playlists.getPlaylistForStation",
  468. this.station._id,
  469. false,
  470. res => {
  471. if (res.status === "success") {
  472. this.editPlaylist(res.data.playlist._id);
  473. this.openModal("editPlaylist");
  474. } else {
  475. new Toast(res.message);
  476. }
  477. }
  478. );
  479. },
  480. ...mapActions("modals/manageStation", [
  481. "showTab",
  482. "editStation",
  483. "setIncludedPlaylists",
  484. "setExcludedPlaylists",
  485. "clearStation",
  486. "updateSongsList",
  487. "repositionSongInList",
  488. "updateStationPaused",
  489. "updateCurrentSong"
  490. ]),
  491. ...mapActions("modalVisibility", ["openModal", "closeModal"]),
  492. ...mapActions("user/playlists", ["editPlaylist"])
  493. }
  494. };
  495. </script>
  496. <style lang="scss">
  497. .manage-station-modal.modal {
  498. z-index: 1800;
  499. .modal-card {
  500. width: 1300px;
  501. height: 100%;
  502. overflow: auto;
  503. .tab > button {
  504. width: 100%;
  505. margin-bottom: 10px;
  506. }
  507. }
  508. }
  509. </style>
  510. <style lang="scss" scoped>
  511. .manage-station-modal.modal .modal-card-body .custom-modal-body {
  512. display: flex;
  513. flex-wrap: wrap;
  514. height: 100%;
  515. .section {
  516. display: flex;
  517. flex-direction: column;
  518. flex-grow: 1;
  519. width: auto;
  520. padding: 15px !important;
  521. margin: 0 10px;
  522. }
  523. .left-section {
  524. flex-basis: 50%;
  525. height: 100%;
  526. overflow-y: auto;
  527. flex-grow: 1;
  528. .tabs-container {
  529. .tab-selection {
  530. display: flex;
  531. .button {
  532. border-radius: 5px 5px 0 0;
  533. border: 0;
  534. text-transform: uppercase;
  535. font-size: 14px;
  536. color: var(--dark-grey-3);
  537. background-color: var(--light-grey-2);
  538. flex-grow: 1;
  539. height: 32px;
  540. &:not(:first-of-type) {
  541. margin-left: 5px;
  542. }
  543. }
  544. .selected {
  545. background-color: var(--dark-grey-3) !important;
  546. color: var(--white) !important;
  547. }
  548. }
  549. .tab {
  550. border: 1px solid var(--light-grey-3);
  551. padding: 15px;
  552. border-radius: 0 0 5px 5px;
  553. }
  554. }
  555. }
  556. .right-section {
  557. flex-basis: 50%;
  558. height: 100%;
  559. overflow-y: auto;
  560. flex-grow: 1;
  561. .section {
  562. .queue-title {
  563. display: flex;
  564. line-height: 30px;
  565. .material-icons {
  566. margin-left: 5px;
  567. margin-bottom: 5px;
  568. font-size: 28px;
  569. cursor: pointer;
  570. &:first-of-type {
  571. margin-left: auto;
  572. }
  573. &.skip-station {
  574. color: var(--red);
  575. }
  576. &.resume-station,
  577. &.pause-station {
  578. color: var(--primary-color);
  579. }
  580. }
  581. }
  582. .currently-playing {
  583. margin-bottom: 10px;
  584. }
  585. }
  586. }
  587. }
  588. @media screen and (max-width: 1100px) {
  589. .manage-station-modal.modal .modal-card-body .custom-modal-body {
  590. .left-section,
  591. .right-section {
  592. flex-basis: unset;
  593. height: auto;
  594. }
  595. }
  596. }
  597. </style>