Parcourir la source

:recycle: unifying current profile | making tags return on queue update | better frontend user simulation

tags/0.0.1
J il y a 4 ans
Parent
révision
727349d21a

+ 2
- 3
backend/lib/routes/profile/patch-queue.js Voir le fichier

18
         Joi.alternatives().try(
18
         Joi.alternatives().try(
19
             Joi.number(),
19
             Joi.number(),
20
             Joi.object({
20
             Joi.object({
21
-                // ORIGINAL
22
                 profile_id: Joi.number(),
21
                 profile_id: Joi.number(),
23
                 user_id: Joi.number(),
22
                 user_id: Joi.number(),
24
-                // Added user_name, user_media to account for updated CompleteProfile
25
                 user_name: Joi.string(),
23
                 user_name: Joi.string(),
26
-                user_media: Joi.string(),
27
                 responses: Joi.array().items(),
24
                 responses: Joi.array().items(),
25
+                tags: Joi.array().items(),
26
+                user_media: Joi.string(),
28
                 user_type: Joi.any(),
27
                 user_type: Joi.any(),
29
             }),
28
             }),
30
         ),
29
         ),

+ 8
- 3
frontend/src/components/MainNav.vue Voir le fichier

1
 <template lang="pug">
1
 <template lang="pug">
2
 nav#main-header.w-full.f-row.around.p-2
2
 nav#main-header.w-full.f-row.around.p-2
3
-    router-link.header__icon.mobile--only(to='/matches') matches
3
+    router-link.header__icon.mobile--only(:to="`/matches?pid=${pid}`") {{pid}} matches
4
     router-link.header__icon(to='/') home
4
     router-link.header__icon(to='/') home
5
-    router-link.header__icon.mobile--only(to='/profile') profile
6
-    router-link.header__icon.mobile--only(to='/survey') survey
5
+    router-link.header__icon.mobile--only(:to="`/profile?pid=${pid}`") {{pid}} profile
6
+    router-link.header__icon.mobile--only(:to="`/survey?pid=${pid}`") {{pid}} survey
7
 </template>
7
 </template>
8
 
8
 
9
 <script>
9
 <script>
10
 export default {
10
 export default {
11
     name: 'MainNav',
11
     name: 'MainNav',
12
+    props: {
13
+        pid: {
14
+            required: true
15
+        }
16
+    }
12
 }
17
 }
13
 </script>
18
 </script>
14
 
19
 

+ 4
- 9
frontend/src/components/ProfileCardList.vue Voir le fichier

23
 </template>
23
 </template>
24
 
24
 
25
 <script setup>
25
 <script setup>
26
+import { onMounted } from '@vue/runtime-core';
26
 import { computed, defineProps, defineEmits } from 'vue'
27
 import { computed, defineProps, defineEmits } from 'vue'
27
 import { updateQueueByProfileId, fetchMembershipsByProfileId, postMembershipByProfileId } from '../services'
28
 import { updateQueueByProfileId, fetchMembershipsByProfileId, postMembershipByProfileId } from '../services'
28
 
29
 
29
-const emit = defineEmits(['reloadQueue'])
30
+const emit = defineEmits(['reload-queue'])
30
 // TODO: Please review this conversion from script to script setup
31
 // TODO: Please review this conversion from script to script setup
31
 // converted from the props section
32
 // converted from the props section
32
 const props = defineProps({
33
 const props = defineProps({
85
         console.log('Make membership')
86
         console.log('Make membership')
86
         postMembershipByProfileId({ profileId, targetId })
87
         postMembershipByProfileId({ profileId, targetId })
87
     }
88
     }
88
-    emit('reloadQueue')
89
+    emit('reload-queue')
89
 }
90
 }
90
 const hold = () => {
91
 const hold = () => {
91
     console.log('held? do we need this?')
92
     console.log('held? do we need this?')
96
     const profileId = props.pid
97
     const profileId = props.pid
97
     const targetId = props.profiles[0].pid
98
     const targetId = props.profiles[0].pid
98
     updateQueueByProfileId(profileId, targetId, true)
99
     updateQueueByProfileId(profileId, targetId, true)
99
-    emit('reloadQueue')
100
+    emit('reload-queue')
100
 }
101
 }
101
 
102
 
102
 // from the data() section
103
 // from the data() section
108
 const favorites = []
109
 const favorites = []
109
 const requests = []
110
 const requests = []
110
 
111
 
111
-    // // I dont know how to convert these to the script setup method
112
-// created() {
113
-//     this.getUser(),
114
-// },
115
-// End conversion from script to script setup
116
-
117
 
112
 
118
 </script>
113
 </script>
119
 
114
 

+ 12
- 7
frontend/src/components/Sidebar.vue Voir le fichier

1
 <template lang="pug">
1
 <template lang="pug">
2
 aside.sidebar.p-1.f-col.between
2
 aside.sidebar.p-1.f-col.between
3
-    h3 Messages
3
+    h3 Profile: {{ pid }}
4
     .search
4
     .search
5
         input
5
         input
6
         label search
6
         label search
8
     messages(:title="title" :users="users")
8
     messages(:title="title" :users="users")
9
     .spacer.f-grow
9
     .spacer.f-grow
10
     .temp-control-box.f-row.start.center
10
     .temp-control-box.f-row.start.center
11
-        p.t-up.p-0 current user
12
-        input(v-model='mypid' style="width: 50px")
13
-        button(@click="$emit('updatePid', mypid)").t-up.p-0 switch
11
+        input(v-model='switchToPID' style="width: 50px")
12
+        button(@click="$emit('updatePid', switchToPID)").t-up.p-0 switch profile
14
 </template>
13
 </template>
15
 
14
 
16
 <script>
15
 <script>
18
 
17
 
19
 export default {
18
 export default {
20
     components: { messages }, 
19
     components: { messages }, 
20
+    props: {
21
+        pid: {
22
+            required: true
23
+        }
24
+    },
21
     data: () => ({
25
     data: () => ({
22
         title:'Messages from Matches',
26
         title:'Messages from Matches',
23
-        mypid: 45,
27
+        switchToPID: null,
24
         users: [
28
         users: [
25
             {
29
             {
26
                 name: 'Bob McRob',
30
                 name: 'Bob McRob',
36
             },
40
             },
37
         ],
41
         ],
38
     }),
42
     }),
39
-    created() {
40
-        this.$emit('updatePid', this.mypid)
43
+    mounted() {
44
+        // Set the form to display the default pid set in Home.vue
45
+        this.switchToPID = this.pid
41
     }
46
     }
42
 }
47
 }
43
 </script>
48
 </script>

+ 9
- 6
frontend/src/components/form.vue Voir le fichier

66
         type: Array,
66
         type: Array,
67
         required: true,
67
         required: true,
68
     },
68
     },
69
+    pid: {
70
+        required: true
71
+    }
69
 })
72
 })
70
 /**
73
 /**
71
  * Our form is comprised of steps, and each step has a series of questions
74
  * Our form is comprised of steps, and each step has a series of questions
124
                 val: answers[answerKey],
127
                 val: answers[answerKey],
125
             })
128
             })
126
         })
129
         })
127
-        // Remove 1st answer from idWithResponseVal and use it for profileId
128
-        // Bc we don't want to pass the 1st question to backend & we want profileId
129
-        // Necessary atm bc we manually added question in Survey class (entity)
130
-        const profileId = idWithResponseVal.shift().val
130
+
131
         const maxDistance = 100
131
         const maxDistance = 100
132
-        saveSurveyByProfileID(idWithResponseVal, profileId)
132
+        
133
+        if(!props.pid) return console.error(`no pid: ${props.pid}`)
134
+
135
+        saveSurveyByProfileID(idWithResponseVal, props.pid)
133
         alert('Responses submitted!')
136
         alert('Responses submitted!')
134
         resetAnswers()
137
         resetAnswers()
135
-        scoreSurveyByProfileId(profileId, maxDistance)
138
+        scoreSurveyByProfileId(props.pid, maxDistance)
136
         state.step = 1
139
         state.step = 1
137
     } else if (state.step < props.form.length) {
140
     } else if (state.step < props.form.length) {
138
         state.step++
141
         state.step++

+ 0
- 10
frontend/src/entities/survey/survey.js Voir le fichier

10
 
10
 
11
         /**  Fields */
11
         /**  Fields */
12
         this.steps = [
12
         this.steps = [
13
-            [
14
-                {
15
-                    id: 0,
16
-                    type: 'input-string',
17
-                    question: 'what is your profile id',
18
-                    responses: null,
19
-                    description: null,
20
-                    category: null,
21
-                }
22
-            ],
23
             ...Object.values(questionSteps),
13
             ...Object.values(questionSteps),
24
         ] // ! required
14
         ] // ! required
25
         
15
         

+ 7
- 0
frontend/src/utils/auth.js Voir le fichier

1
+class Authenticator {
2
+    constructor() {
3
+        this.curentUser = null
4
+    }
5
+}
6
+
7
+export { Authenticator }

+ 6
- 1
frontend/src/utils/index.js Voir le fichier

1
 import Joi from 'joi'
1
 import Joi from 'joi'
2
 import { Connector } from './db'
2
 import { Connector } from './db'
3
+import { Login } from './login'
4
+import { Authenticator } from './auth'
3
 
5
 
4
 const api = new Connector('kittens')
6
 const api = new Connector('kittens')
5
 
7
 
14
     return input.toLowerCase().split(' ').join('-')
16
     return input.toLowerCase().split(' ').join('-')
15
 }
17
 }
16
 
18
 
17
-export { api, validatorMapping, makeKebob }
19
+const loginHandler = new Login()
20
+const authHandler = new Authenticator()
21
+
22
+export { api, validatorMapping, loginHandler, authHandler, makeKebob }

+ 13
- 0
frontend/src/utils/login.js Voir le fichier

1
+class Login {
2
+    constructor() {
3
+        this.currentProfileId = null
4
+    }
5
+    logout() {
6
+        this.currentProfileId = null
7
+    }
8
+    login(pid) {
9
+        this.currentProfileId = parseInt(pid)
10
+    }
11
+}
12
+
13
+export { Login }

+ 9
- 4
frontend/src/views/Matches.vue Voir le fichier

3
 main.f-col.start.w-full
3
 main.f-col.start.w-full
4
     article.match
4
     article.match
5
         h1 Match Page
5
         h1 Match Page
6
-    mainNav
6
+    main-nav(:pid="pid")
7
 </template>
7
 </template>
8
 
8
 
9
 <script>
9
 <script>
10
-import { defineComponent } from 'vue'
11
 import sidebar from '../components/Sidebar.vue'
10
 import sidebar from '../components/Sidebar.vue'
12
 import mainNav from '../components/MainNav.vue'
11
 import mainNav from '../components/MainNav.vue'
12
+import { loginHandler } from '../utils'
13
 
13
 
14
 // import icon from '@/components/icon.vue'
14
 // import icon from '@/components/icon.vue'
15
 // import card from '@/components/card.vue'
15
 // import card from '@/components/card.vue'
16
 
16
 
17
-export default defineComponent({
17
+export default {
18
     components: { sidebar, mainNav },
18
     components: { sidebar, mainNav },
19
-})
19
+    computed: {
20
+        pid: () => {
21
+            return loginHandler.currentProfileId
22
+        }
23
+    },
24
+}
20
 </script>
25
 </script>
21
 
26
 
22
 <style lang="postcss">
27
 <style lang="postcss">

+ 7
- 1
frontend/src/views/Profile.vue Voir le fichier

3
 main.f-col.start.w-full
3
 main.f-col.start.w-full
4
     article#profile
4
     article#profile
5
         h1 Profile Page
5
         h1 Profile Page
6
-    main-nav
6
+    main-nav(:pid="pid")
7
 </template>
7
 </template>
8
 
8
 
9
 <script>
9
 <script>
10
 import sidebar from '../components/Sidebar.vue'
10
 import sidebar from '../components/Sidebar.vue'
11
 import mainNav from '../components/MainNav.vue'
11
 import mainNav from '../components/MainNav.vue'
12
+import { loginHandler } from '../utils'
12
 
13
 
13
 export default {
14
 export default {
14
     name: 'Profile',
15
     name: 'Profile',
24
             },
25
             },
25
         }
26
         }
26
     },
27
     },
28
+    computed: {
29
+        pid: () => {
30
+            return loginHandler.currentProfileId
31
+        }
32
+    },
27
     created() {
33
     created() {
28
         this.getUser()
34
         this.getUser()
29
     },
35
     },

+ 10
- 3
frontend/src/views/Survey.vue Voir le fichier

3
 main.f-col.start.w-full
3
 main.f-col.start.w-full
4
     article.match
4
     article.match
5
         h1 Survey Page
5
         h1 Survey Page
6
-        siimeform(v-if="validSurvey && validSurvey.steps" :form="validSurvey.steps")
7
-    mainNav
6
+        siimeform(v-if="validSurvey && validSurvey.steps" :form="validSurvey.steps" :pid="pid")
7
+    main-nav(:pid="pid")
8
 </template>
8
 </template>
9
 
9
 
10
 <script>
10
 <script>
12
 import sidebar from '../components/Sidebar.vue'
12
 import sidebar from '../components/Sidebar.vue'
13
 import mainNav from '../components/MainNav.vue'
13
 import mainNav from '../components/MainNav.vue'
14
 import { fetchSurveyByProfileId } from '../services'
14
 import { fetchSurveyByProfileId } from '../services'
15
+import { loginHandler } from '../utils'
15
 
16
 
16
 export default {
17
 export default {
17
     components: { siimeform, sidebar, mainNav },
18
     components: { siimeform, sidebar, mainNav },
20
             validSurvey: null,
21
             validSurvey: null,
21
         }
22
         }
22
     },
23
     },
24
+    computed: {
25
+        pid: () => {
26
+            return loginHandler.currentProfileId
27
+        }
28
+    },
23
     async created() {
29
     async created() {
24
-        this.validSurvey = await fetchSurveyByProfileId()
30
+        console.log('survey for:', this.$route.query.pid)
31
+        this.validSurvey = await fetchSurveyByProfileId(this.$route.query.pid)
25
     },
32
     },
26
 }
33
 }
27
 </script>
34
 </script>

+ 28
- 22
frontend/src/views/home.vue Voir le fichier

1
 <template lang="pug">
1
 <template lang="pug">
2
-sidebar(@updatePid="setPid")
2
+sidebar(v-if='!loading' :pid="pid" @updatePid="setPid")
3
 main.f-col.start.w-full
3
 main.f-col.start.w-full
4
     article#home(v-if='!loading')
4
     article#home(v-if='!loading')
5
-        h1(v-if='user') {{ user.user_name }}
6
-        profile-card-list(:profiles='swipables' :pid='parseInt(mypid)' @reloadQueue='getQueue')
5
+        h1 Queue Page
6
+        profile-card-list(:profiles='swipables' :pid='parseInt(pid)' @reload-queue='getQueue')
7
     p(v-else) Loading...
7
     p(v-else) Loading...
8
-    main-nav
8
+    main-nav(v-if='!loading' :pid="pid")
9
 </template>
9
 </template>
10
 
10
 
11
 <script>
11
 <script>
15
 import { fetchQueueByProfileId } from '../services'
15
 import { fetchQueueByProfileId } from '../services'
16
 import { StonkAlert } from '../services/notification.service'
16
 import { StonkAlert } from '../services/notification.service'
17
 import { Chatter } from '../services/chat.service'
17
 import { Chatter } from '../services/chat.service'
18
+import { loginHandler, authHandler } from '../utils'
18
 
19
 
19
 import batch_10 from '../../../backend/db/generated/_batch_10.js.ref'
20
 import batch_10 from '../../../backend/db/generated/_batch_10.js.ref'
20
 import batch_20 from '../../../backend/db/generated/_batch_20.js.ref'
21
 import batch_20 from '../../../backend/db/generated/_batch_20.js.ref'
25
     components: { profileCardList, sidebar, mainNav },
26
     components: { profileCardList, sidebar, mainNav },
26
     data: () => ({
27
     data: () => ({
27
         swipables: [],
28
         swipables: [],
28
-        user: null,
29
-        mypid: null,
30
-        loading: true
29
+        loading: true,
30
+        pid: null
31
     }),
31
     }),
32
     mounted() {
32
     mounted() {
33
-        this.setupChatter()
34
-        this.setupToaster()
35
-    },
36
-    async created() {
37
-        // this.mypid = auth.currentUser?.mypid || "99999";
38
-        this.mypid = 38
33
+        // Uncomment below to use API
34
+        let pid = null
35
+        if(!loginHandler.currentProfileId) {
36
+            pid  = authHandler.currentUser?.pid || 45
37
+        } else {
38
+            pid = loginHandler.currentProfileId
39
+        }
40
+        this.setPid(pid)
41
+
39
         // Uncomment below to use for batch file data
42
         // Uncomment below to use for batch file data
40
         // this.processProfilesFromBatch(this.parseBatch([batch_10, batch_20, batch_30]))
43
         // this.processProfilesFromBatch(this.parseBatch([batch_10, batch_20, batch_30]))
41
 
44
 
42
-        // Uncomment below to use API
43
-        const queueList = await fetchQueueByProfileId(this.mypid)
44
-        // console.log('queueList', queueList)
45
-        this.processQueue(queueList)
45
+        this.setupChatter()
46
+        this.setupToaster()
46
     },
47
     },
47
     methods: {
48
     methods: {
48
         setupToaster() {
49
         setupToaster() {
49
-            const t = new StonkAlert(this.mypid)
50
+            const t = new StonkAlert(this.pid)
50
         },
51
         },
51
         setupChatter() {
52
         setupChatter() {
52
             const c = new Chatter()
53
             const c = new Chatter()
55
             console.log('---')
56
             console.log('---')
56
         },
57
         },
57
         setPid(pid) {
58
         setPid(pid) {
58
-            this.mypid = pid
59
+            loginHandler.login(pid)
60
+            this.pid = loginHandler.currentProfileId
59
             this.getQueue()
61
             this.getQueue()
60
         },
62
         },
61
         async getQueue() {
63
         async getQueue() {
62
             this.loading = true
64
             this.loading = true
63
-            const queueList = await fetchQueueByProfileId(this.mypid)
64
-            this.processQueue(queueList)
65
+            try {
66
+                const queueList = await fetchQueueByProfileId(this.pid)
67
+                this.processQueue(queueList)
68
+            } catch (err) {
69
+                console.error(err)
70
+            }
65
             this.loading = false
71
             this.loading = false
66
         },
72
         },
67
         setupToaster() {
73
         setupToaster() {
68
-            const t = new StonkAlert(this.mypid)
74
+            const t = new StonkAlert(this.pid)
69
         },
75
         },
70
         setupChatter() {
76
         setupChatter() {
71
             const c = new Chatter()
77
             const c = new Chatter()

Chargement…
Annuler
Enregistrer