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

ProfileCardList.vue 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template lang="pug">
  2. section.profile_card_list.w-full
  3. .profile_card_list_container.w-full
  4. .swipe(
  5. v-if="!isGrid"
  6. :config="config"
  7. :key="profile.pid"
  8. @throwout="swipped(profile)"
  9. v-for="(profile, i) in loadedProfiles"
  10. :style="{ 'z-index': 1000-i }"
  11. )
  12. .card.b-solid.rounded.p-0.bg-cover.randomize(
  13. :style="{ 'background-image': `url(${profile.avatar})`, 'top': `${randomize(10)}px`, 'right': `${randomize(20)}px`, 'transform': `rotate(${randomize(7)}deg)` }"
  14. )
  15. .card__content
  16. h3.p-1.mv-0.b-solid.rounded {{ profile.pid }} {{ profile.name }}
  17. nav.swipe_icons.w-full.f-row.between
  18. //- Accept
  19. button.p-1(@click="accept") Accept
  20. //- Hold
  21. button.p-1(@click="view(profile.pid)") view
  22. //- Pass
  23. button.p-1(@click="pass") Pass
  24. .match-layout(
  25. v-else
  26. :key="profile.pid"
  27. v-for="(profile, i) in loadedProfiles"
  28. )
  29. .card.b-solid.rounded.p-0.bg-cover(
  30. :style="{ 'background-image': `url(${profile.avatar})` }"
  31. )
  32. .card__content
  33. h3.p-1.mv-0.b-solid.rounded {{ profile.pid }} {{ profile.name }}
  34. </template>
  35. <script setup>
  36. import { useRouter } from 'vue-router'
  37. import { defineProps, defineEmits } from 'vue'
  38. import {
  39. updateQueueByProfileId,
  40. fetchMembershipsByProfileId,
  41. postMembershipByProfileId,
  42. } from '../services'
  43. const router = useRouter()
  44. const emit = defineEmits(['reload-queue'])
  45. // TODO: Please review this conversion from script to script setup
  46. // converted from the props section
  47. const props = defineProps({
  48. profiles: {
  49. type: [Object, Array],
  50. default: () => [
  51. {
  52. pid: '1',
  53. name: 'Full Name',
  54. 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:*',
  55. metadata: { age: '21', rawMetadata: 'Some Text Here!' },
  56. },
  57. ],
  58. },
  59. pid: {
  60. type: Number,
  61. default: 9999,
  62. },
  63. isGrid: {
  64. type: Boolean,
  65. },
  66. })
  67. const swipped = profile => {
  68. const index = loadedProfiles.findIndex(u => u.pid == profile.pid)
  69. loadedProfiles.splice(index, 1)
  70. profile.id = Date.now() + (Math.random() * 100000).toFixed()
  71. loadedProfiles.unshift({ ...profile })
  72. }
  73. const randomize = max => {
  74. const pos = Math.random() > 0.5 ? -1 : 1
  75. return Math.floor(Math.random() * max) * pos
  76. }
  77. // AHP Button behavior
  78. const accept = async () => {
  79. console.log('accepted aka do NOT reinsert')
  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. console.log('Make membership')
  91. postMembershipByProfileId({ profileId, targetId })
  92. }
  93. emit('reload-queue')
  94. }
  95. const view = pid => {
  96. router.push({
  97. name: 'ProfileView',
  98. params: { pid },
  99. })
  100. }
  101. const pass = () => {
  102. console.log('passed aka do reinsert')
  103. // const charmander = await db.get(`/profile/{profile_id}/queue/{target_id}/delete?include_profile=true&reinsert=true`)
  104. const profileId = props.pid
  105. const targetId = props.profiles[0].pid
  106. updateQueueByProfileId(profileId, targetId, true)
  107. emit('reload-queue')
  108. }
  109. // from the data() section
  110. const config = {
  111. // allowedDirections: [VueSwing.Direction.LEFT, VueSwing.Direction.RIGHT],
  112. minThrowOutDistance: 250,
  113. maxThrowOutDistance: 300,
  114. }
  115. // Copy profiles so we don't mutate the original
  116. const loadedProfiles = [...props.profiles]
  117. </script>
  118. <style lang="postcss">
  119. .profile_card_list_container
  120. display: flex
  121. justify-content: center
  122. .swipe
  123. position: absolute
  124. .randomize
  125. position: relative
  126. .card
  127. position: relative
  128. background-color: #fff
  129. width: 250px
  130. max-width: 85vw
  131. height: 50vh
  132. background-position: center
  133. &_content
  134. width: 100%
  135. height: 100%
  136. h3
  137. position: absolute
  138. bottom: 0
  139. .swipe_icons
  140. position: fixed
  141. bottom: 5vh
  142. width: 250px
  143. </style>