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.

141 lines
3.2 KiB

  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. mdi-account-circle
  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 v-slot:activator="{ on, attrs }">
  26. <v-btn
  27. icon
  28. v-bind="attrs"
  29. v-on="on"
  30. >
  31. <v-icon>mdi-dots-vertical</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 VueFilterDateFormat from '@vuejs-community/vue-filter-date-format'
  96. import VueFilterDateParse from '@vuejs-community/vue-filter-date-parse'
  97. Vue.use(VueFilterDateFormat)
  98. Vue.use(VueFilterDateParse)
  99. export default Vue.extend({
  100. props: {
  101. comment: {
  102. required: true,
  103. type: Object
  104. },
  105. userId: {
  106. required: true,
  107. type: Number
  108. }
  109. },
  110. data() {
  111. return {
  112. showEdit: false,
  113. editText: this.comment.text,
  114. commentRules: [
  115. (v: string) => !!v.trim() || 'Comment is required'
  116. ],
  117. valid: false
  118. }
  119. },
  120. methods: {
  121. updateComment(newText: string) {
  122. this.showEdit = false
  123. const comment = {...this.comment, text:newText }
  124. this.$emit('update-comment', comment)
  125. },
  126. cancel() {
  127. this.showEdit = false
  128. this.editText = this.comment.text
  129. }
  130. }
  131. })
  132. </script>