EditSongs.vue 15 KB

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