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.

144 lines
3.3 KiB

3 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. {{ comment.createdAt | dateParse('YYYY-MM-DDTHH:mm:ss') | dateFormat('DD/MM/YYYY HH:mm') }}
  14. </v-list-item-subtitle>
  15. </v-list-item-content>
  16. <v-row
  17. align="center"
  18. justify="end"
  19. >
  20. <v-menu
  21. v-if="comment.user == userId"
  22. bottom
  23. left
  24. >
  25. <template #activator="{ on, attrs }">
  26. <v-btn
  27. icon
  28. v-bind="attrs"
  29. v-on="on"
  30. >
  31. <v-icon>{{ mdiDotsVertical }}</v-icon>
  32. </v-btn>
  33. </template>
  34. <v-list>
  35. <v-list-item>
  36. <v-list-item-title
  37. @click="showEdit=true"
  38. >
  39. Edit
  40. </v-list-item-title>
  41. </v-list-item>
  42. <v-list-item>
  43. <v-list-item-title
  44. @click="$emit('delete-comment', comment)"
  45. >
  46. Delete
  47. </v-list-item-title>
  48. </v-list-item>
  49. </v-list>
  50. </v-menu>
  51. </v-row>
  52. </v-list-item>
  53. </v-card-title>
  54. <v-card-text class="body-1">
  55. <span v-if="!showEdit">
  56. {{ comment.text }}
  57. </span>
  58. <v-form
  59. v-else
  60. v-model="valid"
  61. >
  62. <v-row>
  63. <v-textarea
  64. v-model="editText"
  65. auto-grow
  66. rows="1"
  67. solo
  68. :rules="commentRules"
  69. />
  70. </v-row>
  71. <v-row justify="end">
  72. <v-btn
  73. text
  74. class="text-capitalize"
  75. @click="cancel"
  76. >
  77. Cancel
  78. </v-btn>
  79. <v-btn
  80. :disabled="!valid"
  81. color="primary"
  82. class="text-capitalize"
  83. @click="updateComment(editText)"
  84. >
  85. Update
  86. </v-btn>
  87. </v-row>
  88. </v-form>
  89. </v-card-text>
  90. <v-divider />
  91. </v-card>
  92. </template>
  93. <script lang="ts">
  94. import Vue from 'vue'
  95. import { mdiAccountCircle, mdiDotsVertical } from '@mdi/js'
  96. import VueFilterDateFormat from '@vuejs-community/vue-filter-date-format'
  97. import VueFilterDateParse from '@vuejs-community/vue-filter-date-parse'
  98. Vue.use(VueFilterDateFormat)
  99. Vue.use(VueFilterDateParse)
  100. export default Vue.extend({
  101. props: {
  102. comment: {
  103. required: true,
  104. type: Object
  105. },
  106. userId: {
  107. required: true,
  108. type: Number
  109. }
  110. },
  111. data() {
  112. return {
  113. showEdit: false,
  114. editText: this.comment.text,
  115. commentRules: [
  116. (v: string) => !!v.trim() || 'Comment is required'
  117. ],
  118. valid: false,
  119. mdiAccountCircle,
  120. mdiDotsVertical
  121. }
  122. },
  123. methods: {
  124. updateComment(newText: string) {
  125. this.showEdit = false
  126. const comment = {...this.comment, text:newText }
  127. this.$emit('update-comment', comment)
  128. },
  129. cancel() {
  130. this.showEdit = false
  131. this.editText = this.comment.text
  132. }
  133. }
  134. })
  135. </script>