You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
1.8 KiB

  1. <template>
  2. <base-card
  3. :title="$t('comments.comments')"
  4. :cancel-text="$t('generic.close')"
  5. @cancel="$emit('click:cancel')"
  6. >
  7. <template v-if="user.id" #content>
  8. <form-create
  9. @add-comment="add"
  10. />
  11. <comment
  12. v-for="comment in comments"
  13. :key="comment.id"
  14. :comment="comment"
  15. :user-id="user.id"
  16. @delete-comment="remove"
  17. @update-comment="maybeUpdate"
  18. />
  19. </template>
  20. </base-card>
  21. </template>
  22. <script lang="ts">
  23. import Vue from 'vue'
  24. import BaseCard from '@/components/utils/BaseCard.vue'
  25. import Comment from '@/components/comment/Comment.vue'
  26. import FormCreate from '@/components/comment/FormCreate.vue'
  27. import { CommentReadDTO } from '~/services/application/comment/commentData'
  28. export default Vue.extend({
  29. components: {
  30. BaseCard,
  31. Comment,
  32. FormCreate
  33. },
  34. props: {
  35. exampleId: {
  36. type: Number,
  37. required: true
  38. }
  39. },
  40. data() {
  41. return {
  42. user: {},
  43. comments: [] as CommentReadDTO[],
  44. }
  45. },
  46. watch: {
  47. exampleId: {
  48. handler(val) {
  49. if (val !== undefined) {
  50. this.list()
  51. }
  52. },
  53. immediate: true,
  54. deep: true
  55. }
  56. },
  57. async created() {
  58. this.user = await this.$services.user.getMyProfile()
  59. },
  60. methods: {
  61. async list() {
  62. this.comments = await this.$services.comment.list(this.$route.params.id, this.exampleId)
  63. },
  64. async add(message: string) {
  65. await this.$services.comment.create(this.$route.params.id, this.exampleId, message)
  66. this.list()
  67. },
  68. async remove(item: CommentReadDTO) {
  69. await this.$services.comment.delete(this.$route.params.id, item)
  70. this.list()
  71. },
  72. async maybeUpdate(item: CommentReadDTO) {
  73. await this.$services.comment.update(this.$route.params.id, item)
  74. this.list()
  75. }
  76. }
  77. })
  78. </script>