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.

home.vue 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template lang="pug">
  2. sidebar
  3. main.f-col.start.w-full
  4. article#home
  5. h1(v-if='user') {{ user.user_name }}
  6. profile-card-list(:profiles='swipables' :uid='mypid')
  7. main-nav
  8. </template>
  9. <script>
  10. import sidebar from '../components/Sidebar.vue'
  11. import mainNav from '../components/MainNav.vue'
  12. import profileCardList from '../components/ProfileCardList.vue'
  13. import { fetchQueueByProfileId } from '../services'
  14. import { Toaster } from '../utils/db'
  15. import batch_10 from '../../../backend/db/generated/_batch_10.js.ref'
  16. import batch_20 from '../../../backend/db/generated/_batch_20.js.ref'
  17. import batch_30 from '../../../backend/db/generated/_batch_30.js.ref'
  18. export default {
  19. name: 'HomeView',
  20. components: { profileCardList, sidebar, mainNav },
  21. data: () => ({
  22. swipables: [],
  23. user: null,
  24. mypid: null,
  25. }),
  26. mounted() {
  27. this.setupToaster()
  28. },
  29. async created() {
  30. // this.mypid = auth.currentUser?.mypid || "99999";
  31. this.mypid = 38
  32. // Uncomment below to use for batch file data
  33. // this.processProfilesFromBatch(this.parseBatch([batch_10, batch_20, batch_30]))
  34. // Uncomment below to use API
  35. const queueList = await fetchQueueByProfileId(this.mypid)
  36. // console.log('queueList', queueList)
  37. this.processQueue(queueList)
  38. },
  39. methods: {
  40. setupToaster() {
  41. const stocks = {}
  42. const source = new EventSource(`http://localhost:3001/api/notification/${this.mypid}/subscribe`)
  43. source.addEventListener('stonk', function (message) {
  44. console.log('updated:', message)
  45. const data = JSON.parse(message.data)
  46. stocks[data.name] = data
  47. })
  48. source.addEventListener('end', function (message) {
  49. this.close()
  50. })
  51. },
  52. processQueue(queueList) {
  53. const formattedList = []
  54. queueList.forEach(profile => {
  55. const formatted = {
  56. uid: profile.profile_id,
  57. name: profile.user_name,
  58. avatar: profile.user_media,
  59. }
  60. formattedList.push(formatted)
  61. })
  62. this.swipables = formattedList
  63. },
  64. // For Batch Data Parsing & Processing
  65. parseBatch(allBatches) {
  66. const finished = { profiles: [], users: [], responses: [] }
  67. allBatches.forEach(batch => {
  68. const split = batch.value.split('\n')
  69. split.splice(0, 5)
  70. split.unshift('{')
  71. const p = JSON.parse(split.join(''))
  72. finished.profiles = [...p.profiles, ...finished.profiles]
  73. finished.users = [...p.users, ...finished.users]
  74. finished.responses = [...p.responses, ...finished.responses]
  75. })
  76. // console.log('parsed batch', finished)
  77. return finished
  78. },
  79. processProfilesFromBatch(parsed) {
  80. const findUser = profile => {
  81. return parsed.users.filter(u => u.user_id == profile.user_id)[0]
  82. }
  83. parsed.profiles.forEach(p => {
  84. // console.log(parsed)
  85. const user = findUser(p)
  86. p.uid = p.profile_id
  87. p.name = user.user_name
  88. p.email = user.user_email
  89. p.avatar = p.user_media[0]
  90. p.responses = parsed.responses.filter(
  91. r => r.profile_id == p.profile_id,
  92. )
  93. p.responses.forEach(r => {
  94. if (r.response_key_id == 7) {
  95. p.zipcode = r.val
  96. }
  97. })
  98. this.swipables.push(p)
  99. })
  100. console.log('swipables', this.swipables)
  101. },
  102. },
  103. }
  104. </script>
  105. <style lang="postcss">
  106. main
  107. position: relative
  108. height: 100%
  109. > article
  110. height: 100%
  111. width: 100%
  112. flex-direction: column
  113. </style>