You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

HomeView.vue 2.8KB

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