index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  1. <template>
  2. <modal
  3. v-if="station"
  4. :title="
  5. !isOwnerOrAdmin() && station.partyMode
  6. ? 'Add Song to Queue'
  7. : 'Manage Station'
  8. "
  9. :style="`--primary-color: var(--${station.theme})`"
  10. class="manage-station-modal"
  11. :wide="true"
  12. :split="true"
  13. >
  14. <template #body v-if="station && station._id">
  15. <div class="left-section">
  16. <div class="section">
  17. <div id="about-station-container">
  18. <div id="station-info">
  19. <div id="station-name">
  20. <h1>{{ station.displayName }}</h1>
  21. <i
  22. v-if="station.type === 'official'"
  23. class="material-icons verified-station"
  24. content="Verified Station"
  25. v-tippy
  26. >
  27. check_circle
  28. </i>
  29. <i
  30. class="material-icons stationMode"
  31. :content="
  32. station.partyMode
  33. ? 'Station in Party mode'
  34. : 'Station in Playlist mode'
  35. "
  36. v-tippy
  37. >{{
  38. station.partyMode
  39. ? "emoji_people"
  40. : "playlist_play"
  41. }}</i
  42. >
  43. </div>
  44. <p>{{ station.description }}</p>
  45. </div>
  46. <div id="admin-buttons" v-if="isOwnerOrAdmin()">
  47. <!-- (Admin) Pause/Resume Button -->
  48. <button
  49. class="button is-danger"
  50. v-if="stationPaused"
  51. @click="resumeStation()"
  52. >
  53. <i class="material-icons icon-with-button"
  54. >play_arrow</i
  55. >
  56. <span> Resume Station </span>
  57. </button>
  58. <button
  59. class="button is-danger"
  60. @click="pauseStation()"
  61. v-else
  62. >
  63. <i class="material-icons icon-with-button"
  64. >pause</i
  65. >
  66. <span> Pause Station </span>
  67. </button>
  68. <!-- (Admin) Skip Button -->
  69. <button
  70. class="button is-danger"
  71. @click="skipStation()"
  72. >
  73. <i class="material-icons icon-with-button"
  74. >skip_next</i
  75. >
  76. <span> Force Skip </span>
  77. </button>
  78. <router-link
  79. v-if="sector !== 'station' && station.name"
  80. :to="{
  81. name: 'station',
  82. params: { id: station.name }
  83. }"
  84. class="button is-primary"
  85. >
  86. Go To Station
  87. </router-link>
  88. </div>
  89. </div>
  90. <div class="tab-selection">
  91. <button
  92. v-if="isOwnerOrAdmin()"
  93. class="button is-default"
  94. :class="{ selected: tab === 'settings' }"
  95. ref="settings-tab"
  96. @click="showTab('settings')"
  97. >
  98. Settings
  99. </button>
  100. <button
  101. v-if="isAllowedToParty() || isOwnerOrAdmin()"
  102. class="button is-default"
  103. :class="{ selected: tab === 'playlists' }"
  104. ref="playlists-tab"
  105. @click="showTab('playlists')"
  106. >
  107. Playlists
  108. </button>
  109. <button
  110. v-if="isAllowedToParty() || isOwnerOrAdmin()"
  111. class="button is-default"
  112. :class="{ selected: tab === 'songs' }"
  113. ref="songs-tab"
  114. @click="showTab('songs')"
  115. >
  116. Songs
  117. </button>
  118. </div>
  119. <settings
  120. v-if="isOwnerOrAdmin()"
  121. class="tab"
  122. v-show="tab === 'settings'"
  123. />
  124. <playlists
  125. v-if="isAllowedToParty() || isOwnerOrAdmin()"
  126. class="tab"
  127. v-show="tab === 'playlists'"
  128. />
  129. <songs
  130. v-if="isAllowedToParty() || isOwnerOrAdmin()"
  131. class="tab"
  132. v-show="tab === 'songs'"
  133. />
  134. </div>
  135. </div>
  136. <div class="right-section">
  137. <div class="section">
  138. <div class="queue-title">
  139. <h4 class="section-title">Queue</h4>
  140. </div>
  141. <hr class="section-horizontal-rule" />
  142. <song-item
  143. v-if="currentSong._id"
  144. :song="currentSong"
  145. :requested-by="
  146. station.type === 'community' &&
  147. station.partyMode === true
  148. "
  149. header="Currently Playing.."
  150. class="currently-playing"
  151. />
  152. <queue sector="manageStation" />
  153. </div>
  154. </div>
  155. </template>
  156. <template #footer>
  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> 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 Songs from "./Tabs/Songs.vue";
  191. export default {
  192. components: {
  193. Modal,
  194. Confirm,
  195. Queue,
  196. SongItem,
  197. Settings,
  198. Playlists,
  199. Songs
  200. },
  201. props: {
  202. stationId: { type: String, default: "" },
  203. sector: { type: String, default: "admin" }
  204. },
  205. computed: {
  206. ...mapState({
  207. loggedIn: state => state.user.auth.loggedIn,
  208. userId: state => state.user.auth.userId,
  209. role: state => state.user.auth.role
  210. }),
  211. ...mapState("modals/manageStation", {
  212. tab: state => state.tab,
  213. station: state => state.station,
  214. originalStation: state => state.originalStation,
  215. songsList: state => state.songsList,
  216. stationPlaylist: state => state.stationPlaylist,
  217. includedPlaylists: state => state.includedPlaylists,
  218. excludedPlaylists: state => state.excludedPlaylists,
  219. stationPaused: state => state.stationPaused,
  220. currentSong: state => state.currentSong
  221. }),
  222. ...mapGetters({
  223. socket: "websockets/getSocket"
  224. })
  225. },
  226. mounted() {
  227. this.socket.dispatch(`stations.getStationById`, this.stationId, res => {
  228. if (res.status === "success") {
  229. const { station } = res.data;
  230. this.editStation(station);
  231. if (!this.isOwnerOrAdmin() && this.station.partyMode)
  232. this.showTab("songs");
  233. const currentSong = res.data.station.currentSong
  234. ? res.data.station.currentSong
  235. : {};
  236. this.updateCurrentSong(currentSong);
  237. this.updateStationPaused(res.data.station.paused);
  238. this.socket.dispatch(
  239. "stations.getStationIncludedPlaylistsById",
  240. this.stationId,
  241. res => {
  242. if (res.status === "success")
  243. this.setIncludedPlaylists(res.data.playlists);
  244. }
  245. );
  246. this.socket.dispatch(
  247. "stations.getStationExcludedPlaylistsById",
  248. this.stationId,
  249. res => {
  250. if (res.status === "success")
  251. this.setExcludedPlaylists(res.data.playlists);
  252. }
  253. );
  254. if (this.isOwnerOrAdmin()) {
  255. this.socket.dispatch(
  256. "playlists.getPlaylistForStation",
  257. this.station._id,
  258. true,
  259. res => {
  260. if (res.status === "success") {
  261. this.updateStationPlaylist(res.data.playlist);
  262. }
  263. }
  264. );
  265. }
  266. this.socket.dispatch(
  267. "stations.getQueue",
  268. this.stationId,
  269. res => {
  270. if (res.status === "success")
  271. this.updateSongsList(res.data.queue);
  272. }
  273. );
  274. this.socket.dispatch(
  275. "apis.joinRoom",
  276. `manage-station.${this.stationId}`
  277. );
  278. this.socket.on(
  279. "event:station.name.updated",
  280. res => {
  281. this.station.name = res.data.name;
  282. },
  283. { modal: "manageStation" }
  284. );
  285. this.socket.on(
  286. "event:station.displayName.updated",
  287. res => {
  288. this.station.displayName = res.data.displayName;
  289. },
  290. { modal: "manageStation" }
  291. );
  292. this.socket.on(
  293. "event:station.description.updated",
  294. res => {
  295. this.station.description = res.data.description;
  296. },
  297. { modal: "manageStation" }
  298. );
  299. this.socket.on(
  300. "event:station.partyMode.updated",
  301. res => {
  302. if (this.station.type === "community")
  303. this.station.partyMode = res.data.partyMode;
  304. },
  305. { modal: "manageStation" }
  306. );
  307. this.socket.on(
  308. "event:station.playMode.updated",
  309. res => {
  310. this.station.playMode = res.data.playMode;
  311. },
  312. { modal: "manageStation" }
  313. );
  314. this.socket.on(
  315. "event:station.theme.updated",
  316. res => {
  317. const { theme } = res.data;
  318. this.station.theme = theme;
  319. },
  320. { modal: "manageStation" }
  321. );
  322. this.socket.on(
  323. "event:station.privacy.updated",
  324. res => {
  325. this.station.privacy = res.data.privacy;
  326. },
  327. { modal: "manageStation" }
  328. );
  329. this.socket.on(
  330. "event:station.queue.lock.toggled",
  331. res => {
  332. this.station.locked = res.data.locked;
  333. },
  334. { modal: "manageStation" }
  335. );
  336. this.socket.on(
  337. "event:station.includedPlaylist",
  338. res => {
  339. const { playlist } = res.data;
  340. const playlistIndex = this.includedPlaylists
  341. .map(includedPlaylist => includedPlaylist._id)
  342. .indexOf(playlist._id);
  343. if (playlistIndex === -1)
  344. this.includedPlaylists.push(playlist);
  345. },
  346. { modal: "manageStation" }
  347. );
  348. this.socket.on(
  349. "event:station.excludedPlaylist",
  350. res => {
  351. const { playlist } = res.data;
  352. const playlistIndex = this.excludedPlaylists
  353. .map(excludedPlaylist => excludedPlaylist._id)
  354. .indexOf(playlist._id);
  355. if (playlistIndex === -1)
  356. this.excludedPlaylists.push(playlist);
  357. },
  358. { modal: "manageStation" }
  359. );
  360. this.socket.on(
  361. "event:station.removedIncludedPlaylist",
  362. res => {
  363. const { playlistId } = res.data;
  364. const playlistIndex = this.includedPlaylists
  365. .map(playlist => playlist._id)
  366. .indexOf(playlistId);
  367. if (playlistIndex >= 0)
  368. this.includedPlaylists.splice(playlistIndex, 1);
  369. },
  370. { modal: "manageStation" }
  371. );
  372. this.socket.on(
  373. "event:station.removedExcludedPlaylist",
  374. res => {
  375. const { playlistId } = res.data;
  376. const playlistIndex = this.excludedPlaylists
  377. .map(playlist => playlist._id)
  378. .indexOf(playlistId);
  379. if (playlistIndex >= 0)
  380. this.excludedPlaylists.splice(playlistIndex, 1);
  381. },
  382. { modal: "manageStation" }
  383. );
  384. this.socket.on(
  385. "event:station.deleted",
  386. () => {
  387. new Toast(`The station you were editing was deleted.`);
  388. this.closeModal("manageStation");
  389. },
  390. { modal: "manageStation" }
  391. );
  392. } else {
  393. new Toast(`Station with that ID not found`);
  394. this.closeModal("manageStation");
  395. }
  396. });
  397. this.socket.on(
  398. "event:station.queue.updated",
  399. res => this.updateSongsList(res.data.queue),
  400. { modal: "manageStation" }
  401. );
  402. this.socket.on(
  403. "event:station.queue.song.repositioned",
  404. res => this.repositionSongInList(res.data.song),
  405. { modal: "manageStation" }
  406. );
  407. this.socket.on(
  408. "event:station.pause",
  409. () => this.updateStationPaused(true),
  410. { modal: "manageStation" }
  411. );
  412. this.socket.on(
  413. "event:station.resume",
  414. () => this.updateStationPaused(false),
  415. { modal: "manageStation" }
  416. );
  417. this.socket.on(
  418. "event:station.nextSong",
  419. res => {
  420. const { currentSong } = res.data;
  421. this.updateCurrentSong(currentSong || {});
  422. },
  423. { modal: "manageStation" }
  424. );
  425. if (this.isOwnerOrAdmin()) {
  426. this.socket.on(
  427. "event:playlist.song.added",
  428. res => {
  429. if (this.stationPlaylist._id === res.data.playlistId)
  430. this.stationPlaylist.songs.push(res.data.song);
  431. },
  432. {
  433. modal: "manageStation"
  434. }
  435. );
  436. this.socket.on(
  437. "event:playlist.song.removed",
  438. res => {
  439. if (this.stationPlaylist._id === res.data.playlistId) {
  440. // remove song from array of playlists
  441. this.stationPlaylist.songs.forEach((song, index) => {
  442. if (song.youtubeId === res.data.youtubeId)
  443. this.stationPlaylist.songs.splice(index, 1);
  444. });
  445. }
  446. },
  447. {
  448. modal: "manageStation"
  449. }
  450. );
  451. this.socket.on(
  452. "event:playlist.songs.repositioned",
  453. res => {
  454. if (this.stationPlaylist._id === res.data.playlistId) {
  455. // for each song that has a new position
  456. res.data.songsBeingChanged.forEach(changedSong => {
  457. this.stationPlaylist.songs.forEach(
  458. (song, index) => {
  459. // find song locally
  460. if (
  461. song.youtubeId === changedSong.youtubeId
  462. ) {
  463. // change song position attribute
  464. this.stationPlaylist.songs[
  465. index
  466. ].position = changedSong.position;
  467. // reposition in array if needed
  468. if (index !== changedSong.position - 1)
  469. this.stationPlaylist.songs.splice(
  470. changedSong.position - 1,
  471. 0,
  472. this.stationPlaylist.songs.splice(
  473. index,
  474. 1
  475. )[0]
  476. );
  477. }
  478. }
  479. );
  480. });
  481. }
  482. },
  483. {
  484. modal: "manageStation"
  485. }
  486. );
  487. }
  488. },
  489. beforeUnmount() {
  490. this.socket.dispatch(
  491. "apis.leaveRoom",
  492. `manage-station.${this.stationId}`,
  493. () => {}
  494. );
  495. if (this.isOwnerOrAdmin()) this.showTab("settings");
  496. this.clearStation();
  497. },
  498. methods: {
  499. isOwner() {
  500. return (
  501. this.loggedIn &&
  502. this.station &&
  503. this.userId === this.station.owner
  504. );
  505. },
  506. isAdmin() {
  507. return this.loggedIn && this.role === "admin";
  508. },
  509. isOwnerOrAdmin() {
  510. return this.isOwner() || this.isAdmin();
  511. },
  512. isPartyMode() {
  513. return (
  514. this.station &&
  515. this.station.type === "community" &&
  516. this.station.partyMode
  517. );
  518. },
  519. isAllowedToParty() {
  520. return (
  521. this.station &&
  522. this.isPartyMode() &&
  523. (!this.station.locked || this.isOwnerOrAdmin()) &&
  524. this.loggedIn
  525. );
  526. },
  527. isPlaylistMode() {
  528. return this.station && !this.isPartyMode();
  529. },
  530. removeStation() {
  531. this.socket.dispatch("stations.remove", this.station._id, res => {
  532. new Toast(res.message);
  533. });
  534. },
  535. resumeStation() {
  536. this.socket.dispatch("stations.resume", this.station._id, res => {
  537. if (res.status !== "success")
  538. new Toast(`Error: ${res.message}`);
  539. else new Toast("Successfully resumed the station.");
  540. });
  541. },
  542. pauseStation() {
  543. this.socket.dispatch("stations.pause", this.station._id, res => {
  544. if (res.status !== "success")
  545. new Toast(`Error: ${res.message}`);
  546. else new Toast("Successfully paused the station.");
  547. });
  548. },
  549. skipStation() {
  550. this.socket.dispatch(
  551. "stations.forceSkip",
  552. this.station._id,
  553. res => {
  554. if (res.status !== "success")
  555. new Toast(`Error: ${res.message}`);
  556. else
  557. new Toast(
  558. "Successfully skipped the station's current song."
  559. );
  560. }
  561. );
  562. },
  563. clearAndRefillStationQueue() {
  564. this.socket.dispatch(
  565. "stations.clearAndRefillStationQueue",
  566. this.station._id,
  567. res => {
  568. if (res.status !== "success")
  569. new Toast({
  570. content: `Error: ${res.message}`,
  571. timeout: 8000
  572. });
  573. else new Toast({ content: res.message, timeout: 4000 });
  574. }
  575. );
  576. },
  577. ...mapActions("modals/manageStation", [
  578. "editStation",
  579. "setIncludedPlaylists",
  580. "setExcludedPlaylists",
  581. "clearStation",
  582. "updateSongsList",
  583. "updateStationPlaylist",
  584. "repositionSongInList",
  585. "updateStationPaused",
  586. "updateCurrentSong"
  587. ]),
  588. ...mapActions({
  589. showTab(dispatch, payload) {
  590. if (this.$refs[`${payload}-tab`])
  591. this.$refs[`${payload}-tab`].scrollIntoView({
  592. block: "nearest"
  593. }); // Only works if the ref exists, which it doesn't always
  594. return dispatch("modals/manageStation/showTab", payload);
  595. }
  596. }),
  597. ...mapActions("modalVisibility", ["openModal", "closeModal"]),
  598. ...mapActions("user/playlists", ["editPlaylist"])
  599. }
  600. };
  601. </script>
  602. <style lang="scss">
  603. .manage-station-modal.modal .modal-card {
  604. .tab > button {
  605. width: 100%;
  606. margin-bottom: 10px;
  607. }
  608. .currently-playing.song-item {
  609. .thumbnail {
  610. min-width: 130px;
  611. width: 130px;
  612. height: 130px;
  613. }
  614. }
  615. }
  616. </style>
  617. <style lang="scss" scoped>
  618. .night-mode {
  619. .manage-station-modal.modal .modal-card-body {
  620. .left-section {
  621. #about-station-container {
  622. background-color: var(--dark-grey-3) !important;
  623. border: 0;
  624. }
  625. .section {
  626. background-color: transparent !important;
  627. }
  628. .tab-selection .button {
  629. background: var(--dark-grey);
  630. color: var(--white);
  631. }
  632. .tab {
  633. background-color: var(--dark-grey-3);
  634. border: 0;
  635. }
  636. }
  637. .right-section .section,
  638. #queue {
  639. border-radius: 5px;
  640. background-color: transparent !important;
  641. }
  642. }
  643. }
  644. .manage-station-modal.modal .modal-card-body {
  645. display: flex;
  646. flex-wrap: wrap;
  647. height: 100%;
  648. .left-section {
  649. .section:first-child {
  650. padding: 0 15px 15px !important;
  651. }
  652. #about-station-container {
  653. padding: 20px;
  654. display: flex;
  655. flex-direction: column;
  656. flex-grow: unset;
  657. border-radius: 5px;
  658. margin: 0 0 20px 0;
  659. background-color: var(--white);
  660. border: 1px solid var(--light-grey-3);
  661. #station-info {
  662. #station-name {
  663. flex-direction: row !important;
  664. display: flex;
  665. flex-direction: row;
  666. max-width: 100%;
  667. h1 {
  668. margin: 0;
  669. font-size: 36px;
  670. line-height: 0.8;
  671. }
  672. i {
  673. margin-left: 10px;
  674. font-size: 30px;
  675. color: var(--yellow);
  676. &.stationMode {
  677. padding-left: 10px;
  678. margin-left: auto;
  679. color: var(--primary-color);
  680. }
  681. }
  682. .verified-station {
  683. color: var(--primary-color);
  684. }
  685. }
  686. p {
  687. max-width: 700px;
  688. margin-bottom: 10px;
  689. }
  690. }
  691. #admin-buttons {
  692. display: flex;
  693. .button {
  694. margin: 3px;
  695. }
  696. }
  697. }
  698. .tab-selection {
  699. display: flex;
  700. overflow-x: auto;
  701. .button {
  702. border-radius: 5px 5px 0 0;
  703. border: 0;
  704. text-transform: uppercase;
  705. font-size: 14px;
  706. color: var(--dark-grey-3);
  707. background-color: var(--light-grey-2);
  708. flex-grow: 1;
  709. height: 32px;
  710. &:not(:first-of-type) {
  711. margin-left: 5px;
  712. }
  713. }
  714. .selected {
  715. background-color: var(--primary-color) !important;
  716. color: var(--white) !important;
  717. font-weight: 600;
  718. }
  719. }
  720. .tab {
  721. border: 1px solid var(--light-grey-3);
  722. padding: 15px;
  723. border-radius: 0 0 5px 5px;
  724. }
  725. }
  726. .right-section {
  727. .section {
  728. .queue-title {
  729. display: flex;
  730. line-height: 30px;
  731. .material-icons {
  732. margin-left: 5px;
  733. margin-bottom: 5px;
  734. font-size: 28px;
  735. cursor: pointer;
  736. &:first-of-type {
  737. margin-left: auto;
  738. }
  739. &.skip-station {
  740. color: var(--red);
  741. }
  742. &.resume-station,
  743. &.pause-station {
  744. color: var(--primary-color);
  745. }
  746. }
  747. }
  748. .currently-playing {
  749. margin-bottom: 10px;
  750. }
  751. }
  752. }
  753. }
  754. </style>