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

: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
 <template lang="pug">
1
 <template lang="pug">
2
 w-app
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
         header
4
         header
5
-            h2 home - profile: {{ getPid }}
5
+            h2 current - profile: {{ profile.id }}
6
         w-drawer(v-model="openDrawer")
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
         w-button(@click="openDrawer = true" outline="")
8
         w-button(@click="openDrawer = true" outline="")
13
             | Active Chats
9
             | Active Chats
10
+
14
     RouterView(
11
     RouterView(
15
-        v-if="isLoggedIn"
16
-        :pid="getPid"
12
+        v-if="profile.isLoggedIn"
13
+        :pid="profile.id.value"
17
         @updatePid="setPid"
14
         @updatePid="setPid"
18
         @show-sidebar="showSidebar = !showSidebar"
15
         @show-sidebar="showSidebar = !showSidebar"
19
     )
16
     )
32
 export default {
29
 export default {
33
     components: { SideBar },
30
     components: { SideBar },
34
     data: () => ({
31
     data: () => ({
35
-        showSidebar: false,
36
         sliderVal: 1,
32
         sliderVal: 1,
37
         openDrawer: false,
33
         openDrawer: false,
38
     }),
34
     }),
39
     computed: {
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
     async created() {
40
     async created() {
54
          * using the login form
47
          * using the login form
55
          */
48
          */
56
         if (DEV_MODE) {
49
         if (DEV_MODE) {
57
-            this.setPid(DEV_PID)
50
+            await this.setPid(DEV_PID)
58
         }
51
         }
59
     },
52
     },
60
     methods: {
53
     methods: {
68
             }
61
             }
69
             await currentProfile.login(profileId, this.$waveui.notify)
62
             await currentProfile.login(profileId, this.$waveui.notify)
70
             console.log('---')
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
 .sidebar--messages
2
 .sidebar--messages
3
   h5.message__title messages from matches
3
   h5.message__title messages from matches
4
   router-link(
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
     .message__right
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
 </template>
14
 </template>
15
 
15
 
16
 <script>
16
 <script>

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

1
 <template lang="pug">
1
 <template lang="pug">
2
 aside.sidebar
2
 aside.sidebar
3
+    p(v-if="profile.isLoggedIn") chans: {{profile.groupings}}
3
     .temp-control-box
4
     .temp-control-box
4
         input(v-model="switchToPID" @keyup.enter="$emit('updatePid', switchToPID)")
5
         input(v-model="switchToPID" @keyup.enter="$emit('updatePid', switchToPID)")
5
         button(@click="$emit('updatePid', switchToPID)") switch profile
6
         button(@click="$emit('updatePid', switchToPID)") switch profile
8
 </template>
9
 </template>
9
 
10
 
10
 <script>
11
 <script>
12
+import { currentProfile } from '../services'
11
 import Messages from './Messages.vue'
13
 import Messages from './Messages.vue'
12
 import { mixins } from '../utils'
14
 import { mixins } from '../utils'
13
 
15
 
16
     mixins: [mixins.pidMixin],
18
     mixins: [mixins.pidMixin],
17
     data: () => ({
19
     data: () => ({
18
         switchToPID: null,
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
     mounted() {
27
     mounted() {
35
         // Set the form to display the default pid set in Home.vue
28
         // Set the form to display the default pid set in Home.vue
36
         this.switchToPID = this.pid
29
         this.switchToPID = this.pid

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

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

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

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

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

3
         pid: {
3
         pid: {
4
             type: Number,
4
             type: Number,
5
             required: true,
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
 const cardMixin = {
11
 const cardMixin = {
16
     }),
16
     }),
17
     watch: {
17
     watch: {
18
         /** Fetch the queue if pid changes */
18
         /** Fetch the queue if pid changes */
19
-        pid() { this.getCards() },
19
+        pid() {
20
+            this.getCards()
21
+        },
20
     },
22
     },
21
     async created() {
23
     async created() {
22
         await this.getCards()
24
         await this.getCards()
24
     methods: {
26
     methods: {
25
         _reformat(data, mapCb) {
27
         _reformat(data, mapCb) {
26
             return data.map(mapCb)
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
     header 
3
     header 
4
         h2 Chat Page
4
         h2 Chat Page
5
  
5
  
6
-    article(v-if="!loading")
6
+    article(v-if="!loading && target && profile.isLoggedIn")
7
         h3 {{ profile.id }} 
7
         h3 {{ profile.id }} 
8
             span chatting with: {{ target.profile_id }}
8
             span chatting with: {{ target.profile_id }}
9
         p subscriptions: {{ profile.chatter.subscriptions }}
9
         p subscriptions: {{ profile.chatter.subscriptions }}
10
+    
10
     p(v-else) Loading...
11
     p(v-else) Loading...
11
 
12
 
12
     MainNav(@show-sidebar="$emit('show-sidebar')")
13
     MainNav(@show-sidebar="$emit('show-sidebar')")
20
     data: () => ({
21
     data: () => ({
21
         loading: true,
22
         loading: true,
22
         target: {},
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
     methods: {
37
     methods: {
29
-        async getProfile() {
38
+        async loadTargetProfile() {
30
             this.loading = true
39
             this.loading = true
31
             try {
40
             try {
32
                 this.target = await fetchProfileByProfileId(
41
                 this.target = await fetchProfileByProfileId(

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