EditSongs.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  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. async mounted() {
  237. this.socket.dispatch("apis.joinRoom", "edit-songs");
  238. this.$store.registerModule(
  239. ["modals", "editSongs", this.modalUuid, "editSong"],
  240. editSong
  241. );
  242. this.socket.dispatch(
  243. "songs.getSongsFromYoutubeIds",
  244. this.youtubeIds,
  245. res => {
  246. res.data.songs.forEach(song => {
  247. this.items.push({
  248. status: "todo",
  249. flagged: false,
  250. song
  251. });
  252. });
  253. if (this.items.length === 0) {
  254. this.closeThisModal();
  255. new Toast("You can't edit 0 songs.");
  256. } else this.editNextSong();
  257. }
  258. );
  259. this.socket.on(
  260. `event:admin.song.created`,
  261. res => {
  262. const index = this.items
  263. .map(item => item.song.youtubeId)
  264. .indexOf(res.data.song.youtubeId);
  265. this.items[index].song = {
  266. ...this.items[index].song,
  267. ...res.data.song,
  268. created: true
  269. };
  270. },
  271. { modalUuid: this.modalUuid }
  272. );
  273. this.socket.on(
  274. `event:admin.song.updated`,
  275. res => {
  276. const index = this.items
  277. .map(item => item.song.youtubeId)
  278. .indexOf(res.data.song.youtubeId);
  279. this.items[index].song = {
  280. ...this.items[index].song,
  281. ...res.data.song,
  282. updated: true
  283. };
  284. },
  285. { modalUuid: this.modalUuid }
  286. );
  287. this.socket.on(
  288. `event:admin.song.removed`,
  289. res => {
  290. const index = this.items
  291. .map(item => item.song._id)
  292. .indexOf(res.data.songId);
  293. this.items[index].song.removed = true;
  294. },
  295. { modalUuid: this.modalUuid }
  296. );
  297. this.socket.on(
  298. `event:admin.youtubeVideo.removed`,
  299. res => {
  300. const index = this.items
  301. .map(item => item.song.youtubeVideoId)
  302. .indexOf(res.videoId);
  303. if (index !== -1) this.items[index].song.removed = true;
  304. },
  305. { modalUuid: this.modalUuid }
  306. );
  307. },
  308. beforeUnmount() {
  309. this.socket.dispatch("apis.leaveRoom", "edit-songs");
  310. },
  311. unmounted() {
  312. // Delete the VueX module that was created for this modal, after all other cleanup tasks are performed
  313. this.$store.unregisterModule(["modals", "editSongs", this.modalUuid]);
  314. },
  315. methods: {
  316. pickSong(song) {
  317. this.editSong({
  318. youtubeId: song.youtubeId,
  319. prefill: this.songPrefillData[song.youtubeId]
  320. });
  321. this.currentSong = song;
  322. if (
  323. this.$refs[`edit-songs-item-${song.youtubeId}`] &&
  324. this.$refs[`edit-songs-item-${song.youtubeId}`][0]
  325. )
  326. this.$refs[
  327. `edit-songs-item-${song.youtubeId}`
  328. ][0].scrollIntoView();
  329. },
  330. editNextSong() {
  331. const currentlyEditingSongIndex = this.filteredEditingItemIndex;
  332. let newEditingSongIndex = -1;
  333. const index =
  334. currentlyEditingSongIndex + 1 === this.filteredItems.length
  335. ? 0
  336. : currentlyEditingSongIndex + 1;
  337. for (let i = index; i < this.filteredItems.length; i += 1) {
  338. if (!this.flagFilter || this.filteredItems[i].flagged) {
  339. newEditingSongIndex = i;
  340. break;
  341. }
  342. }
  343. if (newEditingSongIndex > -1) {
  344. const nextSong = this.filteredItems[newEditingSongIndex].song;
  345. if (nextSong.removed) this.editNextSong();
  346. else this.pickSong(nextSong);
  347. }
  348. },
  349. toggleFlag(songIndex = null) {
  350. if (songIndex && songIndex > -1) {
  351. this.filteredItems[songIndex].flagged =
  352. !this.filteredItems[songIndex].flagged;
  353. new Toast(
  354. `Successfully ${
  355. this.filteredItems[songIndex].flagged
  356. ? "flagged"
  357. : "unflagged"
  358. } song.`
  359. );
  360. } else if (!songIndex && this.editingItemIndex > -1) {
  361. this.items[this.editingItemIndex].flagged =
  362. !this.items[this.editingItemIndex].flagged;
  363. new Toast(
  364. `Successfully ${
  365. this.items[this.editingItemIndex].flagged
  366. ? "flagged"
  367. : "unflagged"
  368. } song.`
  369. );
  370. }
  371. },
  372. onSavedSuccess(youtubeId) {
  373. const itemIndex = this.items.findIndex(
  374. item => item.song.youtubeId === youtubeId
  375. );
  376. if (itemIndex > -1) {
  377. this.items[itemIndex].status = "done";
  378. this.items[itemIndex].flagged = false;
  379. }
  380. },
  381. onSavedError(youtubeId) {
  382. const itemIndex = this.items.findIndex(
  383. item => item.song.youtubeId === youtubeId
  384. );
  385. if (itemIndex > -1) this.items[itemIndex].status = "error";
  386. },
  387. onSaving(youtubeId) {
  388. const itemIndex = this.items.findIndex(
  389. item => item.song.youtubeId === youtubeId
  390. );
  391. if (itemIndex > -1) this.items[itemIndex].status = "saving";
  392. },
  393. toggleDone(index, overwrite = null) {
  394. const { status } = this.filteredItems[index];
  395. if (status === "done" && overwrite !== "done")
  396. this.filteredItems[index].status = "todo";
  397. else {
  398. this.filteredItems[index].status = "done";
  399. this.filteredItems[index].flagged = false;
  400. }
  401. },
  402. toggleFlagFilter() {
  403. this.flagFilter = !this.flagFilter;
  404. },
  405. toggleMobileSidebar() {
  406. this.sidebarMobileActive = !this.sidebarMobileActive;
  407. },
  408. confirmAction({ message, action, params }) {
  409. this.openModal({
  410. modal: "confirm",
  411. data: {
  412. message,
  413. action,
  414. params,
  415. onCompleted: this.handleConfirmed
  416. }
  417. });
  418. },
  419. handleConfirmed({ action, params }) {
  420. if (typeof this[action] === "function") {
  421. if (params) this[action](params);
  422. else this[action]();
  423. }
  424. },
  425. onClose() {
  426. const doneItems = this.items.filter(
  427. item => item.status === "done"
  428. ).length;
  429. const flaggedItems = this.items.filter(item => item.flagged).length;
  430. const notDoneItems = this.items.length - doneItems;
  431. if (doneItems > 0 && notDoneItems > 0)
  432. this.confirmAction({
  433. message:
  434. "You have songs which are not done yet. Are you sure you want to stop editing songs?",
  435. action: "closeThisModal",
  436. params: null
  437. });
  438. else if (flaggedItems > 0)
  439. this.confirmAction({
  440. message:
  441. "You have songs which are flagged. Are you sure you want to stop editing songs?",
  442. action: "closeThisModal",
  443. params: null
  444. });
  445. else this.closeThisModal();
  446. },
  447. closeThisModal() {
  448. this.closeCurrentModal();
  449. },
  450. ...mapActions("modalVisibility", ["openModal", "closeCurrentModal"]),
  451. ...mapModalActions("modals/editSongs/MODAL_UUID/editSong", [
  452. "editSong"
  453. ]),
  454. ...mapModalActions("modals/editSongs/MODAL_UUID", ["resetSongs"])
  455. }
  456. };
  457. </script>
  458. <style lang="less" scoped>
  459. .night-mode .sidebar {
  460. .sidebar-head,
  461. .sidebar-foot {
  462. background-color: var(--dark-grey-3);
  463. border: none;
  464. }
  465. .sidebar-body {
  466. background-color: var(--dark-grey-4) !important;
  467. }
  468. .sidebar-head .toggle-sidebar-icon.material-icons,
  469. .sidebar-title {
  470. color: var(--white);
  471. }
  472. p,
  473. label,
  474. td,
  475. th {
  476. color: var(--light-grey-2) !important;
  477. }
  478. h1,
  479. h2,
  480. h3,
  481. h4,
  482. h5,
  483. h6 {
  484. color: var(--white) !important;
  485. }
  486. }
  487. .toggle-sidebar-icon {
  488. display: none;
  489. }
  490. .sidebar {
  491. width: 100%;
  492. max-width: 350px;
  493. z-index: 2000;
  494. display: flex;
  495. flex-direction: column;
  496. position: relative;
  497. height: 100%;
  498. max-height: calc(100vh - 40px);
  499. overflow: auto;
  500. margin-right: 8px;
  501. border-radius: @border-radius;
  502. .sidebar-head,
  503. .sidebar-foot {
  504. display: flex;
  505. flex-shrink: 0;
  506. position: relative;
  507. justify-content: flex-start;
  508. align-items: center;
  509. padding: 20px;
  510. background-color: var(--light-grey);
  511. }
  512. .sidebar-head {
  513. border-bottom: 1px solid var(--light-grey-2);
  514. border-radius: @border-radius @border-radius 0 0;
  515. .sidebar-title {
  516. display: flex;
  517. flex: 1;
  518. margin: 0;
  519. font-size: 26px;
  520. font-weight: 600;
  521. }
  522. }
  523. .sidebar-body {
  524. background-color: var(--white);
  525. display: flex;
  526. flex-direction: column;
  527. row-gap: 8px;
  528. flex: 1;
  529. overflow: auto;
  530. padding: 10px;
  531. .item {
  532. display: flex;
  533. flex-direction: row;
  534. align-items: center;
  535. column-gap: 8px;
  536. :deep(.song-item) {
  537. .item-icon {
  538. margin-right: 10px;
  539. cursor: pointer;
  540. }
  541. .removed-icon,
  542. .error-icon {
  543. color: var(--red);
  544. }
  545. .saving-icon,
  546. .todo-icon,
  547. .editing-icon {
  548. color: var(--primary-color);
  549. }
  550. .done-icon {
  551. color: var(--green);
  552. }
  553. .flag-icon {
  554. color: var(--orange);
  555. &.flagged {
  556. color: var(--grey);
  557. }
  558. }
  559. &.removed {
  560. filter: grayscale(100%);
  561. cursor: not-allowed;
  562. user-select: none;
  563. }
  564. }
  565. }
  566. .no-items {
  567. text-align: center;
  568. font-size: 18px;
  569. }
  570. }
  571. .sidebar-foot {
  572. border-top: 1px solid var(--light-grey-2);
  573. border-radius: 0 0 @border-radius @border-radius;
  574. .button {
  575. flex: 1;
  576. }
  577. }
  578. .sidebar-overlay {
  579. display: none;
  580. }
  581. }
  582. @media only screen and (max-width: 1580px) {
  583. .toggle-sidebar-icon {
  584. display: flex;
  585. margin-right: 5px;
  586. transform: rotate(90deg);
  587. cursor: pointer;
  588. }
  589. .sidebar {
  590. display: none;
  591. &.active {
  592. display: flex;
  593. position: absolute;
  594. z-index: 2010;
  595. top: 20px;
  596. left: 20px;
  597. .sidebar-head .toggle-sidebar-icon {
  598. display: flex;
  599. margin-left: 5px;
  600. transform: rotate(-90deg);
  601. }
  602. }
  603. }
  604. .sidebar-overlay {
  605. display: flex;
  606. position: absolute;
  607. z-index: 2009;
  608. top: 0;
  609. left: 0;
  610. right: 0;
  611. bottom: 0;
  612. background-color: rgba(10, 10, 10, 0.85);
  613. }
  614. }
  615. </style>