NotificationCard.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <div>
  3. <div class="card notification-card">
  4. <div class="card-header bg-white">
  5. <p class="mb-0 d-flex align-items-center justify-content-between">
  6. <span class="text-muted font-weight-bold">Notifications</span>
  7. <a class="text-dark small" href="/account/activity">See All</a>
  8. </p>
  9. </div>
  10. <div class="card-body loader text-center" style="height: 270px;">
  11. <div class="spinner-border" role="status">
  12. <span class="sr-only">Loading...</span>
  13. </div>
  14. </div>
  15. <div class="card-body pt-2 contents" style="max-height: 270px; overflow-y: scroll;">
  16. <div v-if="notifications.length > 0" class="media mb-3 align-items-center" v-for="(n, index) in notifications">
  17. <img class="mr-2 rounded-circle" style="border:1px solid #ccc" :src="n.account.avatar" alt="" width="32px" height="32px">
  18. <div class="media-body font-weight-light small">
  19. <div v-if="n.type == 'favourite'">
  20. <p class="my-0">
  21. <a :href="n.account.url" class="font-weight-bold text-dark word-break" data-placement="bottom" data-toggle="tooltip" :title="n.account.username">{{truncate(n.account.username)}}</a> liked your <a class="font-weight-bold" v-bind:href="n.status.url">post</a>.
  22. </p>
  23. </div>
  24. <div v-else-if="n.type == 'comment'">
  25. <p class="my-0">
  26. <a :href="n.account.url" class="font-weight-bold text-dark word-break" data-placement="bottom" data-toggle="tooltip" :title="n.account.username">{{truncate(n.account.username)}}</a> commented on your <a class="font-weight-bold" v-bind:href="n.status.url">post</a>.
  27. </p>
  28. </div>
  29. <div v-else-if="n.type == 'mention'">
  30. <p class="my-0">
  31. <a :href="n.account.url" class="font-weight-bold text-dark word-break" data-placement="bottom" data-toggle="tooltip" :title="n.account.username">{{truncate(n.account.username)}}</a> <a class="font-weight-bold" v-bind:href="mentionUrl(n.status)">mentioned</a> you.
  32. </p>
  33. </div>
  34. <div v-else-if="n.type == 'follow'">
  35. <p class="my-0">
  36. <a :href="n.account.url" class="font-weight-bold text-dark word-break" data-placement="bottom" data-toggle="tooltip" :title="n.account.username">{{truncate(n.account.username)}}</a> followed you.
  37. </p>
  38. </div>
  39. <div v-else-if="n.type == 'share'">
  40. <p class="my-0">
  41. <a :href="n.account.url" class="font-weight-bold text-dark word-break" data-placement="bottom" data-toggle="tooltip" :title="n.account.username">{{truncate(n.account.username)}}</a> shared your <a class="font-weight-bold" v-bind:href="n.status.reblog.url">post</a>.
  42. </p>
  43. </div>
  44. </div>
  45. </div>
  46. <div v-if="notifications.length">
  47. <infinite-loading @infinite="infiniteNotifications">
  48. <div slot="no-results" class="font-weight-bold"></div>
  49. <div slot="no-more" class="font-weight-bold"></div>
  50. </infinite-loading>
  51. </div>
  52. <div v-if="notifications.length == 0" class="text-lighter text-center py-3">
  53. <p class="mb-0"><i class="fas fa-inbox fa-3x"></i></p>
  54. <p class="mb-0 small font-weight-bold">0 Notifications!</p>
  55. </div>
  56. </div>
  57. </div>
  58. </div>
  59. </template>
  60. <style type="text/css" scoped></style>
  61. <script type="text/javascript">
  62. export default {
  63. data() {
  64. return {
  65. notifications: {},
  66. notificationCursor: 2
  67. };
  68. },
  69. mounted() {
  70. this.fetchNotifications();
  71. },
  72. updated() {
  73. $('[data-toggle="tooltip"]').tooltip()
  74. },
  75. methods: {
  76. fetchNotifications() {
  77. axios.get('/api/v1/notifications')
  78. .then(res => {
  79. let data = res.data.filter(n => {
  80. if(n.type == 'share' && !status) {
  81. return false;
  82. }
  83. return true;
  84. });
  85. this.notifications = data;
  86. $('.notification-card .loader').addClass('d-none');
  87. $('.notification-card .contents').removeClass('d-none');
  88. });
  89. },
  90. infiniteNotifications($state) {
  91. if(this.notificationCursor > 10) {
  92. $state.complete();
  93. return;
  94. }
  95. axios.get('/api/v1/notifications', {
  96. params: {
  97. page: this.notificationCursor
  98. }
  99. }).then(res => {
  100. if(res.data.length) {
  101. let data = res.data.filter(n => {
  102. if(n.type == 'share' && !status) {
  103. return false;
  104. }
  105. return true;
  106. });
  107. this.notifications.push(...data);
  108. this.notificationCursor++;
  109. $state.loaded();
  110. } else {
  111. $state.complete();
  112. }
  113. });
  114. },
  115. truncate(text) {
  116. if(text.length <= 15) {
  117. return text;
  118. }
  119. return text.slice(0,15) + '...'
  120. }
  121. }
  122. }
  123. </script>