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

HomeView.vue 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template lang="pug">
  2. main.view--home(
  3. style='display: flex; flex-direction: column; gap: 40px; margin-top: 1em'
  4. )
  5. header
  6. h2 Match Queue
  7. article(v-if='cards.length && !loading')
  8. ProfileCardList(:pid='pid' :profiles='cards' @reload='getCards')
  9. p(v-else-if='cards.length === 0') No profiles in match_queue.
  10. p(v-else) Loading...
  11. MainNav
  12. </template>
  13. <script>
  14. import 'wave-ui/dist/wave-ui.css'
  15. import ProfileCardList from '../components/ProfileCardList.vue'
  16. import { Card } from '../entities'
  17. import {
  18. fetchQueueByProfileId,
  19. fetchMembershipsByProfileId,
  20. currentProfile,
  21. } from '../services'
  22. import { mixins } from '../utils'
  23. /** Callback used to format incoming into card */
  24. const convertToCard = profile => {
  25. if (profile.type !== 'profile') {
  26. console.error(`Cannot convert ${profile} to Card. Invalid entity.`)
  27. }
  28. if (!profile.isValid()) {
  29. console.warn(`Profile ${profile.profile_id} is not a valid profile.`)
  30. }
  31. return new Card({
  32. pid: profile.profile_id,
  33. name: profile.user_name,
  34. avatar: profile.profile_media[0],
  35. })
  36. }
  37. const converGroupingToCard = grouping => {
  38. if (grouping.type !== 'grouping') {
  39. console.error(`Cannot convert ${grouping} to Card. Invalid entity.`)
  40. }
  41. if (!grouping.profile.isValid()) {
  42. console.warn(`Profile in ${grouping} is not a valid profile.`)
  43. }
  44. return new Card({
  45. pid: grouping.profile.profile_id,
  46. name: grouping.profile.user_name,
  47. avatar: grouping.profile.profile_media[0],
  48. })
  49. }
  50. export default {
  51. name: 'HomeView',
  52. components: { ProfileCardList },
  53. mixins: [mixins.pidMixin, mixins.cardMixin],
  54. methods: {
  55. /** Gets called from cardMixin */
  56. async getCards() {
  57. this.loading = true
  58. try {
  59. const queueList = await fetchQueueByProfileId(this.pid)
  60. this.cards = this._reformat(queueList, convertToCard)
  61. const matchList = await fetchMembershipsByProfileId(this.pid)
  62. this.matches = this._reformat(matchList, converGroupingToCard)
  63. } catch (err) {
  64. console.error(err)
  65. }
  66. this.loading = false
  67. },
  68. // this can be placed in utils/notification.js
  69. notify(payload) {
  70. this.$waveui.notify({
  71. message: payload.timetoken,
  72. timeout: 6000,
  73. bgColor: 'white',
  74. color: 'success',
  75. dismiss: false,
  76. shadow: true,
  77. round: true,
  78. sm: true,
  79. icon: 'wi-star',
  80. })
  81. },
  82. // a way to send a message to a user for development purposes and testing
  83. async chat() {
  84. const chatter = currentProfile.chatter
  85. const res = await chatter.publish(chatter.subscriptions[0], {
  86. title: 'New Message',
  87. description: 'This is a new message',
  88. })
  89. this.notify(res)
  90. },
  91. },
  92. }
  93. </script>