Reports.vue 9.2 KB

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