Преглед изворни кода

:fire: simplifying | removing cruft

tags/0.0.1
J пре 4 година
родитељ
комит
e379d5a16d

+ 13
- 10
frontend/src/App.vue Прегледај датотеку

@@ -8,38 +8,41 @@ import * as sss from '@/sss/import.css'
8 8
 
9 9
 import SideBar from './components/SideBar.vue'
10 10
 
11
-import { Chatter, StonkAlert } from './services'
11
+import { Chatter, StonkAlert, currentProfile } from './services'
12 12
 
13 13
 const DEFAULT_PID = 45
14 14
 
15 15
 export default {
16 16
     components: { SideBar },
17 17
     data: () => ({
18
-        pid: null,
19 18
         showSidebar: false
20 19
     }),
20
+    computed:{
21
+        pid: () => {
22
+            return currentProfile.id ?  currentProfile.id : DEFAULT_PID
23
+        }
24
+    },
21 25
     created() {
22
-        this.setPid()
23 26
         this.setupChatter()
24 27
         this.setupToaster()
25 28
     },
26 29
     methods: {
27
-        setPid(pid) {
28
-            this.pid = pid ? parseInt(pid) : DEFAULT_PID
29
-        },
30
-
31
-        // For push notifications and chat 
30
+        /**
31
+         * For push notifications and chat group initiation
32
+         */
32 33
         setupToaster() {
33 34
             const t = new StonkAlert(this.pid)
34 35
         },
36
+        /**
37
+         * Pubnub stuff
38
+         */
35 39
         setupChatter() {
36 40
             const c = new Chatter()
37 41
             const testAccountUUID = import.meta.env.VITE_TEST_ACCOUNT_UUID
38 42
             c.setup(testAccountUUID)
39 43
             console.log('---')
40
-        },
44
+        }
41 45
     },
42
-    
43 46
 }
44 47
 </script>
45 48
 

+ 20
- 14
frontend/src/main.js Прегледај датотеку

@@ -1,26 +1,32 @@
1 1
 import { createApp } from 'vue'
2
-import App from './App.vue'
3 2
 import router from './router'
3
+import { currentProfile } from './services'
4 4
 
5
+import App from './App.vue'
5 6
 import MainNav from './components/MainNav.vue'
6 7
 
7
-router.beforeEach((to, from, next) => {
8
-    const requiresAuth = false
9
-    const requiresProfile = true
8
+/**
9
+ * Router guard functions
10
+ */
11
+const checkLoginStatus = (destination, nextCb) => {
12
+    const requiresCompleteProfile = destination.meta.requiresAuth
10 13
 
11
-    if (requiresAuth) {
12
-        console.log('You are not authorized to access this area.')
13
-        next('login')
14
+    if(!currentProfile.isLoggedIn() && requiresCompleteProfile) {
15
+        nextCb('login')
14 16
     } else {
15
-        next()
17
+        nextCb()
16 18
     }
19
+}
17 20
 
18
-    // if (requiresProfile) {
19
-    //   console.log('You must first complete your profile.')
20
-    //   next('profile')
21
-    // } else {
22
-    //   next()
23
-    // }
21
+/**
22
+ * Check between route changes for login/timeout
23
+ */
24
+router.beforeEach((to, from, next) => {
25
+    console.log(currentProfile.isLoggedIn())
26
+    /**
27
+     * Use the loginService to deal with login details
28
+     */
29
+    checkLoginStatus(to, next)
24 30
 })
25 31
 
26 32
 const siimee = createApp(App).use(router)

+ 11
- 24
frontend/src/router/index.js Прегледај датотеку

@@ -2,11 +2,9 @@ import { createRouter, createWebHistory } from 'vue-router'
2 2
 
3 3
 import HomeView from '../views/HomeView.vue'
4 4
 import ProfileView from '../views/ProfileView.vue'
5
-import Matches from '../views/Matches.vue'
6
-import Chats from '../views/Chats.vue'
7
-import Login from '../views/Login.vue'
8
-import Register from '../views/Register.vue'
9
-import Survey from '../views/Survey.vue'
5
+import MatchesView from '../views/MatchesView.vue'
6
+import LoginView from '../views/LoginView.vue'
7
+import SurveyView from '../views/SurveyView.vue'
10 8
 
11 9
 const routes = [
12 10
     {
@@ -19,35 +17,24 @@ const routes = [
19 17
         path: '/profile/:pid',
20 18
         component: ProfileView,
21 19
         name: 'ProfileView',
22
-        meta: { requiresAuth: true },
20
+        meta: { requiresAuth: true, requiresProfile: true },
23 21
     },
24 22
     {
25 23
         path: '/matches',
26
-        component: Matches,
27
-        name: 'matches',
24
+        component: MatchesView,
25
+        name: 'MatchesView',
28 26
         meta: { requiresAuth: true, requiresProfile: true },
29 27
     },
30 28
     {
31
-        path: '/chats/:uid',
32
-        component: Chats,
33
-        name: `chat`,
34
-        props: true,
29
+        path: `/survey`,
30
+        component: SurveyView,
31
+        name: `SurveyView`,
35 32
         meta: { requiresAuth: true, requiresProfile: true },
36 33
     },
37 34
     {
38 35
         path: `/login`,
39
-        component: Login,
40
-        name: `login`,
41
-    },
42
-    {
43
-        path: `/survey`,
44
-        component: Survey,
45
-        name: `survey`,
46
-    },
47
-    {
48
-        path: `/register`,
49
-        component: Register,
50
-        name: `register`,
36
+        component: LoginView,
37
+        name: `LoginView`,
51 38
     },
52 39
 ]
53 40
 

frontend/src/utils/auth.js → frontend/src/services/auth.service.js Прегледај датотеку


+ 2
- 0
frontend/src/services/index.js Прегледај датотеку

@@ -4,3 +4,5 @@ export * from './survey.service'
4 4
 export * from './queue.service'
5 5
 export * from './chat.service'
6 6
 export * from './notification.service'
7
+export * from './login.service'
8
+

+ 73
- 0
frontend/src/services/login.service.js Прегледај датотеку

@@ -0,0 +1,73 @@
1
+import { fetchQueueByProfileId, fetchResponsesByProfileId } from '../services'
2
+
3
+class Login {
4
+    constructor() {
5
+        this._loading = true
6
+
7
+        this.id = null
8
+        this.queue = []
9
+        this.matches = []
10
+        this.responses = []
11
+    }
12
+    isLoading() {
13
+        return this._loading
14
+    }
15
+    isLoggedIn() {
16
+        return this.id != null
17
+    }
18
+    hasQueue() {
19
+        return this.queue.length && this.queue.length > 0
20
+    }
21
+    hasMatches() {
22
+        return this.matches.length && this.matches.length > 0
23
+    } 
24
+    hasResponses() {
25
+        return this.responses.length && this.responses.length > 0
26
+    } 
27
+
28
+    async getQueue() {
29
+        this._loading = true
30
+        try {
31
+            const queueList = await fetchQueueByProfileId(this.id)
32
+            const formatted = this._reformatProfiles(queueList)
33
+            this._setQueue(formatted)
34
+            this._loading = false
35
+        } catch (err) {
36
+            console.error(err)
37
+        }
38
+    }
39
+    _reformatProfiles(profiles) {
40
+        const formattedList = profiles.map(profile => {
41
+            return {
42
+                pid: profile.profile_id,
43
+                name: profile.user_name,
44
+                avatar: '',
45
+            }
46
+        })
47
+        return formattedList
48
+    }
49
+    _setQueue(queue) { this.queue = queue }
50
+
51
+    async getResponses() {
52
+        try {
53
+            const responseList = await fetchResponsesByProfileId(this.id)
54
+            this._setResponses(responseList)
55
+        } catch (err) {
56
+            console.error(err)
57
+        }
58
+    }
59
+    _setResponses(responses) { this.responses = responses }
60
+    
61
+    /**
62
+     * Login a profile id
63
+     */
64
+    async login(pid) {
65
+        this.id = parseInt(pid)
66
+        return this.id
67
+    }
68
+    logout() { this.id = null }
69
+}
70
+
71
+const currentProfile = new Login()
72
+
73
+export { currentProfile }

+ 7
- 0
frontend/src/services/survey.service.js Прегледај датотеку

@@ -47,9 +47,16 @@ const scoreSurveyByProfileId = async (profileId, maxDistance) => {
47 47
     return scoreSurvey
48 48
 }
49 49
 
50
+const fetchResponsesByProfileId = async profileId => {
51
+    return await db.get(
52
+        `/profile/${profileId}/responses`,
53
+    )
54
+}
55
+
50 56
 export {
51 57
     fetchQuestionsByProfileId,
52 58
     saveSurveyByProfileId,
53 59
     updateSurveyByProfileId,
54 60
     scoreSurveyByProfileId,
61
+    fetchResponsesByProfileId,
55 62
 }

+ 1
- 5
frontend/src/utils/index.js Прегледај датотеку

@@ -1,7 +1,5 @@
1 1
 import Joi from 'joi'
2 2
 import { Connector } from './db'
3
-import { Login } from './login'
4
-import { Authenticator } from './auth'
5 3
 import { SurveyFactory } from './survey'
6 4
 import { possible } from './lang'
7 5
 
@@ -18,8 +16,6 @@ const makeKebob = input => {
18 16
     return input.toLowerCase().split(' ').join('-')
19 17
 }
20 18
 
21
-const loginHandler = new Login()
22
-const authHandler = new Authenticator()
23 19
 const surveyFactory = new SurveyFactory(possible['usa'])
24 20
 
25
-export { api, validatorMapping, loginHandler, authHandler, surveyFactory, makeKebob }
21
+export { api, validatorMapping, surveyFactory, makeKebob }

+ 0
- 49
frontend/src/utils/login.js Прегледај датотеку

@@ -1,49 +0,0 @@
1
-import { fetchQueueByProfileId } from '../services'
2
-
3
-class Login {
4
-    constructor() {
5
-        this.loading = true
6
-        this.currentProfileId = null
7
-        this.survey = null
8
-        this.queue = null
9
-        this.matches = null
10
-    }
11
-
12
-    _setSurvey(survey) {
13
-        this.survey = []
14
-    }
15
-
16
-    async getQueue() {
17
-        this.loading = true
18
-        try {
19
-            const queueList = await fetchQueueByProfileId(this.currentProfileId)
20
-            const formatted = this._reformatProfiles(queueList)
21
-            this._setQueue(formatted)
22
-            this.loading = false
23
-        } catch (err) {
24
-            console.error(err)
25
-        }
26
-    }
27
-    _reformatProfiles(profiles) {
28
-        const formattedList = profiles.map(profile => {
29
-            return {
30
-                pid: profile.profile_id,
31
-                name: profile.user_name,
32
-                avatar: '',
33
-            }
34
-        })
35
-        return formattedList
36
-    }
37
-    _SET_QUEUE(queue) {
38
-        this.queue = queue
39
-    }
40
-
41
-    logout() {
42
-        this.currentProfileId = null
43
-    }
44
-    async login(pid) {
45
-        this.currentProfileId = parseInt(pid)
46
-    }
47
-}
48
-
49
-export { Login }

+ 0
- 297
frontend/src/views/Chats.vue
Разлика између датотеке није приказан због своје велике величине
Прегледај датотеку


+ 7
- 3
frontend/src/views/HomeView.vue Прегледај датотеку

@@ -1,9 +1,13 @@
1 1
 <template lang="pug">
2
-main.f-col.start.w-full
3
-    article#home(v-if="!loading")
4
-        h1 Queue Page
2
+main.view--home.f-col.start.w-full
3
+    header
4
+        h2 home
5
+
6
+    article(v-if="!loading")
5 7
         ProfileCardList(:profiles="cards" :pid="pid" @reload-queue="getQueue")
8
+
6 9
     p(v-else) Loading...
10
+
7 11
     MainNav(@show-sidebar="$emit('show-sidebar')")
8 12
 </template>
9 13
 

+ 0
- 48
frontend/src/views/Login.vue Прегледај датотеку

@@ -1,48 +0,0 @@
1
-<template lang="pug">
2
-.login__box
3
-    h2 Login
4
-    form(@submit.prevent='onSubmit')
5
-        .user__box
6
-            input(required='' type='email' v-model='form.email')
7
-            label Email
8
-        .user__box
9
-            input(required='' type='password' v-model='form.password')
10
-            label Password
11
-        .user__box
12
-            router-link.forget__link(to='/forget') Forget Password
13
-        .user__box(style='margin-top: 10px; cursor: pointer')
14
-            p.forget__link(@click='guestAccount') Guest Account
15
-        button(type='submit')
16
-            span
17
-            span
18
-            span
19
-            span {{ requesting ? "Log..." : "Login" }}
20
-        router-link.links(to='/register') Register
21
-</template>
22
-
23
-<script>
24
-export default {
25
-    data: () => ({
26
-        requesting: false,
27
-        form: {
28
-            email: '',
29
-            password: '',
30
-        },
31
-    }),
32
-    methods: {
33
-        onSubmit() {
34
-            this.requesting = true
35
-            // Do some auth
36
-        },
37
-        guestAccount() {
38
-            this.form.email = 'lucy@me.com'
39
-            this.form.password = '123456'
40
-            this.onSubmit()
41
-        },
42
-    },
43
-}
44
-</script>
45
-
46
-<style lang="postcss">
47
-
48
-</style>

+ 51
- 0
frontend/src/views/LoginView.vue Прегледај датотеку

@@ -0,0 +1,51 @@
1
+<template lang="pug">
2
+main.view--login.w-full.f-col
3
+    header
4
+        h2 Login
5
+
6
+    article
7
+        form(@submit.prevent='onSubmit')
8
+            label profile id:
9
+            input(required='' type='profileId' v-model='form.profileId')
10
+            button(type='submit') submit
11
+</template>
12
+
13
+<script>
14
+import { currentProfile } from '../services'
15
+
16
+export default {
17
+    data: () => ({
18
+        form: {
19
+            profileId: null
20
+        },
21
+    }),
22
+    methods: {
23
+        async onSubmit() {
24
+            if(!this.form.profileId) console.error('No profile in form')
25
+            /**
26
+             * Default to the HomeView and
27
+             * alter as needed (side-effects!)
28
+             */
29
+            const toRoute = { name: 'HomeView' }
30
+            
31
+            /**
32
+             * Profile needs a complete survey and
33
+             * alters the url if it's incomplete
34
+             */
35
+            const alreadyLoggedIn = await currentProfile.isLoggedIn()
36
+            if(!alreadyLoggedIn) {
37
+                await currentProfile.login(this.form.profileId)
38
+                if(!currentProfile.hasResponses()) {
39
+                    toRoute.name = 'SurveyView'
40
+                }
41
+            }
42
+
43
+            this.$router.push(toRoute)
44
+        },
45
+    },
46
+}
47
+</script>
48
+
49
+<style lang="postcss">
50
+
51
+</style>

frontend/src/views/Matches.vue → frontend/src/views/MatchesView.vue Прегледај датотеку

@@ -1,9 +1,13 @@
1 1
 <template lang="pug">
2
-main.f-col.start.w-full
3
-    article#match(v-if="!loading")
4
-        h1 Match Page
2
+main.view--matches.f-col.start.w-full
3
+    header
4
+        h2 Match Page
5
+
6
+    article(v-if="!loading")
5 7
         ProfileCardList(:profiles="profiles" :pid="pid" :is-grid="true")
8
+    
6 9
     p(v-else) Loading...
10
+    
7 11
     MainNav(@show-sidebar="$emit('show-sidebar')")
8 12
 </template>
9 13
 

+ 8
- 4
frontend/src/views/ProfileView.vue Прегледај датотеку

@@ -1,10 +1,14 @@
1 1
 <template lang="pug">
2
-main.f-col.start.w-full
3
-    article#home(v-if="!loading")
4
-        h1 Profile Page
5
-        h2 {{ profile }}
2
+main.view--profile.f-col.start.w-full
3
+    header 
4
+        h2 Profile Page
5
+ 
6
+    article(v-if="!loading")
7
+        h3 {{ profile }}
6 8
         RouterLink(:to="{ name: 'HomeView' }") back
9
+
7 10
     p(v-else) Loading...
11
+
8 12
     MainNav(@show-sidebar="$emit('show-sidebar')")
9 13
 </template>
10 14
 

+ 0
- 56
frontend/src/views/Register.vue Прегледај датотеку

@@ -1,56 +0,0 @@
1
-<template lang="pug">
2
-.register__box
3
-    h2 Register
4
-    form(@submit.prevent='onSubmit')
5
-        .user__box
6
-            input(
7
-                minlength='5'
8
-                required=''
9
-                type='text'
10
-                v-model='form.fullname'
11
-            )
12
-            label Fullname
13
-        .user__box
14
-            input(minlength='10' required='' type='email' v-model='form.email')
15
-            label Email
16
-        .user__box
17
-            input(
18
-                minlength='6'
19
-                required=''
20
-                type='password'
21
-                v-model='form.password'
22
-            )
23
-            label Password
24
-        .user__box
25
-            router-link.forget__link(to='/forget') Forget Password
26
-        button(type='submit')
27
-            span
28
-            span
29
-            span
30
-            span {{ requesting ? "Log..." : "Register" }}
31
-        router-link.links(to='/login') Login
32
-</template>
33
-
34
-<script>
35
-export default {
36
-    data: () => ({
37
-        valid: true,
38
-        requesting: false,
39
-        form: {
40
-            email: '',
41
-            password: '',
42
-            fullname: '',
43
-        },
44
-    }),
45
-    methods: {
46
-        onSubmit() {
47
-            this.requesting = true
48
-            this.requesting = false
49
-        },
50
-    },
51
-}
52
-</script>
53
-
54
-<style lang="postcss">
55
-
56
-</style>

frontend/src/views/Survey.vue → frontend/src/views/SurveyView.vue Прегледај датотеку

@@ -1,9 +1,5 @@
1 1
 <template lang="pug">
2
-main.f-col.start.w-full
3
-    p {{step }}
4
-    //- ButtonMulti
5
-    //- ButtonChoice
6
-    //- InputString
2
+main.view--survey.f-col.start.w-full
7 3
     header.w-full.f-col
8 4
         Transition(name="slide-up" :duration="1600")
9 5
             h3(v-if="step == 0") hello, what shall i call you?

+ 0
- 128
frontend/src/views/home.vue Прегледај датотеку

@@ -1,128 +0,0 @@
1
-<template lang="pug">
2
-sidebar(v-if='!loading' :pid="pid" @updatePid="setPid")
3
-main.f-col.start.w-full
4
-    article#home(v-if='!loading')
5
-        h1 Queue Page
6
-        profile-card-list(:profiles='swipables' :pid='parseInt(pid)' @reload-queue='getQueue')
7
-    p(v-else) Loading...
8
-    main-nav(v-if='!loading' :pid="pid")
9
-</template>
10
-
11
-<script>
12
-import sidebar from '../components/Sidebar.vue'
13
-import mainNav from '../components/MainNav.vue'
14
-import profileCardList from '../components/ProfileCardList.vue'
15
-
16
-import { Chatter, StonkAlert } from '../services'
17
-import { loginHandler, authHandler } from '../utils'
18
-
19
-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_30 from '../../../backend/db/generated/_batch_30.js.ref'
22
-
23
-const DEFAULT_PID = 45
24
-
25
-export default {
26
-    name: 'HomeView',
27
-    components: { profileCardList, sidebar, mainNav },
28
-    data: () => ({
29
-        swipables: [],
30
-        loading: true,
31
-        pid: null
32
-    }),
33
-    mounted() {
34
-        // Uncomment below to use API
35
-        let pid
36
-        if(!loginHandler.currentProfileId) {
37
-            pid  = authHandler.currentUser?.pid || DEFAULT_PID
38
-        } else {
39
-            pid = loginHandler.currentProfileId
40
-        }
41
-        this.setPid(pid)
42
-
43
-        // Uncomment below to use for batch file data
44
-        // this.processProfilesFromBatch(this.parseBatch([batch_10, batch_20, batch_30]))
45
-
46
-        this.setupChatter()
47
-        this.setupToaster()
48
-    },
49
-    methods: {
50
-        setPid(pid) {
51
-            loginHandler.login(pid)
52
-            this.pid = loginHandler.currentProfileId
53
-            this.getQueue()
54
-        },
55
-        async getQueue() {
56
-            this.loading = true
57
-            try {
58
-                await loginHandler.getQueue()
59
-                this.swipables = loginHandler.queue
60
-            } catch (err) {
61
-                console.error(err)
62
-            }
63
-            this.loading = false
64
-        },
65
-        // For push notifications and chat 
66
-        setupToaster() {
67
-            const t = new StonkAlert(this.pid)
68
-        },
69
-        setupChatter() {
70
-            const c = new Chatter()
71
-            const testAccountUUID = import.meta.env.VITE_TEST_ACCOUNT_UUID
72
-            c.setup(testAccountUUID)
73
-            console.log('---')
74
-        },
75
-        // For Batch Data Parsing & Processing
76
-        parseBatch(allBatches) {
77
-            const finished = { profiles: [], users: [], responses: [] }
78
-            allBatches.forEach(batch => {
79
-                const split = batch.value.split('\n')
80
-                split.splice(0, 5)
81
-                split.unshift('{')
82
-                const p = JSON.parse(split.join(''))
83
-                finished.profiles = [...p.profiles, ...finished.profiles]
84
-                finished.users = [...p.users, ...finished.users]
85
-                finished.responses = [...p.responses, ...finished.responses]
86
-            })
87
-            // console.log('parsed batch', finished)
88
-            return finished
89
-        },
90
-        processProfilesFromBatch(parsed) {
91
-            const findUser = profile => {
92
-                return parsed.users.filter(u => u.user_id == profile.user_id)[0]
93
-            }
94
-            parsed.profiles.forEach(p => {
95
-                // console.log(parsed)
96
-                const user = findUser(p)
97
-                p.pid = p.profile_id
98
-                p.name = user.user_name
99
-                p.email = user.user_email
100
-                p.avatar = p.profile_media[0]
101
-                p.responses = parsed.responses.filter(
102
-                    r => r.profile_id == p.profile_id,
103
-                )
104
-                p.responses.forEach(r => {
105
-                    if (r.response_key_id == 7) {
106
-                        p.zipcode = r.val
107
-                    }
108
-                })
109
-                this.swipables.push(p)
110
-            })
111
-        },
112
-    },
113
-}
114
-</script>
115
-
116
-<style lang="postcss">
117
-main
118
-    position: relative
119
-    height: 100%
120
-    > article
121
-        height: 100%
122
-        width: 100%
123
-        flex-direction: column
124
-
125
-    input, button
126
-        position: relative
127
-        z-index: 1000
128
-</style>

Loading…
Откажи
Сачувај