StoryTimelineComponent.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <div>
  3. <div v-if="show" class="card card-body p-0 border mt-md-4 mb-md-3 shadow-none">
  4. <div v-if="loading" class="w-100 h-100 d-flex align-items-center justify-content-center">
  5. <div class="spinner-border spinner-border-sm text-lighter" role="status">
  6. <span class="sr-only">Loading...</span>
  7. </div>
  8. </div>
  9. <div v-else class="d-flex align-items-center justify-content-start scrolly">
  10. <div
  11. v-for="(story, index) in stories"
  12. class="px-3 pt-3 text-center cursor-pointer"
  13. :class="{ seen: story.seen }"
  14. @click="showStory(index)">
  15. <span
  16. :class="[
  17. story.seen ? 'not-seen' : '',
  18. story.local ? '' : 'remote'
  19. ]"
  20. class="mb-1 ring">
  21. <img :src="story.avatar" width="60" height="60" class="rounded-circle border" onerror="this.onerror=null;this.src='/storage/avatars/default.png?v=2'">
  22. </span>
  23. <p
  24. class="small font-weight-bold text-truncate"
  25. :class="{ 'text-lighter': story.seen }"
  26. style="max-width: 69px"
  27. :title="story.username"
  28. >
  29. {{story.username}}
  30. </p>
  31. </div>
  32. </div>
  33. </div>
  34. </div>
  35. </template>
  36. <script type="text/javascript">
  37. export default {
  38. props: ['list', 'scope'],
  39. data() {
  40. return {
  41. loading: true,
  42. show: true,
  43. stories: {},
  44. }
  45. },
  46. mounted() {
  47. this.fetchStories();
  48. },
  49. methods: {
  50. fetchStories() {
  51. axios.get('/api/web/stories/v1/recent')
  52. .then(res => {
  53. let data = res.data;
  54. if(!res.data.length) {
  55. this.show = false;
  56. return;
  57. }
  58. this.stories = res.data;
  59. this.loading = false;
  60. }).catch(err => {
  61. this.loading = false;
  62. this.$bvToast.toast('Cannot load stories. Please try again later.', {
  63. title: 'Error',
  64. variant: 'danger',
  65. autoHideDelay: 5000
  66. });
  67. this.show = false;
  68. });
  69. },
  70. showStory(index) {
  71. let suffix;
  72. switch(this.scope) {
  73. case 'home':
  74. suffix = '/?t=1';
  75. break;
  76. case 'local':
  77. suffix = '/?t=2';
  78. break;
  79. case 'network':
  80. suffix = '/?t=3';
  81. break;
  82. }
  83. window.location.href = this.stories[index].url + suffix;
  84. }
  85. }
  86. }
  87. </script>
  88. <style lang="scss" scoped>
  89. .card {
  90. height: 122px;
  91. }
  92. .ring {
  93. display: block;
  94. width: 66px;
  95. height: 66px;
  96. border-radius: 50%;
  97. padding: 3px;
  98. background: radial-gradient(ellipse at 70% 70%, #ee583f 8%, #d92d77 42%, #bd3381 58%);
  99. &.remote {
  100. background: radial-gradient(ellipse at 70% 70%, #f64f59 8%, #c471ed 42%, #12c2e9 58%);
  101. }
  102. &.not-seen {
  103. opacity: 0.55;
  104. background: #ccc;
  105. }
  106. img {
  107. background: #fff;
  108. padding: 3px;
  109. }
  110. }
  111. .scrolly {
  112. -ms-overflow-style: none;
  113. scrollbar-width: none;
  114. overflow-y: scroll;
  115. &::-webkit-scrollbar {
  116. display: none;
  117. }
  118. }
  119. </style>