comments.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template lang="pug">
  2. div(v-intersect.once.quiet='onIntersect')
  3. v-textarea#discussion-new(
  4. outlined
  5. flat
  6. placeholder='Write a new comment...'
  7. auto-grow
  8. dense
  9. rows='3'
  10. hide-details
  11. v-model='newcomment'
  12. color='blue-grey darken-2'
  13. :background-color='$vuetify.theme.dark ? `grey darken-5` : `white`'
  14. )
  15. .d-flex.align-center.pt-3
  16. v-icon.mr-1(color='blue-grey') mdi-language-markdown-outline
  17. .caption.blue-grey--text Markdown Format
  18. v-spacer
  19. v-btn(
  20. dark
  21. color='blue-grey darken-2'
  22. @click='postComment'
  23. depressed
  24. )
  25. v-icon(left) mdi-comment
  26. span.text-none Post Comment
  27. v-divider.mt-3
  28. .pa-5.d-flex.align-center.justify-center(v-if='isLoading')
  29. v-progress-circular(
  30. indeterminate
  31. size='20'
  32. width='1'
  33. color='blue-grey'
  34. )
  35. .caption.blue-grey--text.pl-3: em Loading comments...
  36. v-timeline(
  37. dense
  38. v-else-if='comments && comments.length > 0'
  39. )
  40. v-timeline-item(
  41. color='pink darken-4'
  42. large
  43. v-for='cm of comments'
  44. :key='`comment-` + cm.id'
  45. )
  46. template(v-slot:icon)
  47. v-avatar
  48. v-img(src='http://i.pravatar.cc/64')
  49. v-card.elevation-1
  50. v-card-text
  51. .caption: strong John Smith
  52. .overline.grey--text 3 minutes ago
  53. .mt-3 {{cm.render}}
  54. .pt-5.text-center.body-2.blue-grey--text(v-else) Be the first to comment.
  55. </template>
  56. <script>
  57. import gql from 'graphql-tag'
  58. import { get } from 'vuex-pathify'
  59. export default {
  60. data () {
  61. return {
  62. newcomment: '',
  63. isLoading: true,
  64. canFetch: false,
  65. comments: []
  66. }
  67. },
  68. computed: {
  69. pageId: get('page/id')
  70. },
  71. methods: {
  72. onIntersect () {
  73. this.isLoading = true
  74. this.canFetch = true
  75. },
  76. async postComment () {
  77. }
  78. },
  79. apollo: {
  80. comments: {
  81. query: gql`
  82. query ($pageId: Int!) {
  83. comments {
  84. list(pageId: $pageId) {
  85. id
  86. render
  87. authorName
  88. createdAt
  89. updatedAt
  90. }
  91. }
  92. }
  93. `,
  94. variables() {
  95. return {
  96. pageId: this.pageId
  97. }
  98. },
  99. skip () {
  100. return !this.canFetch
  101. },
  102. fetchPolicy: 'cache-and-network',
  103. update: (data) => data.comments.list,
  104. watchLoading (isLoading) {
  105. this.isLoading = isLoading
  106. }
  107. }
  108. }
  109. }
  110. </script>
  111. <style lang="scss">
  112. </style>