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 1.5KB

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