Bläddra i källkod

:wrench: WIP trying to incorporate services to Pairs page

tags/0.0.1^2
juancarbajal98 3 år sedan
förälder
incheckning
9a21ac645a
2 ändrade filer med 57 tillägg och 6 borttagningar
  1. 18
    0
      frontend/src/components/PairsList.vue
  2. 39
    6
      frontend/src/views/MatchesView.vue

+ 18
- 0
frontend/src/components/PairsList.vue Visa fil

@@ -0,0 +1,18 @@
1
+<template lang="pug">
2
+section.pairs-list
3
+    article
4
+        .pair(
5
+            v-for="p in pairs"
6
+        )
7
+            h3 {{p.name}}
8
+    
9
+</template>
10
+
11
+<script setup>
12
+const props = defineProps({
13
+    pairs: {
14
+        type: [Object, Array],
15
+        default: () => [{}],
16
+    },
17
+})
18
+</script>

+ 39
- 6
frontend/src/views/MatchesView.vue Visa fil

@@ -5,10 +5,11 @@ main.view--matches
5 5
         .matches--paired(:class="currentTab =='paired' ? 'active':'idle'" @click="switchTab('paired')") Paired
6 6
 
7 7
     article.pa12
8
+        //- TODO add and render appropriate lists for both tabs
8 9
         template(v-if="currentTab=='pending'")
9
-            p Pending Matches
10
+            PairsList(:list='pendingList')
10 11
         template(v-else)
11
-            p Paired Matches
12
+            PairsList(:list='pairedList')
12 13
         //- template(v-if='matches.length && !loading')
13 14
         //-     h2 atches
14 15
         //-     ProfileCardList(:pid='pid' :profiles='matches' @reload='getCards')
@@ -20,14 +21,43 @@ main.view--matches
20 21
 </template>
21 22
 
22 23
 <script>
23
-import ProfileCardList from '../components/ProfileCardList.vue'
24
+// import ProfileCardList from '../components/ProfileCardList.vue'
25
+import PairsList from '../components/PairsList.vue'
24 26
 
25
-import { fetchMembershipsByProfileId } from '../services'
27
+import { fetchMembershipsByProfileId, fetchQueueByProfileId } from '../services'
26 28
 import { mixins } from '../utils'
27 29
 
30
+const convertToCard = profile => {
31
+    if (profile.type !== 'profile') {
32
+        console.error(`Cannot convert ${profile} to Card. Invalid entity.`)
33
+    }
34
+    if (!profile.isValid()) {
35
+        console.warn(`Profile ${profile.profile_id} is not a valid profile.`)
36
+    }
37
+    return new Card({
38
+        pid: profile.profile_id,
39
+        name: profile.user_name,
40
+        avatar: profile.profile_media[0],
41
+    })
42
+}
43
+
44
+const converGroupingToCard = grouping => {
45
+    if (grouping.type !== 'grouping') {
46
+        console.error(`Cannot convert ${grouping} to Card. Invalid entity.`)
47
+    }
48
+    if (!grouping.profile.isValid()) {
49
+        console.warn(`Profile in ${grouping} is not a valid profile.`)
50
+    }
51
+    return new Card({
52
+        pid: grouping.profile.profile_id,
53
+        name: grouping.profile.user_name,
54
+        avatar: grouping.profile.profile_media[0],
55
+    })
56
+}
57
+
28 58
 export default {
29 59
     name: 'MatchView',
30
-    components: { ProfileCardList },
60
+    components: { PairsList },
31 61
     mixins: [mixins.pidMixin, mixins.cardMixin],
32 62
     data: () => ({
33 63
         currentTab: 'pending'
@@ -37,7 +67,10 @@ export default {
37 67
         async getCards() {
38 68
             this.loading = true
39 69
             try {
40
-                this.cards = await fetchMembershipsByProfileId(this.pid)
70
+                const pending = await fetchQueueByProfileId(this.pid)
71
+                this.pendingList = this._reformat(pending,converGroupingToCard)
72
+                const paired = await fetchMembershipsByProfileId(this.pid)
73
+                this.PairedList = this._reformat(paired,convertToCard)
41 74
             } catch (err) {
42 75
                 console.error(err)
43 76
             }

Laddar…
Avbryt
Spara