瀏覽代碼

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

tags/0.0.3^2
toj 3 年之前
父節點
當前提交
a831d86912
共有 2 個檔案被更改,包括 20 行新增12 行删除
  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 查看文件

@@ -8,12 +8,12 @@ import { Profile } from '../entities/index.js'
8 8
  * @param {number} offset
9 9
  * @returns {array} profiles
10 10
  */
11
-const fetchQueueByProfileId = async (profileId, limit, offset=0) => {
11
+const fetchQueueByProfileId = async (profileId, offset = 0, limit = 5) => {
12 12
     let queue
13 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 17
         if (!queue?.length) {
18 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 查看文件

@@ -63,23 +63,31 @@ export default {
63 63
         PairingButton,
64 64
     },
65 65
     mixins: [mixins.profileMixin],
66
-    data(){ 
67
-        return { 
66
+    data() {
67
+        return {
68 68
             fetchedCards: [],
69
-            offset: 0 
69
+            offset: 0,
70 70
         }
71 71
     },
72 72
     computed: {
73 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 84
     methods: {
80
-        async onLoadMore(){
85
+        async onLoadMore() {
81 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 91
             this.fetchedCards.push(...newQueue) // update fetchedCards => recalculate cards
84 92
         },
85 93
         // this can be placed in utils/notification.js

Loading…
取消
儲存