EditSongs.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. <template>
  2. <div>
  3. <edit-song
  4. :modal-module-path="`modals/editSongs/${modalUuid}/editSong`"
  5. :modal-uuid="modalUuid"
  6. :bulk="true"
  7. :flagged="currentSongFlagged"
  8. v-if="currentSong"
  9. @savedSuccess="onSavedSuccess"
  10. @savedError="onSavedError"
  11. @saving="onSaving"
  12. @toggleFlag="toggleFlag"
  13. @nextSong="editNextSong"
  14. @close="onClose"
  15. >
  16. <template #toggleMobileSidebar>
  17. <i
  18. class="material-icons toggle-sidebar-icon"
  19. :content="`${
  20. sidebarMobileActive ? 'Close' : 'Open'
  21. } Edit Queue`"
  22. v-tippy
  23. @click="toggleMobileSidebar()"
  24. >expand_circle_down</i
  25. >
  26. </template>
  27. <template #sidebar>
  28. <div class="sidebar" :class="{ active: sidebarMobileActive }">
  29. <header class="sidebar-head">
  30. <h2 class="sidebar-title is-marginless">Edit Queue</h2>
  31. <i
  32. class="material-icons toggle-sidebar-icon"
  33. :content="`${
  34. sidebarMobileActive ? 'Close' : 'Open'
  35. } Edit Queue`"
  36. v-tippy
  37. @click="toggleMobileSidebar()"
  38. >expand_circle_down</i
  39. >
  40. </header>
  41. <section class="sidebar-body">
  42. <div
  43. v-show="filteredItems.length > 0"
  44. class="edit-songs-items"
  45. >
  46. <div
  47. class="item"
  48. v-for="(
  49. { status, flagged, song }, index
  50. ) in filteredItems"
  51. :key="`edit-songs-item-${index}`"
  52. :ref="`edit-songs-item-${song.youtubeId}`"
  53. >
  54. <song-item
  55. :song="song"
  56. :thumbnail="false"
  57. :duration="false"
  58. :disabled-actions="
  59. song.removed
  60. ? ['all']
  61. : ['report', 'edit']
  62. "
  63. :class="{
  64. updated: song.updated,
  65. removed: song.removed
  66. }"
  67. >
  68. <template #leftIcon>
  69. <i
  70. v-if="
  71. currentSong.youtubeId ===
  72. song.youtubeId &&
  73. !song.removed
  74. "
  75. class="material-icons item-icon editing-icon"
  76. content="Currently editing song"
  77. v-tippy="{ theme: 'info' }"
  78. @click="toggleDone(index)"
  79. >edit</i
  80. >
  81. <i
  82. v-else-if="song.removed"
  83. class="material-icons item-icon removed-icon"
  84. content="Song removed"
  85. v-tippy="{ theme: 'info' }"
  86. >delete_forever</i
  87. >
  88. <i
  89. v-else-if="status === 'error'"
  90. class="material-icons item-icon error-icon"
  91. content="Error saving song"
  92. v-tippy="{ theme: 'info' }"
  93. @click="toggleDone(index)"
  94. >error</i
  95. >
  96. <i
  97. v-else-if="status === 'saving'"
  98. class="material-icons item-icon saving-icon"
  99. content="Currently saving song"
  100. v-tippy="{ theme: 'info' }"
  101. >pending</i
  102. >
  103. <i
  104. v-else-if="flagged"
  105. class="material-icons item-icon flag-icon"
  106. content="Song flagged"
  107. v-tippy="{ theme: 'info' }"
  108. @click="toggleDone(index)"
  109. >flag_circle</i
  110. >
  111. <i
  112. v-else-if="status === 'done'"
  113. class="material-icons item-icon done-icon"
  114. content="Song marked complete"
  115. v-tippy="{ theme: 'info' }"
  116. @click="toggleDone(index)"
  117. >check_circle</i
  118. >
  119. <i
  120. v-else-if="status === 'todo'"
  121. class="material-icons item-icon todo-icon"
  122. content="Song marked todo"
  123. v-tippy="{ theme: 'info' }"
  124. @click="toggleDone(index)"
  125. >cancel</i
  126. >
  127. </template>
  128. <template v-if="!song.removed" #actions>
  129. <i
  130. class="material-icons edit-icon"
  131. content="Edit Song"
  132. v-tippy
  133. @click="pickSong(song)"
  134. >
  135. edit
  136. </i>
  137. </template>
  138. <template #tippyActions>
  139. <i
  140. class="material-icons flag-icon"
  141. :class="{ flagged }"
  142. content="Toggle Flag"
  143. v-tippy
  144. @click="toggleFlag(index)"
  145. >
  146. flag_circle
  147. </i>
  148. </template>
  149. </song-item>
  150. </div>
  151. </div>
  152. <p v-if="filteredItems.length === 0" class="no-items">
  153. {{
  154. flagFilter
  155. ? "No flagged songs queued"
  156. : "No songs queued"
  157. }}
  158. </p>
  159. </section>
  160. <footer class="sidebar-foot">
  161. <button
  162. @click="toggleFlagFilter()"
  163. class="button is-primary"
  164. >
  165. {{
  166. flagFilter
  167. ? "Show All Songs"
  168. : "Show Only Flagged Songs"
  169. }}
  170. </button>
  171. </footer>
  172. </div>
  173. <div
  174. v-if="sidebarMobileActive"
  175. class="sidebar-overlay"
  176. @click="toggleMobileSidebar()"
  177. ></div>
  178. </template>
  179. </edit-song>
  180. </div>
  181. </template>
  182. <script>
  183. import { mapActions, mapGetters } from "vuex";
  184. import { defineAsyncComponent } from "vue";
  185. import Toast from "toasters";
  186. import { mapModalState, mapModalActions } from "@/vuex_helpers";
  187. import SongItem from "@/components/SongItem.vue";
  188. import editSong from "@/store/modules/modals/editSong";
  189. export default {
  190. components: {
  191. EditSong: defineAsyncComponent(() =>
  192. import("@/components/modals/EditSong/index.vue")
  193. ),
  194. SongItem
  195. },
  196. props: {
  197. modalUuid: { type: String, default: "" }
  198. },
  199. data() {
  200. return {
  201. items: [],
  202. currentSong: {},
  203. flagFilter: false,
  204. sidebarMobileActive: false
  205. };
  206. },
  207. computed: {
  208. editingItemIndex() {
  209. return this.items.findIndex(
  210. item => item.song.youtubeId === this.currentSong.youtubeId
  211. );
  212. },
  213. filteredEditingItemIndex() {
  214. return this.filteredItems.findIndex(
  215. item => item.song.youtubeId === this.currentSong.youtubeId
  216. );
  217. },
  218. filteredItems: {
  219. get() {
  220. return this.items.filter(item =>
  221. this.flagFilter ? item.flagged : true
  222. );
  223. },
  224. set(newItem) {
  225. const index = this.items.findIndex(
  226. item => item.song.youtubeId === newItem.youtubeId
  227. );
  228. this.item[index] = newItem;
  229. }
  230. },
  231. currentSongFlagged() {
  232. return this.items.find(
  233. item => item.song.youtubeId === this.currentSong.youtubeId
  234. )?.flagged;
  235. },
  236. ...mapModalState("modals/editSongs/MODAL_UUID", {
  237. youtubeIds: state => state.youtubeIds,
  238. songPrefillData: state => state.songPrefillData
  239. }),
  240. ...mapGetters({
  241. socket: "websockets/getSocket"
  242. })
  243. },
  244. beforeMount() {
  245. console.log("EDITSONGS BEFOREMOUNT");
  246. this.$store.registerModule(
  247. ["modals", "editSongs", this.modalUuid, "editSong"],
  248. editSong
  249. );
  250. },
  251. async mounted() {
  252. console.log("EDITSONGS MOUNTED");
  253. this.socket.dispatch("apis.joinRoom", "edit-songs");
  254. this.socket.dispatch(
  255. "songs.getSongsFromYoutubeIds",
  256. this.youtubeIds,
  257. res => {
  258. if (res.data.songs.length === 0) {
  259. this.closeThisModal();
  260. new Toast("You can't edit 0 songs.");
  261. } else {
  262. this.items = res.data.songs.map(song => ({
  263. status: "todo",
  264. flagged: false,
  265. song
  266. }));
  267. this.editNextSong();
  268. }
  269. }
  270. );
  271. this.socket.on(
  272. `event:admin.song.created`,
  273. res => {
  274. const index = this.items
  275. .map(item => item.song.youtubeId)
  276. .indexOf(res.data.song.youtubeId);
  277. if (index >= 0)
  278. this.items[index].song = {
  279. ...this.items[index].song,
  280. ...res.data.song,
  281. created: true
  282. };
  283. },
  284. { modalUuid: this.modalUuid }
  285. );
  286. this.socket.on(
  287. `event:admin.song.updated`,
  288. res => {
  289. const index = this.items
  290. .map(item => item.song.youtubeId)
  291. .indexOf(res.data.song.youtubeId);
  292. if (index >= 0)
  293. this.items[index].song = {
  294. ...this.items[index].song,
  295. ...res.data.song,
  296. updated: true
  297. };
  298. },
  299. { modalUuid: this.modalUuid }
  300. );
  301. this.socket.on(
  302. `event:admin.song.removed`,
  303. res => {
  304. const index = this.items
  305. .map(item => item.song._id)
  306. .indexOf(res.data.songId);
  307. if (index >= 0) this.items[index].song.removed = true;
  308. },
  309. { modalUuid: this.modalUuid }
  310. );
  311. this.socket.on(
  312. `event:admin.youtubeVideo.removed`,
  313. res => {
  314. const index = this.items
  315. .map(item => item.song.youtubeVideoId)
  316. .indexOf(res.videoId);
  317. if (index >= 0) this.items[index].song.removed = true;
  318. },
  319. { modalUuid: this.modalUuid }
  320. );
  321. },
  322. beforeUnmount() {
  323. console.log("EDITSONGS BEFORE UNMOUNT");
  324. this.socket.dispatch("apis.leaveRoom", "edit-songs");
  325. },
  326. unmounted() {
  327. console.log("EDITSONGS UNMOUNTED");
  328. // Delete the VueX module that was created for this modal, after all other cleanup tasks are performed
  329. this.$store.unregisterModule(["modals", "editSongs", this.modalUuid]);
  330. },
  331. methods: {
  332. pickSong(song) {
  333. this.editSong({
  334. youtubeId: song.youtubeId,
  335. prefill: this.songPrefillData[song.youtubeId]
  336. });
  337. this.currentSong = song;
  338. if (
  339. this.$refs[`edit-songs-item-${song.youtubeId}`] &&
  340. this.$refs[`edit-songs-item-${song.youtubeId}`][0]
  341. )
  342. this.$refs[
  343. `edit-songs-item-${song.youtubeId}`
  344. ][0].scrollIntoView();
  345. },
  346. editNextSong() {
  347. const currentlyEditingSongIndex = this.filteredEditingItemIndex;
  348. let newEditingSongIndex = -1;
  349. const index =
  350. currentlyEditingSongIndex + 1 === this.filteredItems.length
  351. ? 0
  352. : currentlyEditingSongIndex + 1;
  353. for (let i = index; i < this.filteredItems.length; i += 1) {
  354. if (!this.flagFilter || this.filteredItems[i].flagged) {
  355. newEditingSongIndex = i;
  356. break;
  357. }
  358. }
  359. if (newEditingSongIndex > -1) {
  360. const nextSong = this.filteredItems[newEditingSongIndex].song;
  361. if (nextSong.removed) this.editNextSong();
  362. else this.pickSong(nextSong);
  363. }
  364. },
  365. toggleFlag(songIndex = null) {
  366. if (songIndex && songIndex > -1) {
  367. this.filteredItems[songIndex].flagged =
  368. !this.filteredItems[songIndex].flagged;
  369. new Toast(
  370. `Successfully ${
  371. this.filteredItems[songIndex].flagged
  372. ? "flagged"
  373. : "unflagged"
  374. } song.`
  375. );
  376. } else if (!songIndex && this.editingItemIndex > -1) {
  377. this.items[this.editingItemIndex].flagged =
  378. !this.items[this.editingItemIndex].flagged;
  379. new Toast(
  380. `Successfully ${
  381. this.items[this.editingItemIndex].flagged
  382. ? "flagged"
  383. : "unflagged"
  384. } song.`
  385. );
  386. }
  387. },
  388. onSavedSuccess(youtubeId) {
  389. const itemIndex = this.items.findIndex(
  390. item => item.song.youtubeId === youtubeId
  391. );
  392. if (itemIndex > -1) {
  393. this.items[itemIndex].status = "done";
  394. this.items[itemIndex].flagged = false;
  395. }
  396. },
  397. onSavedError(youtubeId) {
  398. const itemIndex = this.items.findIndex(
  399. item => item.song.youtubeId === youtubeId
  400. );
  401. if (itemIndex > -1) this.items[itemIndex].status = "error";
  402. },
  403. onSaving(youtubeId) {
  404. const itemIndex = this.items.findIndex(
  405. item => item.song.youtubeId === youtubeId
  406. );
  407. if (itemIndex > -1) this.items[itemIndex].status = "saving";
  408. },
  409. toggleDone(index, overwrite = null) {
  410. const { status } = this.filteredItems[index];
  411. if (status === "done" && overwrite !== "done")
  412. this.filteredItems[index].status = "todo";
  413. else {
  414. this.filteredItems[index].status = "done";
  415. this.filteredItems[index].flagged = false;
  416. }
  417. },
  418. toggleFlagFilter() {
  419. this.flagFilter = !this.flagFilter;
  420. },
  421. toggleMobileSidebar() {
  422. this.sidebarMobileActive = !this.sidebarMobileActive;
  423. },
  424. confirmAction({ message, action, params }) {
  425. this.openModal({
  426. modal: "confirm",
  427. data: {
  428. message,
  429. action,
  430. params,
  431. onCompleted: this.handleConfirmed
  432. }
  433. });
  434. },
  435. handleConfirmed({ action, params }) {
  436. if (typeof this[action] === "function") {
  437. if (params) this[action](params);
  438. else this[action]();
  439. }
  440. },
  441. onClose() {
  442. const doneItems = this.items.filter(
  443. item => item.status === "done"
  444. ).length;
  445. const flaggedItems = this.items.filter(item => item.flagged).length;
  446. const notDoneItems = this.items.length - doneItems;
  447. if (doneItems > 0 && notDoneItems > 0)
  448. this.confirmAction({
  449. message:
  450. "You have songs which are not done yet. Are you sure you want to stop editing songs?",
  451. action: "closeThisModal",
  452. params: null
  453. });
  454. else if (flaggedItems > 0)
  455. this.confirmAction({
  456. message:
  457. "You have songs which are flagged. Are you sure you want to stop editing songs?",
  458. action: "closeThisModal",
  459. params: null
  460. });
  461. else this.closeThisModal();
  462. },
  463. closeThisModal() {
  464. this.closeCurrentModal();
  465. },
  466. ...mapActions("modalVisibility", ["openModal", "closeCurrentModal"]),
  467. ...mapModalActions("modals/editSongs/MODAL_UUID/editSong", [
  468. "editSong"
  469. ]),
  470. ...mapModalActions("modals/editSongs/MODAL_UUID", ["resetSongs"])
  471. }
  472. };
  473. </script>
  474. <style lang="less" scoped>
  475. .night-mode .sidebar {
  476. .sidebar-head,
  477. .sidebar-foot {
  478. background-color: var(--dark-grey-3);
  479. border: none;
  480. }
  481. .sidebar-body {
  482. background-color: var(--dark-grey-4) !important;
  483. }
  484. .sidebar-head .toggle-sidebar-icon.material-icons,
  485. .sidebar-title {
  486. color: var(--white);
  487. }
  488. p,
  489. label,
  490. td,
  491. th {
  492. color: var(--light-grey-2) !important;
  493. }
  494. h1,
  495. h2,
  496. h3,
  497. h4,
  498. h5,
  499. h6 {
  500. color: var(--white) !important;
  501. }
  502. }
  503. .toggle-sidebar-icon {
  504. display: none;
  505. }
  506. .sidebar {
  507. width: 100%;
  508. max-width: 350px;
  509. z-index: 2000;
  510. display: flex;
  511. flex-direction: column;
  512. position: relative;
  513. height: 100%;
  514. max-height: calc(100vh - 40px);
  515. overflow: auto;
  516. margin-right: 8px;
  517. border-radius: @border-radius;
  518. .sidebar-head,
  519. .sidebar-foot {
  520. display: flex;
  521. flex-shrink: 0;
  522. position: relative;
  523. justify-content: flex-start;
  524. align-items: center;
  525. padding: 20px;
  526. background-color: var(--light-grey);
  527. }
  528. .sidebar-head {
  529. border-bottom: 1px solid var(--light-grey-2);
  530. border-radius: @border-radius @border-radius 0 0;
  531. .sidebar-title {
  532. display: flex;
  533. flex: 1;
  534. margin: 0;
  535. font-size: 26px;
  536. font-weight: 600;
  537. }
  538. }
  539. .sidebar-body {
  540. background-color: var(--white);
  541. display: flex;
  542. flex-direction: column;
  543. row-gap: 8px;
  544. flex: 1;
  545. overflow: auto;
  546. padding: 10px;
  547. .edit-songs-items {
  548. display: flex;
  549. flex-direction: column;
  550. row-gap: 8px;
  551. .item {
  552. display: flex;
  553. flex-direction: row;
  554. align-items: center;
  555. column-gap: 8px;
  556. :deep(.song-item) {
  557. .item-icon {
  558. margin-right: 10px;
  559. cursor: pointer;
  560. }
  561. .removed-icon,
  562. .error-icon {
  563. color: var(--red);
  564. }
  565. .saving-icon,
  566. .todo-icon,
  567. .editing-icon {
  568. color: var(--primary-color);
  569. }
  570. .done-icon {
  571. color: var(--green);
  572. }
  573. .flag-icon {
  574. color: var(--orange);
  575. &.flagged {
  576. color: var(--grey);
  577. }
  578. }
  579. &.removed {
  580. filter: grayscale(100%);
  581. cursor: not-allowed;
  582. user-select: none;
  583. }
  584. }
  585. }
  586. }
  587. .no-items {
  588. text-align: center;
  589. font-size: 18px;
  590. }
  591. }
  592. .sidebar-foot {
  593. border-top: 1px solid var(--light-grey-2);
  594. border-radius: 0 0 @border-radius @border-radius;
  595. .button {
  596. flex: 1;
  597. }
  598. }
  599. .sidebar-overlay {
  600. display: none;
  601. }
  602. }
  603. @media only screen and (max-width: 1580px) {
  604. .toggle-sidebar-icon {
  605. display: flex;
  606. margin-right: 5px;
  607. transform: rotate(90deg);
  608. cursor: pointer;
  609. }
  610. .sidebar {
  611. display: none;
  612. &.active {
  613. display: flex;
  614. position: absolute;
  615. z-index: 2010;
  616. top: 20px;
  617. left: 20px;
  618. .sidebar-head .toggle-sidebar-icon {
  619. display: flex;
  620. margin-left: 5px;
  621. transform: rotate(-90deg);
  622. }
  623. }
  624. }
  625. .sidebar-overlay {
  626. display: flex;
  627. position: absolute;
  628. z-index: 2009;
  629. top: 0;
  630. left: 0;
  631. right: 0;
  632. bottom: 0;
  633. background-color: rgba(10, 10, 10, 0.85);
  634. }
  635. }
  636. </style>