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.

MatchesView.vue 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <template lang="pug">
  2. main.view--matches.f-col.start.w-full
  3. header
  4. h2 Matches
  5. article(v-if='matches.length && !loading')
  6. ProfileCardList(:pid='pid' :profiles='matches' @reload='getCards')
  7. p(v-else-if='matches.length === 0') No matches.
  8. p(v-else) Loading...
  9. MainNav
  10. </template>
  11. <script>
  12. import ProfileCardList from '../components/ProfileCardList.vue'
  13. import { Card } from '../entities'
  14. import { fetchMembershipsByProfileId } from '../services'
  15. import { mixins } from '../utils'
  16. /** Callback used to format incoming into card */
  17. const convertToCard = grouping => {
  18. if (grouping.type !== 'grouping') {
  19. console.error(`Cannot convert ${grouping} to Card. Invalid entity.`)
  20. }
  21. if (!grouping.profile.isValid()) {
  22. console.warn(`Profile in ${grouping} is not a valid profile.`)
  23. }
  24. return new Card({
  25. pid: grouping.profile.profile_id,
  26. name: grouping.profile.user_name,
  27. avatar: grouping.profile.profile_media[0],
  28. })
  29. }
  30. export default {
  31. name: 'MatchView',
  32. components: { ProfileCardList },
  33. mixins: [mixins.pidMixin, mixins.cardMixin],
  34. methods: {
  35. /** Gets called from cardMixin */
  36. async getCards() {
  37. this.loading = true
  38. try {
  39. const matchList = await fetchMembershipsByProfileId(this.pid)
  40. this.cards = this._reformat(matchList, convertToCard)
  41. } catch (err) {
  42. console.error(err)
  43. }
  44. this.loading = false
  45. },
  46. },
  47. }
  48. </script>