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.

114 lines
3.1 KiB

2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. <template>
  2. <v-card class="elevation-0">
  3. <v-card-title>
  4. <v-list-item class="grow ps-0">
  5. <v-list-item-avatar>
  6. <v-icon large>
  7. {{ mdiAccountCircle }}
  8. </v-icon>
  9. </v-list-item-avatar>
  10. <v-list-item-content>
  11. <v-list-item-title>{{ comment.username }}</v-list-item-title>
  12. <v-list-item-subtitle>
  13. {{
  14. comment.createdAt | dateParse('YYYY-MM-DDTHH:mm:ss') | dateFormat('DD/MM/YYYY HH:mm')
  15. }}
  16. </v-list-item-subtitle>
  17. </v-list-item-content>
  18. <v-row align="center" justify="end">
  19. <v-menu v-if="comment.user == userId" bottom left>
  20. <template #activator="{ on, attrs }">
  21. <v-btn icon v-bind="attrs" v-on="on">
  22. <v-icon>{{ mdiDotsVertical }}</v-icon>
  23. </v-btn>
  24. </template>
  25. <v-list>
  26. <v-list-item>
  27. <v-list-item-title @click="showEdit = true"> Edit </v-list-item-title>
  28. </v-list-item>
  29. <v-list-item>
  30. <v-list-item-title @click="$emit('delete-comment', comment)">
  31. Delete
  32. </v-list-item-title>
  33. </v-list-item>
  34. </v-list>
  35. </v-menu>
  36. </v-row>
  37. </v-list-item>
  38. </v-card-title>
  39. <v-card-text class="body-1">
  40. <span v-if="!showEdit">
  41. {{ comment.text }}
  42. </span>
  43. <v-form v-else v-model="valid">
  44. <v-row>
  45. <v-textarea v-model="editText" auto-grow rows="1" solo :rules="commentRules" />
  46. </v-row>
  47. <v-row justify="end">
  48. <v-btn text class="text-capitalize" @click="cancel"> Cancel </v-btn>
  49. <v-btn
  50. :disabled="!valid"
  51. color="primary"
  52. class="text-capitalize"
  53. @click="updateComment(editText)"
  54. >
  55. Update
  56. </v-btn>
  57. </v-row>
  58. </v-form>
  59. </v-card-text>
  60. <v-divider />
  61. </v-card>
  62. </template>
  63. <script lang="ts">
  64. import { mdiAccountCircle, mdiDotsVertical } from '@mdi/js'
  65. import VueFilterDateFormat from '@vuejs-community/vue-filter-date-format'
  66. import VueFilterDateParse from '@vuejs-community/vue-filter-date-parse'
  67. import type { PropType } from 'vue'
  68. import Vue from 'vue'
  69. import { CommentItem } from '~/domain/models/comment/comment'
  70. Vue.use(VueFilterDateFormat)
  71. Vue.use(VueFilterDateParse)
  72. export default Vue.extend({
  73. props: {
  74. comment: {
  75. required: true,
  76. type: Object as PropType<CommentItem>
  77. },
  78. userId: {
  79. required: true,
  80. type: Number
  81. }
  82. },
  83. data() {
  84. return {
  85. showEdit: false,
  86. editText: this.comment.text,
  87. commentRules: [(v: string) => !!v.trim() || 'Comment is required'],
  88. valid: false,
  89. mdiAccountCircle,
  90. mdiDotsVertical
  91. }
  92. },
  93. methods: {
  94. updateComment(newText: string) {
  95. this.showEdit = false
  96. const comment = { ...this.comment, text: newText }
  97. this.$emit('update-comment', comment)
  98. },
  99. cancel() {
  100. this.showEdit = false
  101. this.editText = this.comment.text
  102. }
  103. }
  104. })
  105. </script>