Просмотр исходного кода

:recycle: using groupings to create matches list | cleaning up login conditions to better display subscriptions | tracking groupings on login state

tags/0.0.1^2
J 3 лет назад
Родитель
Сommit
29538010c9

+ 9
- 19
frontend/src/App.vue Просмотреть файл

@@ -1,19 +1,16 @@
1 1
 <template lang="pug">
2 2
 w-app
3
-    div.nav(v-if="isLoggedIn" style="display: flex; justify-content: space-between;")
3
+    .nav(v-if="profile.isLoggedIn" style="display: flex; justify-content: space-between;")
4 4
         header
5
-            h2 home - profile: {{ getPid }}
5
+            h2 current - profile: {{ profile.id }}
6 6
         w-drawer(v-model="openDrawer")
7
-            SideBar(
8
-                :pid="getPid"
9
-                @updatePid="setPid"
10
-                @hide="showSidebar = false"
11
-            )
7
+            SideBar(@updatePid="setPid" :pid="profile.id.value")
12 8
         w-button(@click="openDrawer = true" outline="")
13 9
             | Active Chats
10
+
14 11
     RouterView(
15
-        v-if="isLoggedIn"
16
-        :pid="getPid"
12
+        v-if="profile.isLoggedIn"
13
+        :pid="profile.id.value"
17 14
         @updatePid="setPid"
18 15
         @show-sidebar="showSidebar = !showSidebar"
19 16
     )
@@ -32,16 +29,12 @@ const DEV_PID = 45
32 29
 export default {
33 30
     components: { SideBar },
34 31
     data: () => ({
35
-        showSidebar: false,
36 32
         sliderVal: 1,
37 33
         openDrawer: false,
38 34
     }),
39 35
     computed: {
40
-        getPid: () => {
41
-            return currentProfile.id.value ? currentProfile.id.value : null
42
-        },
43
-        isLoggedIn: () => {
44
-            return currentProfile.isLoggedIn
36
+        profile: () => {
37
+            return currentProfile
45 38
         },
46 39
     },
47 40
     async created() {
@@ -54,7 +47,7 @@ export default {
54 47
          * using the login form
55 48
          */
56 49
         if (DEV_MODE) {
57
-            this.setPid(DEV_PID)
50
+            await this.setPid(DEV_PID)
58 51
         }
59 52
     },
60 53
     methods: {
@@ -68,9 +61,6 @@ export default {
68 61
             }
69 62
             await currentProfile.login(profileId, this.$waveui.notify)
70 63
             console.log('---')
71
-            //  step 3: subscribe to the this.subscriptions array
72
-            // view current subscriptions on the currentProfile.chatter.subscriptions
73
-            console.log('subscriptions', currentProfile.chatter.subscriptions)
74 64
         },
75 65
     },
76 66
 }

+ 7
- 7
frontend/src/components/Messages.vue Просмотреть файл

@@ -2,15 +2,15 @@
2 2
 .sidebar--messages
3 3
   h5.message__title messages from matches
4 4
   router-link(
5
-        :to="`/chats/${profile.profile_id}`" 
6
-        v-for='profile in matches' 
7
-        :key='profile.profile_id' 
8
-        :class="[pid == profile.profile_id ? 'active' : '', 'sidebar__message', 'f-col', 'start']"
5
+        :to="`/chats/${match.profile.profile_id}`" 
6
+        v-for='match in matches' 
7
+        :key='match.profile.profile_id' 
8
+        :class="[pid == match.profile.profile_id ? 'active' : '', 'sidebar__message', 'f-col', 'start']"
9 9
     )
10
-    img(:src='profile.avatar' style="max-height:100px")
10
+    img(:src='match.profile.avatar' style="max-height:100px")
11 11
     .message__right
12
-        h4.message__name {{ profile.name }}
13
-        p.message__content {{ profile.metadata.rawMetadata || &quot;Hello I&apos;m using tinder!&quot; }}
12
+        h4.message__name {{ match.profile.name }}
13
+        p.message__content {{ match.profile }}
14 14
 </template>
15 15
 
16 16
 <script>

+ 7
- 14
frontend/src/components/SideBar.vue Просмотреть файл

@@ -1,5 +1,6 @@
1 1
 <template lang="pug">
2 2
 aside.sidebar
3
+    p(v-if="profile.isLoggedIn") chans: {{profile.groupings}}
3 4
     .temp-control-box
4 5
         input(v-model="switchToPID" @keyup.enter="$emit('updatePid', switchToPID)")
5 6
         button(@click="$emit('updatePid', switchToPID)") switch profile
@@ -8,6 +9,7 @@ aside.sidebar
8 9
 </template>
9 10
 
10 11
 <script>
12
+import { currentProfile } from '../services'
11 13
 import Messages from './Messages.vue'
12 14
 import { mixins } from '../utils'
13 15
 
@@ -16,21 +18,12 @@ export default {
16 18
     mixins: [mixins.pidMixin],
17 19
     data: () => ({
18 20
         switchToPID: null,
19
-        matches: [
20
-            {
21
-                name: 'Bob McRob',
22
-                profile_id: 111,
23
-                avatar: 'https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/newborn-baby-boy-sleeping-peacefully-wearing-knit-royalty-free-image-1589459736.jpg?crop=0.669xw:1.00xh;0.228xw,0&resize=640:*',
24
-                metadata: { rawMetadata: 'howdy howdy howdy' },
25
-            },
26
-            {
27
-                name: 'Rob Bebob',
28
-                profile_id: 112,
29
-                avatar: 'https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/newborn-baby-boy-sleeping-peacefully-wearing-knit-royalty-free-image-1589459736.jpg?crop=0.669xw:1.00xh;0.228xw,0&resize=640:*',
30
-                metadata: { rawMetadata: 'this is the last message' },
31
-            },
32
-        ],
33 21
     }),
22
+    computed: {
23
+        profile: () => currentProfile,
24
+        matches: () =>
25
+            currentProfile.groupings.filter(g => g.grouping_type == 'match'),
26
+    },
34 27
     mounted() {
35 28
         // Set the form to display the default pid set in Home.vue
36 29
         this.switchToPID = this.pid

+ 6
- 8
frontend/src/services/chat.service.js Просмотреть файл

@@ -1,8 +1,5 @@
1 1
 import PubNub from 'pubnub'
2 2
 
3
-// custom services
4
-import { fetchMembershipsByProfileId } from '../services/grouping.service'
5
-
6 3
 /**
7 4
  * Provider method holder
8 5
  * We always reference this object so
@@ -91,15 +88,16 @@ class Chatter {
91 88
     async _onPresence(e) {
92 89
         return
93 90
     }
94
-    async setup(uuid) {
91
+    async setup(uuid, groupings) {
95 92
         this.uuid = `${uuid}`
96 93
         this.provider = await setupPubnub(this.uuid)
97 94
 
98 95
         //  step 1: build the this.groupings object from the backend
99 96
         // ? .await for the groupings to be fetched before subscribing to channels
100
-        await this._setupAllChannels(this.uuid)
97
+        await this._setupAllChannels(groupings)
101 98
         this._listenFor({ listeners: this.listeners })
102 99
         this.subscribe({ channels: this.subscriptions })
100
+        return this.subscriptions
103 101
     }
104 102
     /**
105 103
      * Send a message to a channel
@@ -130,14 +128,14 @@ class Chatter {
130 128
     }
131 129
     //  step 2: build the this.subscriptions array from the this.groupings object
132 130
     // fetch all groupings for this profile and then store them in the chatter groupings object for reference
133
-    async _setupAllChannels(profileId) {
134
-        const groupings = await fetchMembershipsByProfileId(profileId)
135
-        console.log(`fetched groupings for profileId: ${profileId}`, groupings)
131
+    async _setupAllChannels(groupings) {
132
+        console.log(`fetched groupings for profileId: ${this.uusid}`, groupings)
136 133
         groupings.forEach(grouping => {
137 134
             this.subscriptions.push(grouping.grouping_name)
138 135
         })
139 136
     }
140 137
     stop() {
138
+        this.subscriptions = [MAIN_CHANNEL]
141 139
         console.warn('chatter stop no implemented')
142 140
     }
143 141
 }

+ 28
- 11
frontend/src/services/login.service.js Просмотреть файл

@@ -1,19 +1,24 @@
1 1
 import { ref } from 'vue'
2
-import { fetchResponsesByProfileId, Chatter, StonkAlert } from '../services'
2
+import {
3
+    fetchMembershipsByProfileId,
4
+    fetchResponsesByProfileId,
5
+    Chatter,
6
+    StonkAlert,
7
+} from '../services'
3 8
 import { surveyFactory } from '../utils'
4 9
 
5
-
6 10
 /**
7 11
  * Logged in profile state manager
8 12
  * Sort of a util and service hybrid
9 13
  */
10 14
 class Login {
11 15
     constructor() {
12
-        this._loading = false
16
+        this._loading = ref(true)
13 17
 
14 18
         // Make reactive with vue observer
15 19
         this.id = ref(null)
16 20
 
21
+        this.groupings = []
17 22
         this.responses = []
18 23
         this.tags = []
19 24
 
@@ -21,7 +26,7 @@ class Login {
21 26
         this.chatter = null
22 27
     }
23 28
     get isLoading() {
24
-        return this._loading
29
+        return this._loading.value
25 30
     }
26 31
     /**
27 32
      * Track login separate from complete-ess
@@ -30,7 +35,7 @@ class Login {
30 35
      * @returns {boolean}
31 36
      */
32 37
     get isLoggedIn() {
33
-        return this.id.value != null
38
+        return this.id.value != null && this.isLoading == false
34 39
     }
35 40
     /**
36 41
      * Combine questions retrieved from the database and
@@ -58,12 +63,18 @@ class Login {
58 63
      * @returns {number} stored reactive id
59 64
      */
60 65
     async login(profileId, cb) {
66
+        this._loading.value = true
67
+
61 68
         console.warn('logging in:', profileId)
62 69
         this.id.value = parseInt(profileId)
63 70
 
64
-        this.setupChatter()
71
+        await this.getGroupings()
72
+
73
+        await this.setupChatter()
65 74
         this.setupToaster(cb)
66 75
 
76
+        this._loading.value = false
77
+        console.warn('logged in:', this.isLoggedIn)
67 78
         return this.id.value
68 79
     }
69 80
     logout() {
@@ -91,7 +102,7 @@ class Login {
91 102
 
92 103
     async getResponses() {
93 104
         try {
94
-            const responseList = await fetchResponsesByProfileId(this.id)
105
+            const responseList = await fetchResponsesByProfileId(this.id.value)
95 106
             this.setResponses(responseList)
96 107
         } catch (err) {
97 108
             console.error(err)
@@ -100,20 +111,26 @@ class Login {
100 111
     setResponses(responses) {
101 112
         this.responses = responses
102 113
     }
114
+
115
+    async getGroupings() {
116
+        try {
117
+            this.groupings = await fetchMembershipsByProfileId(this.id.value)
118
+        } catch (err) {
119
+            console.error(err)
120
+        }
121
+    }
103 122
     /**
104 123
      * For push notifications and chat
105 124
      */
106 125
     setupToaster(waveCb) {
107 126
         this.toaster = new StonkAlert(this.id.value, waveCb)
108 127
     }
109
-    setupChatter() {
128
+    async setupChatter() {
110 129
         this.chatter = new Chatter()
111 130
         // Use the reactive id object
112 131
         const testAccountUUID = this.id.value
113
-        this.chatter.setup(testAccountUUID)
132
+        await this.chatter.setup(testAccountUUID, this.groupings)
114 133
     }
115
-
116
-    
117 134
 }
118 135
 
119 136
 const currentProfile = new Login()

+ 8
- 6
frontend/src/utils/mixins.js Просмотреть файл

@@ -3,9 +3,9 @@ const pidMixin = {
3 3
         pid: {
4 4
             type: Number,
5 5
             required: true,
6
-            validator: prop => typeof prop === 'number' || prop === null
6
+            validator: prop => typeof prop === 'number' || prop === null,
7 7
         },
8
-    }
8
+    },
9 9
 }
10 10
 
11 11
 const cardMixin = {
@@ -16,7 +16,9 @@ const cardMixin = {
16 16
     }),
17 17
     watch: {
18 18
         /** Fetch the queue if pid changes */
19
-        pid() { this.getCards() },
19
+        pid() {
20
+            this.getCards()
21
+        },
20 22
     },
21 23
     async created() {
22 24
         await this.getCards()
@@ -24,8 +26,8 @@ const cardMixin = {
24 26
     methods: {
25 27
         _reformat(data, mapCb) {
26 28
             return data.map(mapCb)
27
-        }
28
-    }
29
+        },
30
+    },
29 31
 }
30 32
 
31
-export { pidMixin, cardMixin }
33
+export { pidMixin, cardMixin }

+ 14
- 5
frontend/src/views/ChatView.vue Просмотреть файл

@@ -3,10 +3,11 @@ main.view--chat.f-col.start.w-full
3 3
     header 
4 4
         h2 Chat Page
5 5
  
6
-    article(v-if="!loading")
6
+    article(v-if="!loading && target && profile.isLoggedIn")
7 7
         h3 {{ profile.id }} 
8 8
             span chatting with: {{ target.profile_id }}
9 9
         p subscriptions: {{ profile.chatter.subscriptions }}
10
+    
10 11
     p(v-else) Loading...
11 12
 
12 13
     MainNav(@show-sidebar="$emit('show-sidebar')")
@@ -20,13 +21,21 @@ export default {
20 21
     data: () => ({
21 22
         loading: true,
22 23
         target: {},
23
-        profile: currentProfile,
24 24
     }),
25
-    created() {
26
-        this.getProfile()
25
+    computed: {
26
+        profile: () => currentProfile,
27
+    },
28
+    watch: {
29
+        async profile() {
30
+            await this.loadTargetProfile(this.$route.params.tid)
31
+            console.log('target :>> ', this.$route.params.tid)
32
+        },
33
+    },
34
+    async created() {
35
+        await this.loadTargetProfile()
27 36
     },
28 37
     methods: {
29
-        async getProfile() {
38
+        async loadTargetProfile() {
30 39
             this.loading = true
31 40
             try {
32 41
                 this.target = await fetchProfileByProfileId(

Загрузка…
Отмена
Сохранить