Bläddra i källkod

:recycle: small refactor to help with default queue limit request

tags/0.0.3^2
toj 3 år sedan
förälder
incheckning
a831d86912
2 ändrade filer med 20 tillägg och 12 borttagningar
  1. 4
    4
      frontend/src/services/queue.service.js
  2. 16
    8
      frontend/src/views/HomeView.vue

+ 4
- 4
frontend/src/services/queue.service.js Visa fil

8
  * @param {number} offset
8
  * @param {number} offset
9
  * @returns {array} profiles
9
  * @returns {array} profiles
10
  */
10
  */
11
-const fetchQueueByProfileId = async (profileId, limit, offset=0) => {
11
+const fetchQueueByProfileId = async (profileId, offset = 0, limit = 5) => {
12
     let queue
12
     let queue
13
     try {
13
     try {
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
-        
14
+        queue = await db.get(
15
+            `/profile/${profileId}/queue?include_profile=true&limit=${limit}&offset=${offset}`,
16
+        )
17
         if (!queue?.length) {
17
         if (!queue?.length) {
18
             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?'
19
         }
19
         }

+ 16
- 8
frontend/src/views/HomeView.vue Visa fil

63
         PairingButton,
63
         PairingButton,
64
     },
64
     },
65
     mixins: [mixins.profileMixin],
65
     mixins: [mixins.profileMixin],
66
-    data(){ 
67
-        return { 
66
+    data() {
67
+        return {
68
             fetchedCards: [],
68
             fetchedCards: [],
69
-            offset: 0 
69
+            offset: 0,
70
         }
70
         }
71
     },
71
     },
72
     computed: {
72
     computed: {
73
         cards() {
73
         cards() {
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))]
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
+            ]
77
         },
82
         },
78
     },
83
     },
79
     methods: {
84
     methods: {
80
-        async onLoadMore(){
85
+        async onLoadMore() {
81
             this.offset += 5 // fetch next batch with updated offset
86
             this.offset += 5 // fetch next batch with updated offset
82
-            let newQueue = await fetchQueueByProfileId(currentProfile.id._value, 5, this.offset)
87
+            let newQueue = await fetchQueueByProfileId(
88
+                currentProfile.id._value,
89
+                this.offset,
90
+            )
83
             this.fetchedCards.push(...newQueue) // update fetchedCards => recalculate cards
91
             this.fetchedCards.push(...newQueue) // update fetchedCards => recalculate cards
84
         },
92
         },
85
         // this can be placed in utils/notification.js
93
         // this can be placed in utils/notification.js

Laddar…
Avbryt
Spara