Explorar el Código

:recycle: making tag list reactive

tags/0.0.3^2
j hace 3 años
padre
commit
2ad4d6d89a

+ 22
- 1
frontend/src/entities/grouping/grouping.js Ver fichero

@@ -1,5 +1,6 @@
1 1
 /** @module entities/grouping */
2 2
 
3
+import { ref } from 'vue'
3 4
 import { _baseRecord } from '../index.js'
4 5
 import { groupingSchema } from './grouping.schema.js'
5 6
 import { revealProfileInfo } from '../../services/profile.service.js'
@@ -14,6 +15,7 @@ class Grouping extends _baseRecord {
14 15
      */
15 16
     constructor({ ...membership }) {
16 17
         super()
18
+        this._loading = ref(true)
17 19
 
18 20
         this.type = this.constructor.name.toLowerCase()
19 21
         this.tags = []
@@ -41,7 +43,26 @@ class Grouping extends _baseRecord {
41 43
         return [this.profile.profile_id]
42 44
     }
43 45
     async reveal(profileId, tagId) {
44
-        return await revealProfileInfo(this.grouping_id, profileId, tagId)
46
+        console.log('[Grouping Entity log]: Attempting to reveal...', tagId)
47
+        this._loading.value = true
48
+        try {
49
+            const revealed = await revealProfileInfo(
50
+                this.grouping_id,
51
+                profileId,
52
+                tagId,
53
+            )
54
+            if (!revealed.tags) {
55
+                throw `[Grouping Entity error]: Could not reveal ${tagId} for ${profileId}`
56
+            }
57
+            // Overwrite with new revealed tags completely
58
+            const toKeep = this.tags.filter(
59
+                assoc => assoc.profile_id != profileId,
60
+            )
61
+            this.tags = [...toKeep, ...revealed.tags]
62
+        } catch (err) {
63
+            console.error(err)
64
+        }
65
+        this._loading.value = false
45 66
     }
46 67
     /**
47 68
      * validate this record

+ 3
- 0
frontend/src/entities/grouping/grouping.schema.js Ver fichero

@@ -10,6 +10,9 @@ import Joi from 'joi'
10 10
 const groupingSchema = {
11 11
     type: 'object',
12 12
     properties: Joi.object().keys({
13
+        /** for vue reactivity */
14
+        _loading: Joi.object(),
15
+
13 16
         /** _baseRecord fields */
14 17
         createdAt: Joi.string(),
15 18
         _id: Joi.string(),

+ 1
- 1
frontend/src/services/grouping.service.js Ver fichero

@@ -25,7 +25,7 @@ const fetchMembershipsByProfileId = async profileId => {
25 25
                     `/profile/${profileId}/tags/${grouping.grouping_id}`,
26 26
                 )
27 27
                 grouping.tags = [...targetTags, ...profileTags]
28
-                console.log('grouping.tags :>> ', grouping.tags)
28
+                grouping._loading.value = false
29 29
                 validGroupingInstances.push(grouping)
30 30
             }
31 31
         }

+ 6
- 16
frontend/src/views/ChatView.vue Ver fichero

@@ -4,8 +4,9 @@ main.view--chat
4 4
         h3 chatting with: {{ target.profile_id }}
5 5
         p {{ grouping.profile.user_name }}
6 6
         p {{ grouping.profile.user_email }}
7
-        p {{ grouping.profile }}
7
+        p(v-if='!grouping._loading') {{ grouping.revealed }}
8 8
         //- p subscriptions: {{ profile.chatter.subscriptions }}
9
+
9 10
         .w-flex.column
10 11
             p reveal: {{ grouping.revealed }}
11 12
             .w-flex.row
@@ -54,16 +55,8 @@ export default {
54 55
         toSend: '',
55 56
         messages: [],
56 57
         openDrawer: null,
58
+        grouping: null,
57 59
     }),
58
-    computed: {
59
-        grouping() {
60
-            return this.profile.groupings.find(profileGrouping =>
61
-                profileGrouping.participants.includes(
62
-                    parseInt(this.$route.params.pid),
63
-                ),
64
-            )
65
-        },
66
-    },
67 60
     watch: {
68 61
         profile() {
69 62
             this.loadTargetProfile()
@@ -73,15 +66,12 @@ export default {
73 66
     created() {
74 67
         this.loadTargetProfile()
75 68
         currentProfile.chatter.setOnMessage(this._onMessage)
69
+        this.grouping = this.getGrouping()
76 70
     },
77 71
     methods: {
78 72
         async reveal(tagId) {
79
-            console.log('trying to reveal')
80
-            const thing = await this.grouping.reveal(
81
-                currentProfile.id.value,
82
-                tagId,
83
-            )
84
-            console.log('thing :>> ', thing)
73
+            const grouping = this.getGrouping()
74
+            await grouping.reveal(currentProfile.id.value, tagId)
85 75
         },
86 76
         /**
87 77
          * Pubnub message callback fires when message event

Loading…
Cancelar
Guardar