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

:recycle: streamlining view loading | removing card mixin | using current profile for load stat

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

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

@@ -0,0 +1,29 @@
1
+<template lang="pug">
2
+.chat-blob.message-wrapper.pa4
3
+    p.pb1
4
+        span(v-if='publisherId == profile.id.value') you
5
+        span(v-else) {{ publisherId }}
6
+        span @{{ new Date(parseInt(time) / 10000).toLocaleTimeString('en-US') }}
7
+    p {{ message }}
8
+</template>
9
+
10
+<script>
11
+import { mixins } from '../utils'
12
+export default {
13
+    props: {
14
+        publisherId: {
15
+            type: String,
16
+            required: true,
17
+        },
18
+        message: {
19
+            type: String,
20
+            required: true,
21
+        },
22
+        time: {
23
+            type: String,
24
+            required: true,
25
+        },
26
+    },
27
+    mixins: [mixins.profileMixin],
28
+}
29
+</script>

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

@@ -107,7 +107,14 @@ const onPair = async () => {
107 107
  * and forward back home
108 108
  */
109 109
 const onPass = async () => {
110
-    currentProfile.updateQueue(currentProfile.id.value, props.card.pid, true)
110
+    currentProfile._loading = true
111
+    await currentProfile.updateQueue(
112
+        currentProfile.id.value,
113
+        props.card.pid,
114
+        true,
115
+    )
116
+    currentProfile._loading = false
117
+
111 118
     let goToRoute = { name: 'HomeView' }
112 119
     router.push(goToRoute)
113 120
 }

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

@@ -139,22 +139,10 @@ class Login {
139 139
     }
140 140
 
141 141
     async getQueue() {
142
-        try {
143
-            this.queue = await fetchQueueByProfileId(this.id.value)
144
-        } catch (err) {
145
-            console.error(`[Login Service]: ${err}`)
146
-        }
142
+        this.queue = await fetchQueueByProfileId(this.id.value)
147 143
     }
148 144
     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}`)
157
-        }
145
+        this.queue = await updateQueueByProfileId(profileId, targetId, reinsert)
158 146
     }
159 147
 
160 148
     /**

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

@@ -31,9 +31,17 @@ const fetchQueueByProfileId = async profileId => {
31 31
  * @returns {array} profiles
32 32
  */
33 33
 const updateQueueByProfileId = async (profileId, targetId, reinsert) => {
34
-    const updateQueue = await db.patch(
35
-        `/profile/${profileId}/queue/${targetId}/delete?include_profile=true&reinsert=${reinsert}`,
36
-    )
34
+    let updateQueue
35
+    try {
36
+        updateQueue = await db.patch(
37
+            `/profile/${profileId}/queue/${targetId}/delete?include_profile=true&reinsert=${reinsert}`,
38
+        )
39
+        if (!updateQueue?.length) {
40
+            throw '[Queue Service]: Could not update match queue.'
41
+        }
42
+    } catch (err) {
43
+        console.error(err)
44
+    }
37 45
     return updateQueue
38 46
         ? updateQueue.map(profileData => {
39 47
               return new Profile({ email: 'fixme@gmail.com', ...profileData })

+ 2
- 2
frontend/src/utils/index.js Прегледај датотеку

@@ -2,7 +2,7 @@ import Joi from 'joi'
2 2
 import { Connector } from './db.js'
3 3
 import { SurveyFactory } from './survey.js'
4 4
 import { possible } from './lang.js'
5
-import { pidMixin, cardMixin } from './mixins.js'
5
+import { pidMixin, profileMixin } from './mixins.js'
6 6
 
7 7
 // This will NOT work until ES2022 gets assert in browsers
8 8
 // import config from '../../../backend/db/data-generator/config.json' assert { type: 'json' }
@@ -46,7 +46,7 @@ const makeKebob = input => {
46 46
 
47 47
 const surveyFactory = new SurveyFactory(possible['usa'])
48 48
 
49
-const mixins = { pidMixin, cardMixin }
49
+const mixins = { pidMixin, profileMixin }
50 50
 
51 51
 const randomNumber = max => {
52 52
     return Math.floor(Math.random() * max) < 1

+ 12
- 16
frontend/src/utils/mixins.js Прегледај датотеку

@@ -1,3 +1,5 @@
1
+import { currentProfile } from '../services'
2
+
1 3
 const pidMixin = {
2 4
     props: {
3 5
         pid: {
@@ -8,23 +10,17 @@ const pidMixin = {
8 10
     },
9 11
 }
10 12
 
11
-const cardMixin = {
12
-    data: () => ({
13
-        cards: [],
14
-        matches: [],
15
-        loading: true,
16
-    }),
17
-    watch: {
18
-        /** Fetch the queue if pid changes */
19
-        pid() {
20
-            this.getCards()
13
+const profileMixin = {
14
+    computed: {
15
+        profile() {
16
+            return currentProfile
21 17
         },
22
-    },
23
-    methods: {
24
-        _reformat(data, mapCb) {
25
-            return data.map(mapCb)
18
+        isLoading() {
19
+            return currentProfile.isLoading
20
+        },
21
+        isLoggedIn() {
22
+            return currentProfile.isLoggedIn
26 23
         },
27 24
     },
28 25
 }
29
-
30
-export { pidMixin, cardMixin }
26
+export { pidMixin, profileMixin }

+ 22
- 20
frontend/src/views/ChatView.vue Прегледај датотеку

@@ -4,24 +4,25 @@ main.view--chat
4 4
         h3 chatting with: {{ target.profile_id }}
5 5
         p subscriptions: {{ profile.chatter.subscriptions }}
6 6
 
7
-    article(v-if='profile.isLoggedIn && target')
8
-        ul#messages.w-flex.column
9
-            template(v-for='chatmessage in messages')
10
-                li(
11
-                    :class='[{ me: chatmessage.publisher == profile.id.value }, chatmessage.publisher]'
12
-                    v-if='chatmessage.message.description'
13
-                )
14
-                    .message-wrapper.pa4
15
-                        p.pb1
16
-                            span(
17
-                                v-if='chatmessage.publisher == profile.id.value'
18
-                            ) you
19
-                            span(v-else) {{ chatmessage.publisher }}
20
-                            span @{{ new Date(parseInt(chatmessage.timetoken) / 10000).toLocaleTimeString('en-US') }}
21
-                        p {{ chatmessage.message.description }}
7
+    article
8
+        template(v-if='isLoading')
9
+            w-spinner(bounce)
22 10
 
23
-    p(v-else-if='profile.isLoggedIn && !target') No match found between profile {{ $route.params.pid }} and {{ profile.id }}...
24
-    w-spinner(bounce v-else)
11
+        template(v-if='!isLoading && target')
12
+            ul#messages.w-flex.column
13
+                template(v-for='chatmessage in messages')
14
+                    li(
15
+                        :class='[{ me: chatmessage.publisher == profile.id.value }, chatmessage.publisher]'
16
+                        v-if='chatmessage.message.description'
17
+                    )
18
+                        ChatBubble(
19
+                            :message='chatmessage.message.description'
20
+                            :publisher-id='chatmessage.publisher'
21
+                            :time='chatmessage.timetoken'
22
+                        )
23
+
24
+        template(v-else-if='!isLoading && !target')
25
+            p No match found between profile {{ $route.params.pid }} and {{ profile.id }}...
25 26
 
26 27
     footer.w-flex.row
27 28
         w-input(@keyup.enter='sendMessage' outline v-model='toSend')
@@ -32,19 +33,20 @@ main.view--chat
32 33
 </template>
33 34
 
34 35
 <script>
36
+import ChatBubble from '../components/ChatBubble.vue'
35 37
 import { currentProfile } from '../services'
38
+import { mixins } from '../utils'
36 39
 
37 40
 export default {
38 41
     name: 'ProfileView',
42
+    components: { ChatBubble },
43
+    mixins: [mixins.profileMixin],
39 44
     data: () => ({
40 45
         target: null,
41 46
         toSend: '',
42 47
         messages: [],
43 48
         openDrawer: null,
44 49
     }),
45
-    computed: {
46
-        profile: () => currentProfile,
47
-    },
48 50
     watch: {
49 51
         profile() {
50 52
             this.loadTargetProfile()

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

@@ -1,10 +1,10 @@
1 1
 <template lang="pug">
2 2
 main.view--home
3 3
     article.w-flex.column.align-center
4
-        template(v-if='loading')
4
+        template(v-if='isLoading')
5 5
             w-spinner(bounce)
6 6
 
7
-        template(v-else-if='!loading && cards.length > 0')
7
+        template(v-else-if='!isLoading && cards.length > 0')
8 8
             ProfileCardList(:cards='cards')
9 9
 
10 10
         template(v-else-if='cards.length === 0')
@@ -23,6 +23,7 @@ import PairingButton from '../components/PairingButton.vue'
23 23
 import { Card } from '../entities'
24 24
 
25 25
 import { currentProfile } from '../services'
26
+import { mixins } from '../utils'
26 27
 
27 28
 const notificationOpts = {
28 29
     message: null,
@@ -60,10 +61,8 @@ export default {
60 61
         SummaryBar,
61 62
         PairingButton,
62 63
     },
64
+    mixins: [mixins.profileMixin],
63 65
     computed: {
64
-        loading() {
65
-            return currentProfile.isLoading
66
-        },
67 66
         cards() {
68 67
             return currentProfile.queue.map(qProfile => convertToCard(qProfile))
69 68
         },

+ 7
- 19
frontend/src/views/MessagesView.vue Прегледај датотеку

@@ -1,36 +1,24 @@
1 1
 <template lang="pug">
2 2
 main.view--messages
3
-    article(v-if="!loading")
4
-        PairsList(:pairs="inboxes")
3
+    article
4
+        template(v-if='!loading')
5
+            w-spinner(bounce)
5 6
 
6
-    w-spinner(v-else bounce)
7
+        template(v-else)
8
+            PairsList(:pairs='inboxes')
7 9
     MainNav
8 10
 </template>
9 11
 
10 12
 <script>
11 13
 import PairsList from '../components/PairsList.vue'
12
-
13
-import { fetchMembershipsByProfileId } from '../services'
14 14
 import { mixins } from '../utils'
15 15
 
16 16
 export default {
17 17
     name: 'MessagesView',
18 18
     components: { PairsList },
19
-    mixins: [mixins.pidMixin, mixins.cardMixin],
19
+    mixins: [mixins.pidMixin, mixins.profileMixin],
20 20
     data: () => ({
21 21
         inboxes: ['x'],
22 22
     }),
23
-    methods: {
24
-        /** Gets called from cardMixin */
25
-        async getCards() {
26
-            this.loading = true
27
-            try {
28
-                this.inboxes = await fetchMembershipsByProfileId(this.pid)
29
-            } catch (err) {
30
-                console.error(err)
31
-            }
32
-            this.loading = false
33
-        },
34
-    },
35 23
 }
36
-</script>
24
+</script>

+ 7
- 9
frontend/src/views/OnboardingView.vue Прегледај датотеку

@@ -49,15 +49,13 @@ export default {
49 49
     components: {
50 50
         ...stepViews,
51 51
     },
52
-    data: () => {
53
-        return {
54
-            answered: {},
55
-            aspectQuestions: [],
56
-            currentStep: 0,
57
-            onboardingStepComponents: [],
58
-            validSurvey: null,
59
-        }
60
-    },
52
+    data: () => ({
53
+        answered: {},
54
+        aspectQuestions: [],
55
+        currentStep: 0,
56
+        onboardingStepComponents: [],
57
+        validSurvey: null,
58
+    }),
61 59
     computed: {
62 60
         onboardingStep() {
63 61
             if (!this.onboardingStepComponents.length) return []

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

@@ -1,17 +1,19 @@
1 1
 <template lang="pug">
2 2
 main.view--pairs
3
-    article(v-if='isLoggedIn')
4
-        w-tabs(:items='tabs' fill-bar slider-color='yellow')
5
-            template(#item-title='{ item }')
6
-                span {{ item.title }}
7
-            //- pending tab
8
-            template(#item-content.1='{ item }')
9
-                PairsList(:pairs='pending' tab-name='pending')
10
-            //- paired tab 
11
-            template(#item-content.2='{ item }')
12
-                PairsList(:pairs='paired' tab-name='paired')
3
+    article
4
+        template(v-if='isLoading')
5
+            w-spinner(bounce)
6
+        template(v-else)
7
+            w-tabs(:items='tabs' fill-bar slider-color='yellow')
8
+                template(#item-title='{ item }')
9
+                    span {{ item.title }}
10
+                //- pending tab
11
+                template(#item-content.1='{ item }')
12
+                    PairsList(:pairs='pending' tab-name='pending')
13
+                //- paired tab 
14
+                template(#item-content.2='{ item }')
15
+                    PairsList(:pairs='paired' tab-name='paired')
13 16
 
14
-    w-spinner(bounce v-else)
15 17
     MainNav
16 18
 </template>
17 19
 
@@ -42,13 +44,11 @@ const convertGroupingToCard = grouping => {
42 44
 export default {
43 45
     name: 'PairsView',
44 46
     components: { PairsList },
47
+    mixins: [mixins.profileMixin],
45 48
     data: () => ({
46 49
         tabs: [{ title: 'Pending' }, { title: 'Paired' }],
47 50
     }),
48 51
     computed: {
49
-        isLoggedIn() {
50
-            return currentProfile.isLoggedIn
51
-        },
52 52
         pending() {
53 53
             if (!this.isLoggedIn || !currentProfile.pendingGroupings) return []
54 54
             return this._reformat(

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