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

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