Explorar el Código

profiles from generated batch; generator updated to include user_media

tags/0.0.1
diaseu hace 4 años
padre
commit
abc1ed1401

+ 1
- 0
backend/db/data-generator/classes.js Ver fichero

@@ -3,6 +3,7 @@ class User {
3 3
         this.user_id = id
4 4
         this.user_name = ''
5 5
         this.user_email = ''
6
+        this.user_media = ''
6 7
         this.is_admin = false
7 8
         this.is_poster = false
8 9
     }

+ 2
- 2
backend/db/data-generator/config.js Ver fichero

@@ -2,8 +2,8 @@ const mockOutputPath = './db/generated/_batch'
2 2
 const magic = 1000
3 3
 
4 4
 // Insert here how many users you would like to generate:
5
-const total = 20
6
-const batchSize = 10
5
+const total = 100
6
+const batchSize = 20
7 7
 
8 8
 // Amount of responses for a complete survey
9 9
 const questions = 13

+ 8
- 1
backend/db/data-generator/index.js Ver fichero

@@ -30,7 +30,7 @@ const write = async (batchNum, outputDataObject) => {
30 30
     await fs.writeFile(`${config.mockOutputPath}_${batchNum}.js`, '', () => {})
31 31
     fs.appendFile(
32 32
         `${config.mockOutputPath}_${batchNum}.js`,
33
-        config.header + 'module.exports = ' + JSON.stringify(outputDataObject),
33
+        config.header + 'export default ' + JSON.stringify(outputDataObject),
34 34
         err => {
35 35
             if (err) {
36 36
                 console.error(err)
@@ -67,6 +67,13 @@ const generateUsers = () => {
67 67
         }
68 68
         user.user_name = random.name() + ' ' + random.name()
69 69
         user.user_email = random.email()
70
+
71
+        var mediaArray = []
72
+        for (let i=0; i < 3; i++) {
73
+            
74
+        }
75
+
76
+        user.user_media = random.media()
70 77
     })
71 78
     console.log('COMPLETED: Generated Users...')
72 79
     return users

+ 15
- 0
backend/db/data-generator/random.js Ver fichero

@@ -30,10 +30,25 @@ const randomName = (length = 4) => {
30 30
     }
31 31
     return str
32 32
 }
33
+const randomMedia = max => {
34
+    const stockimg = [
35
+        'https://i.imgur.com/a4wirDS.png',
36
+        'https://i.imgur.com/F6GxGXG.jpeg',
37
+        'https://i.imgur.com/ekrkdNt.jpeg',
38
+        'https://i.imgur.com/VtMTfDg.jpeg',
39
+        'https://i.imgur.com/9Fwouqm.jpeg',
40
+        'https://i.imgur.com/rOjRCgo.jpeg',
41
+        'https://i.imgur.com/FwSdQww.jpeg',
42
+        'https://i.imgur.com/JjZyzXL.jpeg',
43
+
44
+    ]
45
+    return randomValFrom(stockimg)
46
+}
33 47
 
34 48
 module.exports = {
35 49
     number: randomNumber,
36 50
     valFrom: randomValFrom,
37 51
     email: randomEmail,
38 52
     name: randomName,
53
+    media: randomMedia
39 54
 }

+ 22
- 16
frontend/src/components/ProfileCardList.vue Ver fichero

@@ -3,23 +3,26 @@ section.profile_card_list.w-full
3 3
     .profile_card_list_container.w-full
4 4
         .swipe(
5 5
             :config='config'
6
-            :key='user.id'
7
-            @throwout='swipped(user)'
8
-            v-for='user in users'
6
+            :key='profile.profile_id'
7
+            @throwout='swipped(profile)'
8
+            v-for='profile in profiles'
9 9
         )
10 10
             .card.b-solid.rounded.p-0.bg-cover(
11
-                :style='{ "background-image": `url(${user.avatar})` }'
11
+                :style='{ "background-image": `url(${profile.user.user_media})` }'
12
+                
12 13
             )
13 14
                 .card__content
14
-                    h3.p-1.mv-0.b-solid.rounded {{ user.name }}
15
+                    h3.p-1.mv-0.b-solid.rounded {{ profile.user.user_name }}
15 16
 
16 17
 </template>
17 18
 
18 19
 <script>
20
+
21
+
19 22
 export default {
20 23
     name: 'ProfileCardList',
21 24
     props: {
22
-        users: {
25
+        profiles: {
23 26
             type: [Object, Array],
24 27
             default: () => [
25 28
                 {
@@ -31,8 +34,8 @@ export default {
31 34
             ],
32 35
         },
33 36
         uid: {
34
-            type: String,
35
-            default: '9999',
37
+            type: Number,
38
+            default: 1,
36 39
         },
37 40
     },
38 41
     data: () => ({
@@ -46,24 +49,24 @@ export default {
46 49
     }),
47 50
     computed: {
48 51
         currentCard() {
49
-            return this.users[this.users.length - 1]
52
+            return this.profiles[this.profiles.length - 1]
50 53
         },
51 54
     },
52 55
     created() {
53
-        this.getUser()
56
+        this.getProfile()
54 57
     },
55 58
     methods: {
56 59
         logOut() {},
57 60
         reject() {
58 61
             this.swipped(this.currentCard)
59 62
         },
60
-        swipped(user) {
61
-            const index = this.users.findIndex(u => u.uid == user.uid)
62
-            this.users.splice(index, 1)
63
-            user.id = Date.now() + (Math.random() * 100000).toFixed()
64
-            this.users.unshift({ ...user })
63
+        swipped(profile) {
64
+            const index = this.profiles.findIndex(u => u.uid == profile.uid)
65
+            this.profiles.splice(index, 1)
66
+            profile.id = Date.now() + (Math.random() * 100000).toFixed()
67
+            this.profiles.unshift({ ...profile })
65 68
         },
66
-        getUser() {
69
+        getProfile() {
67 70
             return
68 71
         },
69 72
         onRequest() {
@@ -89,11 +92,14 @@ export default {
89 92
     max-width: 85vw
90 93
     height: 50vh
91 94
     background-position: center
95
+    border-radius: 3vh
96
+    border: 1px solid #fff
92 97
     &_content
93 98
         width: 100%
94 99
         height: 100%
95 100
     h3
96 101
         position: absolute
97 102
         bottom: 0
103
+        color: #fff
98 104
 
99 105
 </style>

+ 1
- 0
frontend/src/components/Sidebar.vue Ver fichero

@@ -1,4 +1,5 @@
1 1
 <template lang="pug">
2
+
2 3
 aside.sidebar.p-1
3 4
     h3 Messages
4 5
     input

+ 56
- 20
frontend/src/views/home.vue Ver fichero

@@ -1,39 +1,75 @@
1 1
 <template lang="pug">
2 2
 article#home
3
-    profile-card-list(:uid='uid' :users='swipables')
3
+    h1(v-if="user") {{ user.user_name }}
4
+    profile-card-list(:uid='mypid' :profiles='swipables')
5
+    
6
+
4 7
 </template>
5 8
 
6 9
 <script>
7 10
 import profileCardList from '../components/ProfileCardList.vue'
11
+import batch20 from '../../../backend/db/generated/_batch_20.js'
8 12
 
9 13
 export default {
10 14
     name: 'HomeView',
11 15
     components: { profileCardList },
12 16
     data: () => ({
13
-        swipables: [],
14
-        uid: null,
17
+        swipables: [   
18
+            // { 
19
+            //     user_id: 1, 
20
+            //     user: {
21
+            //         user_id: 20,
22
+            //         user_name: 'wravu pdjak',
23
+            //         user_email: '3vypx3qyj@aol.com',
24
+            //         is_admin: false,
25
+            //         is_poster: 1,
26
+            //     }, 
27
+            //     profile_id: 1 
28
+            // },
29
+        ],
30
+        user: null,
31
+        mypid: null,
15 32
     }),
16 33
     created() {
17
-        // this.uid = auth.currentUser?.uid || "99999";
18
-        this.uid = '99999'
19
-        this.getUsers()
34
+        // this.mypid = auth.currentUser?.mypid || "99999";
35
+        this.mypid = 21
36
+        this.getBatch()
37
+        const myProfile = this.getProfilesfor(this.mypid)
38
+        this.user = this.getUserfromProfile(myProfile)
39
+        console.log('this.user', this.user)
20 40
     },
21 41
     methods: {
22
-        getUsers() {
23
-            const users = [
24
-                {
25
-                    name: 'bob',
26
-                    id: 1234,
27
-                    metadata: { age: '21', rawMetadata: 'Some Text Here!' },
28
-                },
29
-                {
30
-                    name: 'rob',
31
-                    id: 1235,
32
-                    metadata: { age: '21', rawMetadata: 'Some Text Here!' },
33
-                },
34
-            ]
35
-            this.swipables = users
42
+        getBatch() {
43
+            const profiles = batch20.profiles
44
+            // .map is more readable
45
+            this.swipables = profiles.map((profile) => {
46
+                profile.user = this.getUserfromProfile(profile)
47
+                return profile
48
+            })
49
+            // for loop is faster
50
+            // const myList = []
51
+            // for (let profile in profiles) {
52
+            //     profile.user = this.getUserfromProfile(profile)
53
+            //     myList.push(profile)
54
+            // }
55
+            // this.swipables = myList
56
+            // before you store in 31, save user info per profile
57
+        },
58
+        getProfilesfor(pid) {
59
+            const profilesfromBatch = batch20.profiles
60
+            const profiles = profilesfromBatch.filter((profile) => {
61
+                return profile.profile_id === pid
62
+            })
63
+            return profiles[0]
36 64
         },
65
+        getUserfromProfile(profile) {
66
+            const users = batch20.users
67
+            const usersProfile = users.filter((user) => {
68
+                return user.user_id === profile.user_id
69
+            })
70
+            return usersProfile[0]
71
+        }
72
+
37 73
     },
38 74
 }
39 75
 </script>

Loading…
Cancelar
Guardar