ReplyingTo.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <info-tooltip class='replying_to' @hover='loadPost'>
  3. <template slot='content'>
  4. <div style='margin-top: -0.25rem;'>
  5. <div class='replying_to__username' v-if='post'>{{postUsername}}</div>
  6. <div class='replying_to__date' v-if='post'>{{post.createdAt | formatDate('date|time', ' - ')}}</div>
  7. </div>
  8. <div class='replying_to__content' v-if='post'>{{post.content | stripTags | truncate(100)}}</div>
  9. <template v-else>Loading...</template>
  10. </template>
  11. <div
  12. slot='display'
  13. class='replying_to__display'
  14. @click='$emit("click")'
  15. >
  16. <span class='fa fa-reply replying_to__icon'></span>
  17. {{username || '[deleted]'}}
  18. </div>
  19. </info-tooltip>
  20. </template>
  21. <script>
  22. import InfoTooltip from './InfoTooltip'
  23. import AjaxErrorHandler from '../assets/js/errorHandler'
  24. export default {
  25. name: 'ReplyingTo',
  26. props: ['replyId', 'username'],
  27. components: { InfoTooltip },
  28. data () {
  29. return {
  30. post: null
  31. }
  32. },
  33. computed: {
  34. postUsername () {
  35. if(this.post.User) {
  36. return this.post.User.username
  37. } else {
  38. return '[deleted]'
  39. }
  40. }
  41. },
  42. methods: {
  43. loadPost () {
  44. if(this.post) return
  45. this.axios
  46. .get('/api/v1/post/' + this.replyId)
  47. .then((res) => {
  48. this.post = res.data
  49. })
  50. .catch(AjaxErrorHandler(this.$store))
  51. }
  52. }
  53. }
  54. </script>
  55. <style lang='scss'>
  56. @import '../assets/scss/variables.scss';
  57. .replying_to {
  58. @at-root #{&}__icon {
  59. font-size: 0.7rem;
  60. margin-right: 0.25rem;
  61. color: rgba(0, 0, 0, 0.87);
  62. }
  63. @at-root #{&}__date {
  64. display: inline-block;
  65. color: $color__gray--darkest;
  66. font-size: 0.8rem;
  67. }
  68. @at-root #{&}__username {
  69. display: inline-block;
  70. font-size: 0.9rem;
  71. color: #000;
  72. }
  73. @at-root #{&}__content {
  74. *:first-child, *:last-child {
  75. margin: 0;
  76. }
  77. p {
  78. margin: 0.25rem 0;
  79. }
  80. }
  81. @at-root #{&}__display {
  82. display: inline-flex;
  83. cursor: pointer;
  84. align-items: baseline;
  85. }
  86. }
  87. </style>