Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

HomeView.vue 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <template lang="pug">
  2. main.view--home(style="display:flex; flex-direction:column; gap: 40px")
  3. div.view--nav(style="display: flex; justify-content: space-between;")
  4. header
  5. h2 home - profile: {{ pid }}
  6. w-drawer(v-model="openDrawer")
  7. w-button(@click="openDrawer = true" outline="")
  8. | Active Chats
  9. h2 Match Queue
  10. article(v-if="cards.length && !loading")
  11. ProfileCardList(:profiles="cards" :pid="pid" @reload="getCards")
  12. p(v-else) Loading...
  13. h2 Matches
  14. article(v-if="matches.length && !loading")
  15. ProfileCardList(:profiles="matches" :pid="pid" @reload="getCards")
  16. p(v-else-if="matches.length===0") No matches.
  17. p(v-else) Loading...
  18. </template>
  19. <script>
  20. import ProfileCardList from '../components/ProfileCardList.vue'
  21. import { Card } from '../entities'
  22. import { fetchQueueByProfileId, fetchMembershipsByProfileId } from '../services'
  23. import { mixins } from '../utils'
  24. /** Callback used to format incoming into card */
  25. const convertToCard = profile => {
  26. if (profile.type !== 'profile') {
  27. console.error(`Cannot convert ${profile} to Card. Invalid entity.`)
  28. }
  29. if (!profile.isValid()) {
  30. console.warn(`Profile ${profile.profile_id} is not a valid profile.`)
  31. }
  32. return new Card({
  33. pid: profile.profile_id,
  34. name: profile.user_name,
  35. avatar: profile.profile_media[0],
  36. })
  37. }
  38. const converGroupingToCard = grouping => {
  39. if (grouping.type !== 'grouping') {
  40. console.error(`Cannot convert ${grouping} to Card. Invalid entity.`)
  41. }
  42. if (!grouping.profile.isValid()) {
  43. console.warn(`Profile in ${grouping} is not a valid profile.`)
  44. }
  45. return new Card({
  46. pid: grouping.profile.profile_id,
  47. name: grouping.profile.user_name,
  48. avatar: grouping.profile.profile_media[0],
  49. })
  50. }
  51. export default {
  52. name: 'HomeView',
  53. components: { ProfileCardList },
  54. mixins: [mixins.pidMixin, mixins.cardMixin],
  55. data: () => ({
  56. openDrawer: false,
  57. }),
  58. methods: {
  59. /** Gets called from cardMixin */
  60. async getCards() {
  61. this.loading = true
  62. try {
  63. const queueList = await fetchQueueByProfileId(this.pid)
  64. this.cards = this._reformat(queueList, convertToCard)
  65. const matchList = await fetchMembershipsByProfileId(this.pid)
  66. this.matches = this._reformat(matchList, converGroupingToCard)
  67. } catch (err) {
  68. console.error(err)
  69. }
  70. this.loading = false
  71. },
  72. },
  73. }
  74. </script>