Просмотр исходного кода

:radio_button: button to load more queue results with pagination

tags/0.0.3^2
juancarbajal98 3 лет назад
Родитель
Сommit
aaf563ec52

+ 7
- 0
frontend/src/components/ProfileCardList.vue Просмотреть файл

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

+ 6
- 2
frontend/src/services/queue.service.js Просмотреть файл

4
 /**
4
 /**
5
  * Get a match queue of profiles
5
  * Get a match queue of profiles
6
  * @param {number} profileId
6
  * @param {number} profileId
7
+ * @param {number} limit
8
+ * @param {number} offset
7
  * @returns {array} profiles
9
  * @returns {array} profiles
8
  */
10
  */
9
-const fetchQueueByProfileId = async profileId => {
11
+const fetchQueueByProfileId = async (profileId, limit, offset=0) => {
10
     let queue
12
     let queue
11
     try {
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
         if (!queue?.length) {
17
         if (!queue?.length) {
14
             throw '[Queue Service]: Could not retrieve match queue.\nHave you taken the survey and scored this profile?'
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
             w-spinner(bounce)
5
             w-spinner(bounce)
6
 
6
 
7
         template(v-else-if='!isLoading && cards.length > 0')
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
         template(v-else-if='cards.length === 0')
13
         template(v-else-if='cards.length === 0')
11
             p No profiles in match_queue.
14
             p No profiles in match_queue.
21
 
24
 
22
 import { Card } from '../entities'
25
 import { Card } from '../entities'
23
 
26
 
24
-import { currentProfile } from '../services'
27
+import { currentProfile, fetchQueueByProfileId } from '../services'
25
 import { mixins } from '../utils'
28
 import { mixins } from '../utils'
26
 
29
 
27
 const notificationOpts = {
30
 const notificationOpts = {
60
         PairingButton,
63
         PairingButton,
61
     },
64
     },
62
     mixins: [mixins.profileMixin],
65
     mixins: [mixins.profileMixin],
66
+    data(){ 
67
+        return { 
68
+            fetchedCards: [],
69
+            offset: 0 
70
+        }
71
+    },
63
     computed: {
72
     computed: {
64
         cards() {
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
     methods: {
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
         // this can be placed in utils/notification.js
85
         // this can be placed in utils/notification.js
70
         notify(payload) {
86
         notify(payload) {
71
             notificationOpts.message = payload
87
             notificationOpts.message = payload

Загрузка…
Отмена
Сохранить