-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: detección geo, mensajes y errores (#111)
* chore: agrega servicio sentry * fix: mejora logica y validaciones servicio user * chore: mueve servicios a carpeta * fix: mejoras menores helper * fix: mejora validacion inicial app * fix: mejora action para obtener geo * chore: actualiza deps * chore: remueve validacion inicial route * fix: mejoras validaciones y mensajes de error * chore: agrega param save-exact * fix: mejoras en el retorno de codigos de errores * chore: modifica orden de carga de action userGeoData
- Loading branch information
Showing
15 changed files
with
366 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
NODE_ENV=development | ||
VUE_APP_TITLE=GrowlerApp | ||
VUE_APP_GRAPHQL_API=https://api-growlerapp.herokuapp.com/graphql | ||
VUE_APP_GOOGLE_MAPS_KEY= | ||
VUE_APP_GOOGLE_MAPS_KEY= | ||
VUE_APP_SENTRY_SLUG='' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
package-lock=false | ||
save-exact=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import Vue from 'vue' | ||
import * as Sentry from '@sentry/browser' | ||
import * as Integrations from '@sentry/integrations' | ||
|
||
if (process.env.NODE_ENV === 'production') { | ||
Sentry.init({ | ||
dsn: process.env.VUE_APP_SENTRY_SLUG, | ||
integrations: [new Integrations.Vue({ Vue, attachProps: true })] | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import { isJSON } from '@/helpers' | ||
|
||
/** | ||
* Parse any errors from PositionError callback | ||
* @param {object} error | ||
* @return {object} | ||
*/ | ||
const parsePositionError = error => { | ||
switch (error.code) { | ||
case error.PERMISSION_DENIED: | ||
return { | ||
code: 1, | ||
message: 'User denied the request for geolocation.' | ||
} | ||
case error.POSITION_UNAVAILABLE: | ||
return { | ||
code: 2, | ||
message: 'Location information is unavailable.' | ||
} | ||
case error.TIMEOUT: | ||
return { | ||
code: 3, | ||
message: 'The request to get user location timed out.' | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Get user geo from device | ||
* @return {Promise<Object>} | ||
* https://developer.mozilla.org/en-US/docs/Web/API/Geolocation_API | ||
*/ | ||
const getUserGeoDataFromDevice = () => { | ||
return new Promise((resolve, reject) => { | ||
if ('geolocation' in navigator) { | ||
navigator.geolocation.getCurrentPosition(({ coords }) => | ||
resolve(coords), error => reject(parsePositionError(error)) | ||
) | ||
} | ||
}) | ||
} | ||
|
||
/** | ||
* Fetch user geo data | ||
* @return {object} user geo data | ||
*/ | ||
const fetchUserGeoData = () => { | ||
return new Promise(async (resolve, reject) => { | ||
try { | ||
let data = await getUserGeoDataFromDevice() | ||
data = { | ||
lat: data.latitude, | ||
long: data.longitude | ||
} | ||
setUserGeoDataToStorage(data) | ||
resolve(data) | ||
} catch (error) { | ||
// eslint-disable-next-line prefer-promise-reject-errors | ||
reject(error) | ||
} | ||
}) | ||
} | ||
|
||
/** | ||
* Set flag if user has joined to app | ||
*/ | ||
const setUserHasJoined = () => { | ||
localStorage.setItem('userHasJoined', JSON.stringify(true)) | ||
} | ||
|
||
/** | ||
* Check if user has joined to app | ||
*/ | ||
const checkHasJoined = () => { | ||
return !!localStorage.getItem('userHasJoined') | ||
} | ||
|
||
/** | ||
* Set user geo data | ||
* @param {object} data | ||
*/ | ||
const setUserGeoDataToStorage = data => { | ||
localStorage.setItem('userGeoData', JSON.stringify(data)) | ||
} | ||
|
||
/** | ||
* Get user geo data from localstorage | ||
*/ | ||
const getUserGeoDataFromStorage = () => { | ||
try { | ||
return JSON.parse(localStorage.getItem('userGeoData')) | ||
} catch (err) { | ||
return null | ||
} | ||
} | ||
|
||
/** | ||
* Check if user has geo data | ||
*/ | ||
const checkUserGeoData = () => { | ||
const data = getUserGeoDataFromStorage() | ||
return isJSON(data) && data.lat && data.long | ||
} | ||
|
||
/** | ||
* Get user data from storage or user device | ||
* @param {boolean} force | ||
* @return {Promise<object>} user geo data | ||
*/ | ||
const getUserData = (force = false) => { | ||
try { | ||
if (force) { | ||
return fetchUserGeoData() | ||
} else { | ||
return checkUserGeoData() | ||
? getUserGeoDataFromStorage() | ||
: fetchUserGeoData() | ||
} | ||
} catch (error) { | ||
return error | ||
} | ||
} | ||
|
||
export { | ||
getUserData, | ||
checkUserGeoData, | ||
checkHasJoined, | ||
setUserHasJoined, | ||
fetchUserGeoData | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.