Kaynağa Gözat

:recycle: making tag list reactive

tags/0.0.3^2
j 3 yıl önce
ebeveyn
işleme
2ad4d6d89a

+ 22
- 1
frontend/src/entities/grouping/grouping.js Dosyayı Görüntüle

1
 /** @module entities/grouping */
1
 /** @module entities/grouping */
2
 
2
 
3
+import { ref } from 'vue'
3
 import { _baseRecord } from '../index.js'
4
 import { _baseRecord } from '../index.js'
4
 import { groupingSchema } from './grouping.schema.js'
5
 import { groupingSchema } from './grouping.schema.js'
5
 import { revealProfileInfo } from '../../services/profile.service.js'
6
 import { revealProfileInfo } from '../../services/profile.service.js'
14
      */
15
      */
15
     constructor({ ...membership }) {
16
     constructor({ ...membership }) {
16
         super()
17
         super()
18
+        this._loading = ref(true)
17
 
19
 
18
         this.type = this.constructor.name.toLowerCase()
20
         this.type = this.constructor.name.toLowerCase()
19
         this.tags = []
21
         this.tags = []
41
         return [this.profile.profile_id]
43
         return [this.profile.profile_id]
42
     }
44
     }
43
     async reveal(profileId, tagId) {
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
      * validate this record
68
      * validate this record

+ 3
- 0
frontend/src/entities/grouping/grouping.schema.js Dosyayı Görüntüle

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

+ 1
- 1
frontend/src/services/grouping.service.js Dosyayı Görüntüle

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

+ 6
- 16
frontend/src/views/ChatView.vue Dosyayı Görüntüle

4
         h3 chatting with: {{ target.profile_id }}
4
         h3 chatting with: {{ target.profile_id }}
5
         p {{ grouping.profile.user_name }}
5
         p {{ grouping.profile.user_name }}
6
         p {{ grouping.profile.user_email }}
6
         p {{ grouping.profile.user_email }}
7
-        p {{ grouping.profile }}
7
+        p(v-if='!grouping._loading') {{ grouping.revealed }}
8
         //- p subscriptions: {{ profile.chatter.subscriptions }}
8
         //- p subscriptions: {{ profile.chatter.subscriptions }}
9
+
9
         .w-flex.column
10
         .w-flex.column
10
             p reveal: {{ grouping.revealed }}
11
             p reveal: {{ grouping.revealed }}
11
             .w-flex.row
12
             .w-flex.row
54
         toSend: '',
55
         toSend: '',
55
         messages: [],
56
         messages: [],
56
         openDrawer: null,
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
     watch: {
60
     watch: {
68
         profile() {
61
         profile() {
69
             this.loadTargetProfile()
62
             this.loadTargetProfile()
73
     created() {
66
     created() {
74
         this.loadTargetProfile()
67
         this.loadTargetProfile()
75
         currentProfile.chatter.setOnMessage(this._onMessage)
68
         currentProfile.chatter.setOnMessage(this._onMessage)
69
+        this.grouping = this.getGrouping()
76
     },
70
     },
77
     methods: {
71
     methods: {
78
         async reveal(tagId) {
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
          * Pubnub message callback fires when message event
77
          * Pubnub message callback fires when message event

Loading…
İptal
Kaydet