Procházet zdrojové kódy

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

tags/0.0.3^2
j před 3 roky
rodič
revize
571ea56f55

+ 29
- 0
frontend/src/components/ChatBubble.vue Zobrazit soubor

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 Zobrazit soubor

107
  * and forward back home
107
  * and forward back home
108
  */
108
  */
109
 const onPass = async () => {
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
     let goToRoute = { name: 'HomeView' }
118
     let goToRoute = { name: 'HomeView' }
112
     router.push(goToRoute)
119
     router.push(goToRoute)
113
 }
120
 }

+ 2
- 14
frontend/src/services/login.service.js Zobrazit soubor

139
     }
139
     }
140
 
140
 
141
     async getQueue() {
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
     async updateQueue(profileId, targetId, reinsert) {
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 Zobrazit soubor

31
  * @returns {array} profiles
31
  * @returns {array} profiles
32
  */
32
  */
33
 const updateQueueByProfileId = async (profileId, targetId, reinsert) => {
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
     return updateQueue
45
     return updateQueue
38
         ? updateQueue.map(profileData => {
46
         ? updateQueue.map(profileData => {
39
               return new Profile({ email: 'fixme@gmail.com', ...profileData })
47
               return new Profile({ email: 'fixme@gmail.com', ...profileData })

+ 2
- 2
frontend/src/utils/index.js Zobrazit soubor

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

+ 12
- 16
frontend/src/utils/mixins.js Zobrazit soubor

1
+import { currentProfile } from '../services'
2
+
1
 const pidMixin = {
3
 const pidMixin = {
2
     props: {
4
     props: {
3
         pid: {
5
         pid: {
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 Zobrazit soubor

4
         h3 chatting with: {{ target.profile_id }}
4
         h3 chatting with: {{ target.profile_id }}
5
         p subscriptions: {{ profile.chatter.subscriptions }}
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
     footer.w-flex.row
27
     footer.w-flex.row
27
         w-input(@keyup.enter='sendMessage' outline v-model='toSend')
28
         w-input(@keyup.enter='sendMessage' outline v-model='toSend')
32
 </template>
33
 </template>
33
 
34
 
34
 <script>
35
 <script>
36
+import ChatBubble from '../components/ChatBubble.vue'
35
 import { currentProfile } from '../services'
37
 import { currentProfile } from '../services'
38
+import { mixins } from '../utils'
36
 
39
 
37
 export default {
40
 export default {
38
     name: 'ProfileView',
41
     name: 'ProfileView',
42
+    components: { ChatBubble },
43
+    mixins: [mixins.profileMixin],
39
     data: () => ({
44
     data: () => ({
40
         target: null,
45
         target: null,
41
         toSend: '',
46
         toSend: '',
42
         messages: [],
47
         messages: [],
43
         openDrawer: null,
48
         openDrawer: null,
44
     }),
49
     }),
45
-    computed: {
46
-        profile: () => currentProfile,
47
-    },
48
     watch: {
50
     watch: {
49
         profile() {
51
         profile() {
50
             this.loadTargetProfile()
52
             this.loadTargetProfile()

+ 4
- 5
frontend/src/views/HomeView.vue Zobrazit soubor

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

+ 7
- 19
frontend/src/views/MessagesView.vue Zobrazit soubor

1
 <template lang="pug">
1
 <template lang="pug">
2
 main.view--messages
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
     MainNav
9
     MainNav
8
 </template>
10
 </template>
9
 
11
 
10
 <script>
12
 <script>
11
 import PairsList from '../components/PairsList.vue'
13
 import PairsList from '../components/PairsList.vue'
12
-
13
-import { fetchMembershipsByProfileId } from '../services'
14
 import { mixins } from '../utils'
14
 import { mixins } from '../utils'
15
 
15
 
16
 export default {
16
 export default {
17
     name: 'MessagesView',
17
     name: 'MessagesView',
18
     components: { PairsList },
18
     components: { PairsList },
19
-    mixins: [mixins.pidMixin, mixins.cardMixin],
19
+    mixins: [mixins.pidMixin, mixins.profileMixin],
20
     data: () => ({
20
     data: () => ({
21
         inboxes: ['x'],
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 Zobrazit soubor

49
     components: {
49
     components: {
50
         ...stepViews,
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
     computed: {
59
     computed: {
62
         onboardingStep() {
60
         onboardingStep() {
63
             if (!this.onboardingStepComponents.length) return []
61
             if (!this.onboardingStepComponents.length) return []

+ 14
- 14
frontend/src/views/PairsView.vue Zobrazit soubor

1
 <template lang="pug">
1
 <template lang="pug">
2
 main.view--pairs
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
     MainNav
17
     MainNav
16
 </template>
18
 </template>
17
 
19
 
42
 export default {
44
 export default {
43
     name: 'PairsView',
45
     name: 'PairsView',
44
     components: { PairsList },
46
     components: { PairsList },
47
+    mixins: [mixins.profileMixin],
45
     data: () => ({
48
     data: () => ({
46
         tabs: [{ title: 'Pending' }, { title: 'Paired' }],
49
         tabs: [{ title: 'Pending' }, { title: 'Paired' }],
47
     }),
50
     }),
48
     computed: {
51
     computed: {
49
-        isLoggedIn() {
50
-            return currentProfile.isLoggedIn
51
-        },
52
         pending() {
52
         pending() {
53
             if (!this.isLoggedIn || !currentProfile.pendingGroupings) return []
53
             if (!this.isLoggedIn || !currentProfile.pendingGroupings) return []
54
             return this._reformat(
54
             return this._reformat(

Načítá se…
Zrušit
Uložit