index.vue 15 KB

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