Skip to content

Commit 084e5f8

Browse files
committed
WIP step before loading screen
1 parent 9ffd1d2 commit 084e5f8

File tree

5 files changed

+104
-3
lines changed

5 files changed

+104
-3
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<template>
2+
<SingleChoice
3+
v-bind:slide="{
4+
key: 'location',
5+
current: slide.current,
6+
count: slide.count,
7+
header: 'Location',
8+
subheader: 'Would you like to share your location to get potential matches closer to you?',
9+
options: ['yes', 'no'],
10+
buttonText: slide.buttonText}"
11+
v-on:saveInput="saveLocation"></SingleChoice>
12+
</template>
13+
14+
<script>
15+
import SingleChoice from '@/components/app/onboarding/SingleChoice.vue';
16+
17+
export default {
18+
props: ['slide'],
19+
components: {
20+
SingleChoice,
21+
},
22+
methods: {
23+
async saveLocation(...args) {
24+
const [key, value] = args;
25+
if (key === 'location') {
26+
if (value === 'yes') {
27+
navigator.geolocation.getCurrentPosition(
28+
this.locationAllowed,
29+
this.locationDenied,
30+
{ enableHighAccuracy: true },
31+
);
32+
} else {
33+
await this.locationDenied();
34+
}
35+
}
36+
},
37+
async locationAllowed(position) {
38+
const { latitude } = position.coords;
39+
const { longitude } = position.coords;
40+
await this.sendLocation({ lat: latitude, lng: longitude, ip: '0.0.0.0' });
41+
},
42+
async locationDenied() {
43+
let ipRequest = await fetch('https://api.ipify.org?format=json');
44+
ipRequest = await ipRequest.json();
45+
const { ip } = ipRequest;
46+
await this.sendLocation({ ip });
47+
},
48+
async sendLocation(data) {
49+
await this.$http.put('/profile/edit/geolocation', data);
50+
this.$emit('nextSlide');
51+
},
52+
},
53+
};
54+
</script>

frontend/src/components/app/onboarding/SingleChoice.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<section class="onboarding-sub-container">
44
<h1 class="text-gray-matcha">{{slide.current}} / {{slide.count}}</h1>
55
<h1 class="onboarding-sub-container-content-heading leading-none">{{slide.header}}</h1>
6+
<p v-if="slide.subheader" class="text-gray-matcha text-center max-w-xs w-full mt-4">{{slide.subheader}}</p>
67
<div v-bind:class="{'onboarding-selection-button-container': true, 'justify-center': slide.options.length < 5}">
78
<SelectionButton v-for="(option, index) in slide.options" :key="index + option"
89
v-bind:val="option"

frontend/src/router/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import AccountVerifiedError from '../views/auth/AccountVerifiedError.vue';
99
import ResetPassword from '../views/auth/ResetPassword.vue';
1010
import ResetPasswordError from '../views/auth/ResetPasswordError.vue';
1111
import Onboarding from '../views/app/Onboarding.vue';
12+
import Browse from '../views/app/Browse.vue';
1213
import store from '../store/index';
1314

1415
Vue.use(VueRouter);
@@ -29,6 +30,17 @@ function notLoggedInRedirectLogin(to, from, next) {
2930
}
3031
}
3132

33+
function blockRepeatedOnboarding(to, from, next) {
34+
const user = store.getters.getLoggedInUser;
35+
if (user && user.is_profile_completed) {
36+
next('/browse');
37+
} else if (user && !user.is_profile_completed) {
38+
next();
39+
} else {
40+
next('/accounts/signin');
41+
}
42+
}
43+
3244
const routes = [
3345
{
3446
path: '/',
@@ -81,6 +93,12 @@ const routes = [
8193
path: '/onboarding',
8294
name: 'Onboarding',
8395
component: Onboarding,
96+
beforeEnter: blockRepeatedOnboarding,
97+
},
98+
{
99+
path: '/browse',
100+
name: Browse,
101+
component: Browse,
84102
beforeEnter: notLoggedInRedirectLogin,
85103
},
86104
];

frontend/src/store/modules/user.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ const mutations = {
1717
logout(state) {
1818
state.user = null;
1919
},
20+
profileCompleted(state) {
21+
state.user.is_profile_completed = true;
22+
},
2023
};
2124

2225
const actions = {
@@ -26,6 +29,9 @@ const actions = {
2629
logout(state) {
2730
state.commit('logout');
2831
},
32+
profileCompleted(state) {
33+
state.commit('profileCompleted');
34+
},
2935
};
3036

3137
export default {

frontend/src/views/app/Onboarding.vue

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@
8080
buttonText}"
8181
v-on:saveInput="saveInput"
8282
v-if="slideCurrent === 6"></Textblock>
83+
<Location
84+
v-bind:slide="{
85+
key: 'location',
86+
current: slideCurrent,
87+
count: slideCount,
88+
buttonText}"
89+
v-on:nextSlide="nextSlide"
90+
v-if="slideCurrent === 7"></Location>
8391
</div>
8492
</template>
8593

@@ -90,6 +98,7 @@ import SingleChoice from '@/components/app/onboarding/SingleChoice.vue';
9098
import MultipleChoice from '@/components/app/onboarding/MultipleChoice.vue';
9199
import MainAndSecondaryImagesUpload from '@/components/app/onboarding/MainAndSecondaryImagesUpload.vue';
92100
import Textblock from '@/components/app/onboarding/Textblock.vue';
101+
import Location from "@/components/app/onboarding/Location";
93102
94103
export default {
95104
components: {
@@ -98,24 +107,30 @@ export default {
98107
MultipleChoice,
99108
MainAndSecondaryImagesUpload,
100109
Textblock,
110+
Location,
101111
},
102112
data: () => ({
103113
slideCurrent: 0,
104-
slideCount: 6,
114+
slideCount: 7,
105115
userData: {},
106116
}),
107117
methods: {
108118
saveInput(...args) {
109119
let [key, value] = args;
110120
if (key === 'birthdate') {
111121
value = this.formatBirthdate(value);
122+
} else if (key === 'location') {
123+
value = this.processLocation(value);
112124
}
113125
this.userData[key] = value;
114126
this.nextSlide();
115127
},
116-
nextSlide() {
128+
async nextSlide() {
117129
if (this.slideCurrent === this.slideCount) {
118-
this.$router.push('/browse');
130+
await this.$http.post('/profile/complete', this.userData);
131+
await this.$store.dispatch('profileCompleted');
132+
console.log('setting up profile might take a while');
133+
// await this.$router.push('/browse');
119134
}
120135
if (this.slideCurrent < this.slideCount) {
121136
this.slideCurrent += 1;
@@ -132,6 +147,13 @@ export default {
132147
let birthyear = new Date().getFullYear() - age;
133148
return '01/01/' + birthyear;
134149
},
150+
processLocation(allowAccessToLocation) {
151+
if (allowAccessToLocation) {
152+
navigator.geolocation.getCurrentPosition(function(position) {
153+
console.log(position.coords.latitude + position.coords.longitude);
154+
});
155+
}
156+
}
135157
},
136158
computed: {
137159
buttonText() {

0 commit comments

Comments
 (0)