Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

HomeView.vue 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template lang="pug">
  2. main.view--home
  3. article.w-flex.column.align-center
  4. template(v-if='isLoading')
  5. w-spinner(bounce)
  6. template(v-else-if='!isLoading && cards.length > 0')
  7. ProfileCardList(
  8. :cards='cards'
  9. @loadMore='onLoadMore'
  10. )
  11. template(v-else-if='cards.length === 0')
  12. p No profiles in match_queue.
  13. MainNav
  14. </template>
  15. <script>
  16. import 'wave-ui/dist/wave-ui.css'
  17. import ProfileCardList from '../components/ProfileCardList.vue'
  18. import AspectBar from '../components/AspectBar.vue'
  19. import SummaryBar from '../components/SummaryBar.vue'
  20. import PairingButton from '../components/PairingButton.vue'
  21. import { Card } from '../entities'
  22. import { currentProfile, fetchQueueByProfileId } from '../services'
  23. import { mixins } from '../utils'
  24. const notificationOpts = {
  25. message: null,
  26. timeout: 6000,
  27. bgColor: 'white',
  28. color: 'success',
  29. dismiss: false,
  30. shadow: true,
  31. round: true,
  32. sm: true,
  33. icon: 'wi-star',
  34. }
  35. /** Callback used to format incoming into card */
  36. const convertToCard = profile => {
  37. if (profile.type !== 'profile') {
  38. console.error(`Cannot convert ${profile} to Card. Invalid entity.`)
  39. }
  40. if (!profile.isValid()) {
  41. console.warn(`Profile ${profile.profile_id} is not a valid profile.`)
  42. }
  43. return new Card({
  44. pid: profile.profile_id,
  45. name: profile.user_name,
  46. avatar: profile.profile_media[0],
  47. })
  48. }
  49. export default {
  50. name: 'HomeView',
  51. components: {
  52. ProfileCardList,
  53. AspectBar,
  54. SummaryBar,
  55. PairingButton,
  56. },
  57. mixins: [mixins.profileMixin],
  58. data() {
  59. return {
  60. fetchedCards: [],
  61. offset: 0,
  62. }
  63. },
  64. computed: {
  65. cards() {
  66. let initialCards = currentProfile.queue.map(qProfile =>
  67. convertToCard(qProfile),
  68. )
  69. if (this.fetchedCards.length === 0) return initialCards
  70. return [
  71. ...initialCards,
  72. ...this.fetchedCards.map(qProfile => convertToCard(qProfile)),
  73. ]
  74. },
  75. },
  76. methods: {
  77. async onLoadMore() {
  78. this.offset += 5 // fetch next batch with updated offset
  79. let newQueue = await fetchQueueByProfileId(
  80. currentProfile.id._value,
  81. this.offset,
  82. )
  83. this.fetchedCards.push(...newQueue) // update fetchedCards => recalculate cards
  84. },
  85. // this can be placed in utils/notification.js
  86. notify(payload) {
  87. notificationOpts.message = payload
  88. this.$waveui.notify(notificationOpts)
  89. },
  90. },
  91. }
  92. </script>