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

:recycle: moving service calls into the current logged in profile

tags/0.0.3^2
j пре 3 година
родитељ
комит
49b5a3b7bb

+ 13
- 16
frontend/src/components/ProfileCard.vue Прегледај датотеку

@@ -44,11 +44,7 @@ w-card.profile-card-list--card.xs12
44 44
 <script setup>
45 45
 import { ref } from 'vue'
46 46
 import { useRouter } from 'vue-router'
47
-import {
48
-    updateQueueByProfileId,
49
-    postMembershipByProfileId,
50
-    currentProfile,
51
-} from '../services'
47
+import { postMembershipByProfileId, currentProfile } from '../services'
52 48
 
53 49
 import NamePlate from './NamePlate.vue'
54 50
 import AspectBar from './AspectBar.vue'
@@ -91,18 +87,18 @@ const onTab = tabIndex => {
91 87
  * for both profileId and targetId
92 88
  */
93 89
 const onPair = async () => {
94
-    const group = await postMembershipByProfileId({
95
-        profileId: currentProfile.id.value,
96
-        targetId: props.card.pid,
90
+    currentProfile._loading = true
91
+    const profileId = currentProfile.id.value
92
+    const targetId = props.card.pid
93
+    await postMembershipByProfileId({
94
+        profileId,
95
+        targetId,
97 96
     })
98
-    updateQueueByProfileId(currentProfile.id.value, props.card.pid, false)
99
-    currentProfile.getGroupings()
100
-    console.warn('created grouping:', group)
97
+    await currentProfile.updateQueue(profileId, targetId, false)
98
+    await currentProfile.getGroupings()
99
+    currentProfile._loading = false
101 100
 
102 101
     let goToRoute = { name: 'HomeView' }
103
-    // if (group.membershipMatch.hasMatch) {
104
-    //     goToRoute = { name: 'PairsView' }
105
-    // }
106 102
     router.push(goToRoute)
107 103
 }
108 104
 
@@ -111,8 +107,9 @@ const onPair = async () => {
111 107
  * and forward back home
112 108
  */
113 109
 const onPass = async () => {
114
-    updateQueueByProfileId(currentProfile.id.value, props.card.pid, true)
115
-    router.push({ name: 'HomeView' })
110
+    currentProfile.updateQueue(currentProfile.id.value, props.card.pid, true)
111
+    let goToRoute = { name: 'HomeView' }
112
+    router.push(goToRoute)
116 113
 }
117 114
 </script>
118 115
 

+ 5
- 49
frontend/src/components/ProfileCardList.vue Прегледај датотеку

@@ -1,8 +1,5 @@
1 1
 <template lang="pug">
2 2
 section.profile-card-list.xs12.w-flex.column
3
-    header.xs12.w-flex 
4
-        //- w-select(:items="['one', 'two', 'three']" outline) Label
5
-
6 3
     article
7 4
         ProfileCard.match-layout(
8 5
             :aspects='aspects'
@@ -54,59 +51,18 @@ const props = defineProps({
54 51
             },
55 52
         ],
56 53
     },
57
-    pid: {
58
-        type: Number,
59
-        default: 9999,
60
-    },
61 54
     isGrid: {
62 55
         type: Boolean,
63 56
     },
64 57
 })
65 58
 
66
-// AHP Button behavior
67
-const accept = async targetId => {
68
-    if (targetId == props.pid) return
69
-    // need to pass these arguments (profileId, targetId, status)
70
-    // the url structure is
71
-    // const charmander = await db.get(`/profile/{profile_id}/queue/{target_id}/delete?include_profile=true&reinsert=false`)
72
-    // http://localhost:3001/api/profile/38/queue/9/delete?include_profile=true&reinsert=true
73
-    const profileId = props.pid
74
-    await updateQueueByProfileId(profileId, targetId, false)
75
-    const { membershipMatch, groupingName } = await postMembershipByProfileId({
76
-        profileId,
77
-        targetId,
78
-    })
79
-
80
-    // Reuse old grouping name if theres a match
81
-    let channel = groupingName
82
-    if (membershipMatch?.hasMatch) {
83
-        channel = membershipMatch.groupings[0].grouping_name
84
-    }
85
-    await subscribeToChannel(channel)
86
-    emit('reload')
87
-}
88
-
59
+/**
60
+ * publish a new message to the chatter with the channel and the message & title is optional
61
+ */
89 62
 const subscribeToChannel = async channelName => {
90
-    // create a chatter reference from the current profile
91
-    const chatter = currentProfile.chatter
92
-
93
-    /**
94
-     * publish a new message to the chatter with the channel and the message & title is optional
95
-     */
96 63
     // You MUST send chatter channels as an array in an object
97
-    chatter.subscribe({ channels: [channelName] })
98
-    const res = await chatter.publish(channelName, {
99
-        title: 'New Message',
100
-        description: `This is the checking to see if we are subscribed to the ${channelName} channel!`,
101
-    })
102
-    // PubNub response will be a timecode of when the message was published
103
-    //router.push({ path: `/chat/${pid}` })
104
-}
105
-
106
-const pass = targetId => {
107
-    if (targetId == props.pid) return
108
-    updateQueueByProfileId(props.pid, targetId, true)
109
-    emit('reload')
64
+    const channels = [channelName]
65
+    currentProfile.chatter.subscribe({ channels })
110 66
 }
111 67
 </script>
112 68
 

+ 13
- 13
frontend/src/components/TagList.vue Прегледај датотеку

@@ -1,6 +1,6 @@
1 1
 <template lang="pug">
2 2
 section.w-flex.row.wrap.pb5.justify-space-between
3
-    w-tag(v-for="tag in tags")
3
+    w-tag(v-for='tag in tags')
4 4
         p {{ tag }}
5 5
 </template>
6 6
 
@@ -8,7 +8,7 @@ section.w-flex.row.wrap.pb5.justify-space-between
8 8
 export default {
9 9
     props: {
10 10
         tags: {
11
-            required: true,
11
+            required: false,
12 12
             type: Array,
13 13
             default: () => [
14 14
                 'California RN License',
@@ -28,15 +28,15 @@ export default {
28 28
 </script>
29 29
 
30 30
 <style lang="sass">
31
-    section
32
-        min-height: 100%
33
-        .w-tag
34
-            background-color: #F7F5A6
35
-            margin: 3px 0
36
-            p
37
-                color: #183770
38
-                padding: 5px
39
-                font-size: 12px
40
-                font-weight: bolder
41
-                text-align: center
31
+section
32
+    min-height: 100%
33
+    .w-tag
34
+        background-color: #F7F5A6
35
+        margin: 3px 0
36
+        p
37
+            color: #183770
38
+            padding: 5px
39
+            font-size: 12px
40
+            font-weight: bolder
41
+            text-align: center
42 42
 </style>

+ 29
- 3
frontend/src/services/login.service.js Прегледај датотеку

@@ -1,5 +1,7 @@
1 1
 import { ref } from 'vue'
2 2
 import {
3
+    fetchQueueByProfileId,
4
+    updateQueueByProfileId,
3 5
     fetchMembershipsByProfileId,
4 6
     fetchResponsesByProfileId,
5 7
     Chatter,
@@ -20,6 +22,9 @@ class Login {
20 22
 
21 23
         this.groupings = []
22 24
         this.responses = []
25
+
26
+        this.queue = []
27
+        this.responses = []
23 28
         this.tags = []
24 29
 
25 30
         this.toaster = null
@@ -77,6 +82,7 @@ class Login {
77 82
         this.id.value = parseInt(profileId)
78 83
 
79 84
         await this.getGroupings()
85
+        await this.getQueue()
80 86
 
81 87
         await this.setupChatter()
82 88
         this.setupToaster(cb)
@@ -105,7 +111,7 @@ class Login {
105 111
             const tags = []
106 112
             this.setTags(tags)
107 113
         } catch (err) {
108
-            console.error(err)
114
+            console.error(`[Login Service]: ${err}`)
109 115
         }
110 116
     }
111 117
     setTags(tags) {
@@ -117,7 +123,7 @@ class Login {
117 123
             const responseList = await fetchResponsesByProfileId(this.id.value)
118 124
             this.setResponses(responseList)
119 125
         } catch (err) {
120
-            console.error(err)
126
+            console.error(`[Login Service]: ${err}`)
121 127
         }
122 128
     }
123 129
     setResponses(responses) {
@@ -128,9 +134,29 @@ class Login {
128 134
         try {
129 135
             this.groupings = await fetchMembershipsByProfileId(this.id.value)
130 136
         } catch (err) {
131
-            console.error(err)
137
+            console.error(`[Login Service]: ${err}`)
138
+        }
139
+    }
140
+
141
+    async getQueue() {
142
+        try {
143
+            this.queue = await fetchQueueByProfileId(this.id.value)
144
+        } catch (err) {
145
+            console.error(`[Login Service]: ${err}`)
146
+        }
147
+    }
148
+    async updateQueue(profileId, targetId, reinsert) {
149
+        try {
150
+            this.queue = await updateQueueByProfileId(
151
+                profileId,
152
+                targetId,
153
+                reinsert,
154
+            )
155
+        } catch (err) {
156
+            console.error(`[Login Service]: ${err}`)
132 157
         }
133 158
     }
159
+
134 160
     /**
135 161
      * For push notifications and chat
136 162
      */

+ 1
- 3
frontend/src/services/queue.service.js Прегледај датотеку

@@ -8,16 +8,14 @@ import { Profile } from '../entities/index.js'
8 8
  */
9 9
 const fetchQueueByProfileId = async profileId => {
10 10
     let queue
11
-
12 11
     try {
13 12
         queue = await db.get(`/profile/${profileId}/queue?include_profile=true`)
14 13
         if (!queue?.length) {
15
-            throw '[Queue Service]: Could not retrieve match queue. Please take the survey and rescore.'
14
+            throw '[Queue Service]: Could not retrieve match queue.\nHave you taken the survey and scored this profile?'
16 15
         }
17 16
     } catch (err) {
18 17
         console.error(err)
19 18
     }
20
-
21 19
     return queue
22 20
         ? queue.map(profileData => {
23 21
               return new Profile({ email: 'fixme@gmail.com', ...profileData })

+ 30
- 57
frontend/src/views/HomeView.vue Прегледај датотеку

@@ -1,11 +1,14 @@
1 1
 <template lang="pug">
2 2
 main.view--home
3
-    article(v-if='cards.length && !loading')
4
-        ProfileCardList(:cards='cards' :pid='pid' @reload='getCards')
3
+    article.w-flex.column.align-center
4
+        template(v-if='loading')
5
+            w-spinner(bounce)
5 6
 
6
-    p(v-else-if='cards.length === 0') No profiles in match_queue.
7
-    w-spinner(bounce v-else)
7
+        template(v-else-if='!loading && cards.length > 0')
8
+            ProfileCardList(:cards='cards')
8 9
 
10
+        template(v-else-if='cards.length === 0')
11
+            p No profiles in match_queue.
9 12
     MainNav
10 13
 </template>
11 14
 
@@ -19,12 +22,19 @@ import PairingButton from '../components/PairingButton.vue'
19 22
 
20 23
 import { Card } from '../entities'
21 24
 
22
-import {
23
-    currentProfile,
24
-    fetchQueueByProfileId,
25
-    fetchMembershipsByProfileId,
26
-} from '../services'
27
-import { mixins } from '../utils'
25
+import { currentProfile } from '../services'
26
+
27
+const notificationOpts = {
28
+    message: null,
29
+    timeout: 6000,
30
+    bgColor: 'white',
31
+    color: 'success',
32
+    dismiss: false,
33
+    shadow: true,
34
+    round: true,
35
+    sm: true,
36
+    icon: 'wi-star',
37
+}
28 38
 
29 39
 /** Callback used to format incoming into card */
30 40
 const convertToCard = profile => {
@@ -41,20 +51,6 @@ const convertToCard = profile => {
41 51
     })
42 52
 }
43 53
 
44
-const convertGroupingToCard = 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
-
58 54
 export default {
59 55
     name: 'HomeView',
60 56
     components: {
@@ -64,42 +60,19 @@ export default {
64 60
         SummaryBar,
65 61
         PairingButton,
66 62
     },
67
-    mixins: [mixins.cardMixin],
68
-    methods: {
69
-        /** Gets called from cardMixin */
70
-        async getCards() {
71
-            if (!currentProfile.isLoggedIn) {
72
-                console.error(
73
-                    '[Home View]: Profile not logged in or has problem loading',
74
-                )
75
-                console.error('[Home View]: Profile error:', currentProfile)
76
-                return
77
-            }
78
-            this.loading = true
79
-            const pid = currentProfile.id
80
-            try {
81
-                const queueList = await fetchQueueByProfileId(pid)
82
-                this.cards = this._reformat(queueList, convertToCard)
83
-                const matchList = await fetchMembershipsByProfileId(pid)
84
-                this.matches = this._reformat(matchList, convertGroupingToCard)
85
-            } catch (err) {
86
-                console.error(err)
87
-            }
88
-            this.loading = false
63
+    computed: {
64
+        loading() {
65
+            return currentProfile.isLoading
89 66
         },
67
+        cards() {
68
+            return currentProfile.queue.map(qProfile => convertToCard(qProfile))
69
+        },
70
+    },
71
+    methods: {
90 72
         // this can be placed in utils/notification.js
91 73
         notify(payload) {
92
-            this.$waveui.notify({
93
-                message: payload,
94
-                timeout: 6000,
95
-                bgColor: 'white',
96
-                color: 'success',
97
-                dismiss: false,
98
-                shadow: true,
99
-                round: true,
100
-                sm: true,
101
-                icon: 'wi-star',
102
-            })
74
+            notificationOpts.message = payload
75
+            this.$waveui.notify(notificationOpts)
103 76
         },
104 77
     },
105 78
 }

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