瀏覽代碼

:radio_button: button to load more queue results with pagination

tags/0.0.3^2
juancarbajal98 3 年之前
父節點
當前提交
aaf563ec52

+ 7
- 0
frontend/src/components/ProfileCardList.vue 查看文件

@@ -8,6 +8,7 @@ section.profile-card-list.xs12.w-flex.column
8 8
             :key='`${card.pid}-${i}`'
9 9
             v-for='(card, i) in cards'
10 10
         )
11
+        w-button.pa8.more-results(bg-color='primary' @click="loadMoreResults()")
11 12
 </template>
12 13
 
13 14
 <script setup>
@@ -17,6 +18,8 @@ import ProfileCard from './ProfileCard.vue'
17 18
 
18 19
 const aspects = ref(cardAspects)
19 20
 
21
+const emit = defineEmits(['loadMore'])
22
+
20 23
 const props = defineProps({
21 24
     cards: {
22 25
         type: [Object, Array],
@@ -32,10 +35,14 @@ const props = defineProps({
32 35
         ],
33 36
     },
34 37
 })
38
+
39
+const loadMoreResults = () => { emit('loadMore') } // TODO update to scroll
35 40
 </script>
36 41
 
37 42
 <style lang="sass">
38 43
 .profile-card-list
39 44
     > header > .w-select >.primary
40 45
         margin-top: 0
46
+.more-results
47
+    margin-bottom: 2em
41 48
 </style>

+ 6
- 2
frontend/src/services/queue.service.js 查看文件

@@ -4,12 +4,16 @@ import { Profile } from '../entities/index.js'
4 4
 /**
5 5
  * Get a match queue of profiles
6 6
  * @param {number} profileId
7
+ * @param {number} limit
8
+ * @param {number} offset
7 9
  * @returns {array} profiles
8 10
  */
9
-const fetchQueueByProfileId = async profileId => {
11
+const fetchQueueByProfileId = async (profileId, limit, offset=0) => {
10 12
     let queue
11 13
     try {
12
-        queue = await db.get(`/profile/${profileId}/queue?include_profile=true`)
14
+        if(typeof limit==='undefined') queue = await db.get(`/profile/${profileId}/queue?include_profile=true&limit=5`)
15
+        else queue = await db.get(`/profile/${profileId}/queue?include_profile=true&limit=${limit}&offset=${offset}`)
16
+        
13 17
         if (!queue?.length) {
14 18
             throw '[Queue Service]: Could not retrieve match queue.\nHave you taken the survey and scored this profile?'
15 19
         }

+ 19
- 3
frontend/src/views/HomeView.vue 查看文件

@@ -5,7 +5,10 @@ main.view--home
5 5
             w-spinner(bounce)
6 6
 
7 7
         template(v-else-if='!isLoading && cards.length > 0')
8
-            ProfileCardList(:cards='cards')
8
+            ProfileCardList(
9
+                :cards='cards' 
10
+                @loadMore='onLoadMore'
11
+            )
9 12
 
10 13
         template(v-else-if='cards.length === 0')
11 14
             p No profiles in match_queue.
@@ -21,7 +24,7 @@ import PairingButton from '../components/PairingButton.vue'
21 24
 
22 25
 import { Card } from '../entities'
23 26
 
24
-import { currentProfile } from '../services'
27
+import { currentProfile, fetchQueueByProfileId } from '../services'
25 28
 import { mixins } from '../utils'
26 29
 
27 30
 const notificationOpts = {
@@ -60,12 +63,25 @@ export default {
60 63
         PairingButton,
61 64
     },
62 65
     mixins: [mixins.profileMixin],
66
+    data(){ 
67
+        return { 
68
+            fetchedCards: [],
69
+            offset: 0 
70
+        }
71
+    },
63 72
     computed: {
64 73
         cards() {
65
-            return currentProfile.queue.map(qProfile => convertToCard(qProfile))
74
+            let initialCards = currentProfile.queue.map(qProfile => convertToCard(qProfile))
75
+            if(this.fetchedCards.length === 0) return initialCards
76
+            return [...initialCards,...this.fetchedCards.map(qProfile => convertToCard(qProfile))]
66 77
         },
67 78
     },
68 79
     methods: {
80
+        async onLoadMore(){
81
+            this.offset += 5 // fetch next batch with updated offset
82
+            let newQueue = await fetchQueueByProfileId(currentProfile.id._value, 5, this.offset)
83
+            this.fetchedCards.push(...newQueue) // update fetchedCards => recalculate cards
84
+        },
69 85
         // this can be placed in utils/notification.js
70 86
         notify(payload) {
71 87
             notificationOpts.message = payload

Loading…
取消
儲存