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.

112 lines
3.0 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 Vue from 'vue'
  65. import { mdiAccountCircle, mdiDotsVertical } from '@mdi/js'
  66. import VueFilterDateFormat from '@vuejs-community/vue-filter-date-format'
  67. import VueFilterDateParse from '@vuejs-community/vue-filter-date-parse'
  68. Vue.use(VueFilterDateFormat)
  69. Vue.use(VueFilterDateParse)
  70. export default Vue.extend({
  71. props: {
  72. comment: {
  73. required: true,
  74. type: Object
  75. },
  76. userId: {
  77. required: true,
  78. type: Number
  79. }
  80. },
  81. data() {
  82. return {
  83. showEdit: false,
  84. editText: this.comment.text,
  85. commentRules: [(v: string) => !!v.trim() || 'Comment is required'],
  86. valid: false,
  87. mdiAccountCircle,
  88. mdiDotsVertical
  89. }
  90. },
  91. methods: {
  92. updateComment(newText: string) {
  93. this.showEdit = false
  94. const comment = { ...this.comment, text: newText }
  95. this.$emit('update-comment', comment)
  96. },
  97. cancel() {
  98. this.showEdit = false
  99. this.editText = this.comment.text
  100. }
  101. }
  102. })
  103. </script>