Browse Source

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

tags/0.0.1
J 4 years ago
parent
commit
727349d21a

+ 2
- 3
backend/lib/routes/profile/patch-queue.js View File

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

+ 8
- 3
frontend/src/components/MainNav.vue View File

@@ -1,14 +1,19 @@
1 1
 <template lang="pug">
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 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 7
 </template>
8 8
 
9 9
 <script>
10 10
 export default {
11 11
     name: 'MainNav',
12
+    props: {
13
+        pid: {
14
+            required: true
15
+        }
16
+    }
12 17
 }
13 18
 </script>
14 19
 

+ 4
- 9
frontend/src/components/ProfileCardList.vue View File

@@ -23,10 +23,11 @@ section.profile_card_list.w-full
23 23
 </template>
24 24
 
25 25
 <script setup>
26
+import { onMounted } from '@vue/runtime-core';
26 27
 import { computed, defineProps, defineEmits } from 'vue'
27 28
 import { updateQueueByProfileId, fetchMembershipsByProfileId, postMembershipByProfileId } from '../services'
28 29
 
29
-const emit = defineEmits(['reloadQueue'])
30
+const emit = defineEmits(['reload-queue'])
30 31
 // TODO: Please review this conversion from script to script setup
31 32
 // converted from the props section
32 33
 const props = defineProps({
@@ -85,7 +86,7 @@ const accept = async () => {
85 86
         console.log('Make membership')
86 87
         postMembershipByProfileId({ profileId, targetId })
87 88
     }
88
-    emit('reloadQueue')
89
+    emit('reload-queue')
89 90
 }
90 91
 const hold = () => {
91 92
     console.log('held? do we need this?')
@@ -96,7 +97,7 @@ const pass = () => {
96 97
     const profileId = props.pid
97 98
     const targetId = props.profiles[0].pid
98 99
     updateQueueByProfileId(profileId, targetId, true)
99
-    emit('reloadQueue')
100
+    emit('reload-queue')
100 101
 }
101 102
 
102 103
 // from the data() section
@@ -108,12 +109,6 @@ const config = {
108 109
 const favorites = []
109 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 113
 </script>
119 114
 

+ 12
- 7
frontend/src/components/Sidebar.vue View File

@@ -1,6 +1,6 @@
1 1
 <template lang="pug">
2 2
 aside.sidebar.p-1.f-col.between
3
-    h3 Messages
3
+    h3 Profile: {{ pid }}
4 4
     .search
5 5
         input
6 6
         label search
@@ -8,9 +8,8 @@ aside.sidebar.p-1.f-col.between
8 8
     messages(:title="title" :users="users")
9 9
     .spacer.f-grow
10 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 13
 </template>
15 14
 
16 15
 <script>
@@ -18,9 +17,14 @@ import messages from './Messages.vue'
18 17
 
19 18
 export default {
20 19
     components: { messages }, 
20
+    props: {
21
+        pid: {
22
+            required: true
23
+        }
24
+    },
21 25
     data: () => ({
22 26
         title:'Messages from Matches',
23
-        mypid: 45,
27
+        switchToPID: null,
24 28
         users: [
25 29
             {
26 30
                 name: 'Bob McRob',
@@ -36,8 +40,9 @@ export default {
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 48
 </script>

+ 9
- 6
frontend/src/components/form.vue View File

@@ -66,6 +66,9 @@ const props = defineProps({
66 66
         type: Array,
67 67
         required: true,
68 68
     },
69
+    pid: {
70
+        required: true
71
+    }
69 72
 })
70 73
 /**
71 74
  * Our form is comprised of steps, and each step has a series of questions
@@ -124,15 +127,15 @@ const next = async e => {
124 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 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 136
         alert('Responses submitted!')
134 137
         resetAnswers()
135
-        scoreSurveyByProfileId(profileId, maxDistance)
138
+        scoreSurveyByProfileId(props.pid, maxDistance)
136 139
         state.step = 1
137 140
     } else if (state.step < props.form.length) {
138 141
         state.step++

+ 0
- 10
frontend/src/entities/survey/survey.js View File

@@ -10,16 +10,6 @@ class Survey extends _baseRecord {
10 10
 
11 11
         /**  Fields */
12 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 13
             ...Object.values(questionSteps),
24 14
         ] // ! required
25 15
         

+ 7
- 0
frontend/src/utils/auth.js View File

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

+ 6
- 1
frontend/src/utils/index.js View File

@@ -1,5 +1,7 @@
1 1
 import Joi from 'joi'
2 2
 import { Connector } from './db'
3
+import { Login } from './login'
4
+import { Authenticator } from './auth'
3 5
 
4 6
 const api = new Connector('kittens')
5 7
 
@@ -14,4 +16,7 @@ const makeKebob = input => {
14 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 View File

@@ -0,0 +1,13 @@
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 View File

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

+ 7
- 1
frontend/src/views/Profile.vue View File

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

+ 10
- 3
frontend/src/views/Survey.vue View File

@@ -3,8 +3,8 @@ sidebar
3 3
 main.f-col.start.w-full
4 4
     article.match
5 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 8
 </template>
9 9
 
10 10
 <script>
@@ -12,6 +12,7 @@ import siimeform from '../components/form.vue'
12 12
 import sidebar from '../components/Sidebar.vue'
13 13
 import mainNav from '../components/MainNav.vue'
14 14
 import { fetchSurveyByProfileId } from '../services'
15
+import { loginHandler } from '../utils'
15 16
 
16 17
 export default {
17 18
     components: { siimeform, sidebar, mainNav },
@@ -20,8 +21,14 @@ export default {
20 21
             validSurvey: null,
21 22
         }
22 23
     },
24
+    computed: {
25
+        pid: () => {
26
+            return loginHandler.currentProfileId
27
+        }
28
+    },
23 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 34
 </script>

+ 28
- 22
frontend/src/views/home.vue View File

@@ -1,11 +1,11 @@
1 1
 <template lang="pug">
2
-sidebar(@updatePid="setPid")
2
+sidebar(v-if='!loading' :pid="pid" @updatePid="setPid")
3 3
 main.f-col.start.w-full
4 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 7
     p(v-else) Loading...
8
-    main-nav
8
+    main-nav(v-if='!loading' :pid="pid")
9 9
 </template>
10 10
 
11 11
 <script>
@@ -15,6 +15,7 @@ import profileCardList from '../components/ProfileCardList.vue'
15 15
 import { fetchQueueByProfileId } from '../services'
16 16
 import { StonkAlert } from '../services/notification.service'
17 17
 import { Chatter } from '../services/chat.service'
18
+import { loginHandler, authHandler } from '../utils'
18 19
 
19 20
 import batch_10 from '../../../backend/db/generated/_batch_10.js.ref'
20 21
 import batch_20 from '../../../backend/db/generated/_batch_20.js.ref'
@@ -25,28 +26,28 @@ export default {
25 26
     components: { profileCardList, sidebar, mainNav },
26 27
     data: () => ({
27 28
         swipables: [],
28
-        user: null,
29
-        mypid: null,
30
-        loading: true
29
+        loading: true,
30
+        pid: null
31 31
     }),
32 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 42
         // Uncomment below to use for batch file data
40 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 48
     methods: {
48 49
         setupToaster() {
49
-            const t = new StonkAlert(this.mypid)
50
+            const t = new StonkAlert(this.pid)
50 51
         },
51 52
         setupChatter() {
52 53
             const c = new Chatter()
@@ -55,17 +56,22 @@ export default {
55 56
             console.log('---')
56 57
         },
57 58
         setPid(pid) {
58
-            this.mypid = pid
59
+            loginHandler.login(pid)
60
+            this.pid = loginHandler.currentProfileId
59 61
             this.getQueue()
60 62
         },
61 63
         async getQueue() {
62 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 71
             this.loading = false
66 72
         },
67 73
         setupToaster() {
68
-            const t = new StonkAlert(this.mypid)
74
+            const t = new StonkAlert(this.pid)
69 75
         },
70 76
         setupChatter() {
71 77
             const c = new Chatter()

Loading…
Cancel
Save