AvatarIcon.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <info-tooltip class='avatar_icon' @hover='loadUser'>
  3. <template slot='content'>
  4. <template v-if='ajaxUser'>
  5. <div class='avatar_icon__header'>
  6. <div
  7. class='avatar_icon__icon avatar_icon__icon--small'
  8. :style='{ "background-color": user.color }'
  9. @click='goToUser'
  10. >
  11. {{user.username[0]}}
  12. </div>
  13. <div class='avatar_icon__header_info'>
  14. <span class='avatar_icon__username' @click='goToUser'>{{ajaxUser.username}}</span>
  15. <span class='avatar_icon__date'>Created: {{ajaxUser.createdAt | formatDate('date') }}</span>
  16. </div>
  17. </div>
  18. <div class='avatar_icon__description'>
  19. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
  20. </div>
  21. </template>
  22. <template v-else>Loading...</template>
  23. </template>
  24. <div
  25. slot='display'
  26. class='avatar_icon__icon'
  27. :style='{ "background-color": user.color }'
  28. @click='goToUser'
  29. >
  30. {{user.username[0]}}
  31. </div>
  32. </info-tooltip>
  33. </template>
  34. <script>
  35. import InfoTooltip from './InfoTooltip'
  36. import AjaxErrorHandler from '../assets/js/errorHandler'
  37. export default {
  38. name: 'AvatarIcon',
  39. props: ['user'],
  40. components: { InfoTooltip },
  41. data () {
  42. return {
  43. ajaxUser: null
  44. }
  45. },
  46. methods: {
  47. loadUser () {
  48. if(this.ajaxUser) return
  49. this.axios
  50. .get('/api/v1/user/' + this.user.username)
  51. .then((res) => {
  52. this.ajaxUser = res.data
  53. })
  54. .catch(AjaxErrorHandler(this.$store))
  55. },
  56. goToUser () {
  57. this.$router.push('/user/' + this.user.username)
  58. }
  59. }
  60. }
  61. </script>
  62. <style lang='scss'>
  63. @import '../assets/scss/variables.scss';
  64. .avatar_icon {
  65. @at-root #{&}__icon {
  66. font-size: 0.7rem;
  67. margin-right: 0.25rem;
  68. color: rgba(0, 0, 0, 0.87);
  69. }
  70. @at-root #{&}__header {
  71. display: flex;
  72. align-items: center;
  73. }
  74. @at-root #{&}__icon {
  75. height: 3rem;
  76. width: 3rem;
  77. line-height: 3rem;
  78. cursor: pointer;
  79. @include text($font--role-emphasis, 2rem)
  80. text-align: center;
  81. border-radius: 100%;
  82. background-color: $color__gray--darkest;
  83. color: #fff;
  84. @at-root #{&}--small {
  85. height: 2.5rem;
  86. width: 2.5rem;
  87. font-size: 2rem;
  88. line-height: 2.25rem;
  89. }
  90. }
  91. @at-root #{&}__header_info {
  92. display: flex;
  93. flex-direction: column;
  94. height: 2.5rem;
  95. }
  96. @at-root #{&}__username {
  97. cursor: pointer;
  98. }
  99. @at-root #{&}__date {
  100. color: $color__gray--darkest;
  101. font-size: 0.9rem;
  102. }
  103. @at-root #{&}__description {
  104. margin-top: 0.25rem;
  105. font-size: 0.9rem;
  106. }
  107. }
  108. </style>