Преглед изворни кода

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

tags/0.0.3^2
maeda пре 3 година
родитељ
комит
c86fc59c5e

+ 3
- 4
backend/lib/routes/profile/queue.js Прегледај датотеку

23
 
23
 
24
 const validators = {
24
 const validators = {
25
     params: params.profileId,
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
 module.exports = {
29
 module.exports = {
37
         cors: true,
37
         cors: true,
38
         handler: async function (request, h) {
38
         handler: async function (request, h) {
39
             const { profile_id } = request.params
39
             const { profile_id } = request.params
40
-            const { include_profile } = request.query
40
+            const { include_profile, limit, offset} = request.query
41
             const { profileService, matchQueueService } =
41
             const { profileService, matchQueueService } =
42
                 request.server.services()
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
             const queueIds = queue.map(entry => entry.target_id)
45
             const queueIds = queue.map(entry => entry.target_id)
46
-            // console.log('queueIds', queueIds)
47
             const res = {
46
             const res = {
48
                 ok: true,
47
                 ok: true,
49
                 handler: pluginConfig.handlerType,
48
                 handler: pluginConfig.handlerType,

+ 8
- 1
backend/lib/services/matchqueue.js Прегледај датотеку

9
      * @param {number} profileId
9
      * @param {number} profileId
10
      * @returns {array} MatchQueue
10
      * @returns {array} MatchQueue
11
      */
11
      */
12
-    async getQueue(profileId) {
12
+    async getQueue(profileId, limit, offset=0) {
13
         const { MatchQueue } = this.server.models()
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
         return await MatchQueue.query()
20
         return await MatchQueue.query()
16
             .where('profile_id', profileId)
21
             .where('profile_id', profileId)
17
             .where('is_deleted', 0)
22
             .where('is_deleted', 0)
23
+            .limit(limit)
24
+            .offset(offset)
18
     }
25
     }
19
     /**
26
     /**
20
      * Returns queues by profile id by user type
27
      * Returns queues by profile id by user type

+ 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, offset = 0, limit = 5) => {
10
     let queue
12
     let queue
11
     try {
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
         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
         }

+ 27
- 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 =>
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
     methods: {
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
         // this can be placed in utils/notification.js
93
         // this can be placed in utils/notification.js
70
         notify(payload) {
94
         notify(payload) {
71
             notificationOpts.message = payload
95
             notificationOpts.message = payload

Loading…
Откажи
Сачувај