StoryTimelineComponent.vue 2.9 KB

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