Reports.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. <script setup lang="ts">
  2. import { defineAsyncComponent, ref, computed, onMounted } from "vue";
  3. import { storeToRefs } from "pinia";
  4. import Toast from "toasters";
  5. import { useEditSongStore } from "@/stores/editSong";
  6. import { useWebsocketsStore } from "@/stores/websockets";
  7. const ReportInfoItem = defineAsyncComponent(
  8. () => import("@/components/ReportInfoItem.vue")
  9. );
  10. const props = defineProps({
  11. modalUuid: { type: String, required: true },
  12. modalModulePath: { type: String, default: "modals/editSong/MODAL_UUID" }
  13. });
  14. const editSongStore = useEditSongStore({ modalUuid: props.modalUuid });
  15. const { socket } = useWebsocketsStore();
  16. const tab = ref("sort-by-report");
  17. const icons = ref({
  18. duration: "timer",
  19. video: "tv",
  20. thumbnail: "image",
  21. artists: "record_voice_over",
  22. title: "title",
  23. custom: "lightbulb"
  24. });
  25. const tabs = ref({});
  26. const { reports } = storeToRefs(editSongStore);
  27. const sortedByCategory = computed(() => {
  28. const categories = {};
  29. reports.value.forEach(report =>
  30. report.issues.forEach(issue => {
  31. if (categories[issue.category])
  32. categories[issue.category].push({
  33. ...issue,
  34. reportId: report._id
  35. });
  36. else
  37. categories[issue.category] = [
  38. { ...issue, reportId: report._id }
  39. ];
  40. })
  41. );
  42. return categories;
  43. });
  44. const { resolveReport } = editSongStore;
  45. const showTab = _tab => {
  46. tabs.value[`${_tab}-tab`].scrollIntoView({ block: "nearest" });
  47. tab.value = _tab;
  48. };
  49. const resolve = reportId => {
  50. socket.dispatch("reports.resolve", reportId, res => new Toast(res.message));
  51. };
  52. const toggleIssue = (reportId, issueId) => {
  53. socket.dispatch("reports.toggleIssue", reportId, issueId, res => {
  54. if (res.status !== "success") new Toast(res.message);
  55. });
  56. };
  57. onMounted(() => {
  58. socket.on(
  59. "event:admin.report.created",
  60. res => reports.value.unshift(res.data.report),
  61. { modalUuid: props.modalUuid }
  62. );
  63. socket.on(
  64. "event:admin.report.resolved",
  65. res => resolveReport(res.data.reportId),
  66. { modalUuid: props.modalUuid }
  67. );
  68. socket.on(
  69. "event:admin.report.issue.toggled",
  70. res => {
  71. reports.value.forEach((report, index) => {
  72. if (report._id === res.data.reportId) {
  73. const issue = reports.value[index].issues.find(
  74. issue => issue._id.toString() === res.data.issueId
  75. );
  76. issue.resolved = res.data.resolved;
  77. }
  78. });
  79. },
  80. { modalUuid: props.modalUuid }
  81. );
  82. });
  83. </script>
  84. <template>
  85. <div class="reports-tab tabs-container">
  86. <div class="tab-selection">
  87. <button
  88. class="button is-default"
  89. :ref="el => (tabs['sort-by-report-tab'] = el)"
  90. :class="{ selected: tab === 'sort-by-report' }"
  91. @click="showTab('sort-by-report')"
  92. >
  93. Sort by Report
  94. </button>
  95. <button
  96. class="button is-default"
  97. :ref="el => (tabs['sort-by-category-tab'] = el)"
  98. :class="{ selected: tab === 'sort-by-category' }"
  99. @click="showTab('sort-by-category')"
  100. >
  101. Sort by Category
  102. </button>
  103. </div>
  104. <div class="tab" v-if="tab === 'sort-by-category'">
  105. <div class="report-items" v-if="reports.length > 0">
  106. <div
  107. class="report-item"
  108. v-for="(issues, category) in sortedByCategory"
  109. :key="category"
  110. >
  111. <div class="report-item-header universal-item">
  112. <i
  113. class="material-icons"
  114. :content="category"
  115. v-tippy="{ theme: 'info' }"
  116. >
  117. {{ icons[category] }}
  118. </i>
  119. <p>{{ category }} Issues</p>
  120. </div>
  121. <div class="report-sub-items">
  122. <div
  123. class="report-sub-item report-sub-item-unresolved"
  124. :class="[
  125. 'report',
  126. issue.resolved
  127. ? 'report-sub-item-resolved'
  128. : 'report-sub-item-unresolved'
  129. ]"
  130. v-for="(issue, issueIndex) in issues"
  131. :key="issueIndex"
  132. >
  133. <i
  134. class="material-icons duration-icon report-sub-item-left-icon"
  135. :content="issue.category"
  136. v-tippy
  137. >
  138. {{ icons[category] }}
  139. </i>
  140. <p class="report-sub-item-info">
  141. <span class="report-sub-item-title">
  142. {{ issue.title }}
  143. </span>
  144. <span
  145. class="report-sub-item-description"
  146. v-if="issue.description"
  147. >
  148. {{ issue.description }}
  149. </span>
  150. </p>
  151. <div
  152. class="report-sub-item-actions universal-item-actions"
  153. >
  154. <i
  155. class="material-icons resolve-icon"
  156. content="Resolve"
  157. v-tippy
  158. v-if="!issue.resolved"
  159. @click="
  160. toggleIssue(issue.reportId, issue._id)
  161. "
  162. >
  163. done
  164. </i>
  165. <i
  166. class="material-icons unresolve-icon"
  167. content="Unresolve"
  168. v-tippy
  169. v-else
  170. @click="
  171. toggleIssue(issue.reportId, issue._id)
  172. "
  173. >
  174. remove
  175. </i>
  176. </div>
  177. </div>
  178. </div>
  179. </div>
  180. </div>
  181. <p class="no-reports" v-else>There are no reports for this song.</p>
  182. </div>
  183. <div class="tab" v-if="tab === 'sort-by-report'">
  184. <div class="report-items" v-if="reports.length > 0">
  185. <div
  186. class="report-item"
  187. v-for="report in reports"
  188. :key="report._id"
  189. >
  190. <report-info-item
  191. :created-at="`${report.createdAt}`"
  192. :created-by="report.createdBy"
  193. >
  194. <template #actions>
  195. <i
  196. class="material-icons resolve-icon"
  197. content="Resolve all"
  198. v-tippy
  199. @click="resolve(report._id)"
  200. >
  201. done_all
  202. </i>
  203. </template>
  204. </report-info-item>
  205. <div class="report-sub-items">
  206. <div
  207. class="report-sub-item report-sub-item-unresolved"
  208. :class="[
  209. 'report',
  210. issue.resolved
  211. ? 'report-sub-item-resolved'
  212. : 'report-sub-item-unresolved'
  213. ]"
  214. v-for="(issue, issueIndex) in report.issues"
  215. :key="issueIndex"
  216. >
  217. <i
  218. class="material-icons duration-icon report-sub-item-left-icon"
  219. :content="issue.category"
  220. v-tippy
  221. >
  222. {{ icons[issue.category] }}
  223. </i>
  224. <p class="report-sub-item-info">
  225. <span class="report-sub-item-title">
  226. {{ issue.title }}
  227. </span>
  228. <span
  229. class="report-sub-item-description"
  230. v-if="issue.description"
  231. >
  232. {{ issue.description }}
  233. </span>
  234. </p>
  235. <div
  236. class="report-sub-item-actions universal-item-actions"
  237. >
  238. <i
  239. class="material-icons resolve-icon"
  240. content="Resolve"
  241. v-tippy
  242. v-if="!issue.resolved"
  243. @click="toggleIssue(report._id, issue._id)"
  244. >
  245. done
  246. </i>
  247. <i
  248. class="material-icons unresolve-icon"
  249. content="Unresolve"
  250. v-tippy
  251. v-else
  252. @click="toggleIssue(report._id, issue._id)"
  253. >
  254. remove
  255. </i>
  256. </div>
  257. </div>
  258. </div>
  259. </div>
  260. </div>
  261. <p class="no-reports" v-else>There are no reports for this song.</p>
  262. </div>
  263. </div>
  264. </template>
  265. <style lang="less" scoped>
  266. .night-mode {
  267. .report-items .report-item {
  268. background-color: var(--dark-grey-3) !important;
  269. }
  270. .report-items .report-item .report-item-header {
  271. background-color: var(--dark-grey-2) !important;
  272. }
  273. .label,
  274. p,
  275. strong {
  276. color: var(--light-grey-2);
  277. }
  278. .tabs-container .tab-selection .button {
  279. background: var(--dark-grey) !important;
  280. color: var(--white) !important;
  281. }
  282. }
  283. .reports-tab.tabs-container {
  284. .tab-selection {
  285. display: flex;
  286. overflow-x: auto;
  287. .button {
  288. border-radius: 0;
  289. border: 0;
  290. text-transform: uppercase;
  291. font-size: 14px;
  292. color: var(--dark-grey-3);
  293. background-color: var(--light-grey-2);
  294. flex-grow: 1;
  295. height: 32px;
  296. &:not(:first-of-type) {
  297. margin-left: 5px;
  298. }
  299. }
  300. .selected {
  301. background-color: var(--primary-color) !important;
  302. color: var(--white) !important;
  303. font-weight: 600;
  304. }
  305. }
  306. .tab {
  307. padding: 15px 0;
  308. border-radius: 0;
  309. }
  310. }
  311. .no-reports {
  312. text-align: center;
  313. }
  314. .report-items {
  315. .report-item {
  316. background-color: var(--white);
  317. border: 0.5px solid var(--primary-color);
  318. border-radius: @border-radius;
  319. padding: 8px;
  320. &:not(:first-of-type) {
  321. margin-bottom: 16px;
  322. }
  323. .report-item-header {
  324. justify-content: center;
  325. text-transform: capitalize;
  326. i {
  327. margin-right: 5px;
  328. }
  329. }
  330. .report-sub-items {
  331. .report-sub-item {
  332. border: 0.5px solid var(--black);
  333. margin-top: -1px;
  334. line-height: 24px;
  335. display: flex;
  336. padding: 4px;
  337. display: flex;
  338. &:first-child {
  339. border-radius: @border-radius @border-radius 0 0;
  340. }
  341. &:last-child {
  342. border-radius: 0 0 @border-radius @border-radius;
  343. }
  344. &.report-sub-item-resolved {
  345. .report-sub-item-description,
  346. .report-sub-item-title {
  347. text-decoration: line-through;
  348. }
  349. }
  350. .report-sub-item-left-icon {
  351. margin-right: 8px;
  352. margin-top: auto;
  353. margin-bottom: auto;
  354. }
  355. .report-sub-item-info {
  356. flex: 1;
  357. display: flex;
  358. flex-direction: column;
  359. .report-sub-item-title {
  360. font-size: 14px;
  361. }
  362. .report-sub-item-description {
  363. font-size: 12px;
  364. line-height: 16px;
  365. }
  366. }
  367. .report-sub-item-actions {
  368. height: 24px;
  369. margin-left: 8px;
  370. margin-top: auto;
  371. margin-bottom: auto;
  372. }
  373. }
  374. }
  375. .resolve-icon {
  376. color: var(--green);
  377. cursor: pointer;
  378. }
  379. .unresolve-icon {
  380. color: var(--dark-red);
  381. cursor: pointer;
  382. }
  383. }
  384. }
  385. </style>