Skip to content

Commit 17ae571

Browse files
committed
send location to backend when loading screen appears
1 parent a5869d5 commit 17ae571

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
import SingleChoice from '@/components/app/onboarding/SingleChoice.vue';
1616
1717
export default {
18-
props: ['slide'],
18+
props: ['slide', 'bus'],
19+
data: () => ({
20+
locationData: {},
21+
}),
1922
components: {
2023
SingleChoice,
2124
},
@@ -37,18 +40,22 @@ export default {
3740
async locationAllowed(position) {
3841
const { latitude } = position.coords;
3942
const { longitude } = position.coords;
40-
await this.sendLocation({ lat: latitude, lng: longitude, ip: '0.0.0.0' });
43+
this.locationData = { lat: latitude, lng: longitude, ip: '0.0.0.0' };
44+
this.$emit('nextSlide');
4145
},
4246
async locationDenied() {
4347
let ipRequest = await fetch('https://api.ipify.org?format=json');
4448
ipRequest = await ipRequest.json();
4549
const { ip } = ipRequest;
46-
await this.sendLocation({ ip });
47-
},
48-
async sendLocation(data) {
49-
await this.$http.put('/profile/edit/geolocation', data);
50+
this.locationData = { ip };
5051
this.$emit('nextSlide');
5152
},
53+
async sendLocation() {
54+
await this.$http.put('/profile/edit/geolocation', this.locationData);
55+
},
56+
},
57+
mounted() {
58+
this.bus.$on('sendUserLocationToBackend', this.sendLocation);
5259
},
5360
};
5461
</script>

frontend/src/views/app/Onboarding.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
current: slideCurrent,
8787
count: slideCount,
8888
buttonText}"
89+
v-bind:bus="bus"
8990
v-on:nextSlide="nextSlide"
9091
v-if="slideCurrent === 7"></Location>
9192
<SettingUp v-if="slideCurrent === 8"></SettingUp>
@@ -101,6 +102,7 @@ import MainAndSecondaryImagesUpload from '@/components/app/onboarding/MainAndSec
101102
import Textblock from '@/components/app/onboarding/Textblock.vue';
102103
import Location from "@/components/app/onboarding/Location.vue";
103104
import SettingUp from "@/components/app/onboarding/SettingUp.vue";
105+
import Vue from 'vue';
104106
105107
export default {
106108
components: {
@@ -117,6 +119,7 @@ export default {
117119
slideCount: 7,
118120
userData: {},
119121
userUploadedImagesCount: 0,
122+
bus: new Vue(),
120123
}),
121124
methods: {
122125
saveInput(...args) {
@@ -132,6 +135,7 @@ export default {
132135
async nextSlide() {
133136
if (this.slideCurrent === this.slideCount) {
134137
this.slideCurrent += 1;
138+
await this.bus.$emit('sendUserLocationToBackend');
135139
await this.$http.post('/profile/complete', this.userData);
136140
await this.$http.get('/recommendations');
137141
await this.$store.dispatch('profileCompleted');

0 commit comments

Comments
 (0)