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.

ProfileCardList.vue 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template lang="pug">
  2. section.profile-card-list
  3. .swipe(
  4. v-if="!isGrid"
  5. :config="config"
  6. :key="profile.pid"
  7. @throwout="swipped(profile)"
  8. v-for="(profile, i) in loadedProfiles"
  9. :style="{ 'z-index': 1000-i }"
  10. )
  11. .card.randomize(
  12. :style="{ 'background-image': `url(${profile.avatar})`, 'top': `${randomize(10)}px`, 'right': `${randomize(20)}px`, 'transform': `rotate(${randomize(7)}deg)` }"
  13. )
  14. .card--content
  15. p(style="color: magenta;") profile: {{ profile.pid }}
  16. .card--content--lower
  17. h4 {{ profile.name }}
  18. nav.swipe_icons
  19. //- Accept
  20. button(@click="accept") Accept
  21. button(@click="view(profile.pid)") view
  22. //- Pass
  23. button(@click="pass") Pass
  24. .match-layout(
  25. v-else
  26. :key="profile.pid"
  27. v-for="(profile, i) in loadedProfiles"
  28. )
  29. .card.bg-cover(
  30. :style="{ 'background-image': `url(${profile.avatar})` }"
  31. )
  32. .card--content
  33. p(style="color: magenta;") profile: {{ profile.pid }}
  34. .card--content--lower
  35. h4 {{ profile.name }}
  36. nav.swipe_icons
  37. button(@click="view(profile.pid)") view
  38. </template>
  39. <script setup>
  40. import { useRouter } from 'vue-router'
  41. import {
  42. updateQueueByProfileId,
  43. fetchMembershipsByProfileId,
  44. postMembershipByProfileId,
  45. } from '../services'
  46. const router = useRouter()
  47. const emit = defineEmits(['reload'])
  48. const props = defineProps({
  49. profiles: {
  50. type: [Object, Array],
  51. default: () => [
  52. {
  53. pid: '1',
  54. name: 'Full Name',
  55. avatar: 'https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/newborn-baby-boy-sleeping-peacefully-wearing-knit-royalty-free-image-1589459736.jpg?crop=0.669xw:1.00xh;0.228xw,0&resize=640:*',
  56. metadata: { age: '21', rawMetadata: 'Some Text Here!' },
  57. },
  58. ],
  59. },
  60. pid: {
  61. type: Number,
  62. default: 9999,
  63. },
  64. isGrid: {
  65. type: Boolean,
  66. },
  67. })
  68. const swipped = profile => {
  69. const index = loadedProfiles.findIndex(u => u.pid == profile.pid)
  70. loadedProfiles.splice(index, 1)
  71. profile.id = Date.now() + (Math.random() * 100000).toFixed()
  72. loadedProfiles.unshift({ ...profile })
  73. }
  74. const randomize = max => {
  75. const pos = Math.random() > 0.5 ? -1 : 1
  76. return Math.floor(Math.random() * max) * pos
  77. }
  78. // AHP Button behavior
  79. const accept = async () => {
  80. // need to pass these arguments (profileId, targetId, status)
  81. // the url structure is
  82. // const charmander = await db.get(`/profile/{profile_id}/queue/{target_id}/delete?include_profile=true&reinsert=false`)
  83. // http://localhost:3001/api/profile/38/queue/9/delete?include_profile=true&reinsert=true
  84. const profileId = props.pid
  85. const targetId = props.profiles[0].pid
  86. updateQueueByProfileId(profileId, targetId, false)
  87. // TODO: next step is grouping/membership
  88. const checkMembership = await fetchMembershipsByProfileId(profileId)
  89. if (!checkMembership.length) {
  90. postMembershipByProfileId({ profileId, targetId })
  91. }
  92. emit('reload')
  93. }
  94. const view = pid => {
  95. router.push({ path: `/matches/${pid}` })
  96. }
  97. const pass = () => {
  98. const targetId = props.profiles[0].pid
  99. updateQueueByProfileId(props.pid, targetId, true)
  100. emit('reload')
  101. }
  102. // from the data() section
  103. const config = {
  104. // allowedDirections: [VueSwing.Direction.LEFT, VueSwing.Direction.RIGHT],
  105. minThrowOutDistance: 250,
  106. maxThrowOutDistance: 300,
  107. }
  108. // Copy profiles so we don't mutate the original
  109. const loadedProfiles = [...props.profiles]
  110. </script>