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

HomeView.vue 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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(@log-out='logout')
  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 {
  21. currentProfile,
  22. authenticator,
  23. fetchQueueByProfileId,
  24. } from '../services'
  25. import { mixins } from '../utils'
  26. const notificationOpts = {
  27. message: null,
  28. timeout: 6000,
  29. bgColor: 'white',
  30. color: 'success',
  31. dismiss: false,
  32. shadow: true,
  33. round: true,
  34. sm: true,
  35. icon: 'wi-star',
  36. }
  37. /** Callback used to format incoming into card */
  38. const convertToCard = profile => {
  39. if (profile.type !== 'profile') {
  40. console.error(`Cannot convert ${profile} to Card. Invalid entity.`)
  41. }
  42. if (!profile.isValid()) {
  43. console.warn(`Profile ${profile.profile_id} is not a valid profile.`)
  44. }
  45. return new Card({
  46. pid: profile.profile_id,
  47. name: profile.user_name,
  48. avatar: profile.profile_media[0],
  49. })
  50. }
  51. export default {
  52. name: 'HomeView',
  53. components: {
  54. ProfileCardList,
  55. AspectBar,
  56. SummaryBar,
  57. PairingButton,
  58. },
  59. mixins: [mixins.profileMixin],
  60. data() {
  61. return {
  62. fetchedCards: [],
  63. offset: 0,
  64. }
  65. },
  66. computed: {
  67. cP() {
  68. return currentProfile ? currentProfile : null
  69. },
  70. cards() {
  71. let initialCards = currentProfile.queue.map(qProfile =>
  72. convertToCard(qProfile),
  73. )
  74. if (this.fetchedCards.length === 0) return initialCards
  75. return [
  76. ...initialCards,
  77. ...this.fetchedCards.map(qProfile => convertToCard(qProfile)),
  78. ]
  79. },
  80. },
  81. methods: {
  82. async onLoadMore() {
  83. this.offset += 5 // fetch next batch with updated offset
  84. let newQueue = await fetchQueueByProfileId(
  85. currentProfile.id._value,
  86. this.offset,
  87. )
  88. this.fetchedCards.push(...newQueue) // update fetchedCards => recalculate cards
  89. },
  90. async logout() {
  91. if (currentProfile.isLoggedIn) {
  92. currentProfile.logout()
  93. }
  94. const hashedSessionToken =
  95. authenticator.grabStoredCookie('siimee_session')
  96. const removedSession = await authenticator.removeSession(
  97. hashedSessionToken,
  98. )
  99. if (removedSession.error)
  100. console.error('ERROR :=>', removedSession.error)
  101. document.cookie = `siimee_session=''; max-age=0; path=/; secure`
  102. this.$router.push('/onboarding')
  103. },
  104. // this can be placed in utils/notification.js
  105. notify(payload) {
  106. notificationOpts.message = payload
  107. this.$waveui.notify(notificationOpts)
  108. },
  109. },
  110. }
  111. </script>