Bladeren bron

Merge branch 'paginated-queue-return' of fyindr/siimee into dev

tags/0.0.3^2
maeda 3 jaren geleden
bovenliggende
commit
c86fc59c5e

+ 3
- 4
backend/lib/routes/profile/queue.js Bestand weergeven

@@ -23,7 +23,7 @@ const responseSchemas = {
23 23
 
24 24
 const validators = {
25 25
     params: params.profileId,
26
-    query: params.profileInclude,
26
+    query: Joi.object({include_profile: Joi.bool(), limit: Joi.number(), offset: Joi.number()}),
27 27
 }
28 28
 
29 29
 module.exports = {
@@ -37,13 +37,12 @@ module.exports = {
37 37
         cors: true,
38 38
         handler: async function (request, h) {
39 39
             const { profile_id } = request.params
40
-            const { include_profile } = request.query
40
+            const { include_profile, limit, offset} = request.query
41 41
             const { profileService, matchQueueService } =
42 42
                 request.server.services()
43 43
 
44
-            const queue = await matchQueueService.getQueue(profile_id)
44
+            const queue = await matchQueueService.getQueue(profile_id, limit, offset)
45 45
             const queueIds = queue.map(entry => entry.target_id)
46
-            // console.log('queueIds', queueIds)
47 46
             const res = {
48 47
                 ok: true,
49 48
                 handler: pluginConfig.handlerType,

+ 8
- 1
backend/lib/services/matchqueue.js Bestand weergeven

@@ -9,12 +9,19 @@ module.exports = class MatchQueueService extends Schmervice.Service {
9 9
      * @param {number} profileId
10 10
      * @returns {array} MatchQueue
11 11
      */
12
-    async getQueue(profileId) {
12
+    async getQueue(profileId, limit, offset=0) {
13 13
         const { MatchQueue } = this.server.models()
14
+        if(typeof limit==='undefined') {
15
+            return await MatchQueue.query()
16
+                .where('profile_id', profileId)
17
+                .where('is_deleted', 0)
18
+        }
14 19
 
15 20
         return await MatchQueue.query()
16 21
             .where('profile_id', profileId)
17 22
             .where('is_deleted', 0)
23
+            .limit(limit)
24
+            .offset(offset)
18 25
     }
19 26
     /**
20 27
      * Returns queues by profile id by user type

+ 7
- 0
frontend/src/components/ProfileCardList.vue Bestand weergeven

@@ -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 Bestand weergeven

@@ -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, offset = 0, limit = 5) => {
10 12
     let queue
11 13
     try {
12
-        queue = await db.get(`/profile/${profileId}/queue?include_profile=true`)
14
+        queue = await db.get(
15
+            `/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
         }

+ 27
- 3
frontend/src/views/HomeView.vue Bestand weergeven

@@ -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,33 @@ 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 =>
75
+                convertToCard(qProfile),
76
+            )
77
+            if (this.fetchedCards.length === 0) return initialCards
78
+            return [
79
+                ...initialCards,
80
+                ...this.fetchedCards.map(qProfile => convertToCard(qProfile)),
81
+            ]
66 82
         },
67 83
     },
68 84
     methods: {
85
+        async onLoadMore() {
86
+            this.offset += 5 // fetch next batch with updated offset
87
+            let newQueue = await fetchQueueByProfileId(
88
+                currentProfile.id._value,
89
+                this.offset,
90
+            )
91
+            this.fetchedCards.push(...newQueue) // update fetchedCards => recalculate cards
92
+        },
69 93
         // this can be placed in utils/notification.js
70 94
         notify(payload) {
71 95
             notificationOpts.message = payload

Laden…
Annuleren
Opslaan