EditSongs.vue 13 KB

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