feat: save search history when sorting pharmacies by distance
This commit is contained in:
@@ -92,6 +92,21 @@ function PublicView({
|
|||||||
setUserPosition({ lat: savedLat, lon: savedLon });
|
setUserPosition({ lat: savedLat, lon: savedLon });
|
||||||
setPositionSource('profile');
|
setPositionSource('profile');
|
||||||
setSortByDistance(true);
|
setSortByDistance(true);
|
||||||
|
// Save to search history
|
||||||
|
try {
|
||||||
|
fetch('/api/search-history', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
credentials: 'include',
|
||||||
|
body: JSON.stringify({
|
||||||
|
address: currentUser?.address,
|
||||||
|
latitude: savedLat,
|
||||||
|
longitude: savedLon,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error saving search history:', err);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (userPosition) {
|
if (userPosition) {
|
||||||
@@ -104,6 +119,21 @@ function PublicView({
|
|||||||
setUserPosition(pos);
|
setUserPosition(pos);
|
||||||
setPositionSource('browser');
|
setPositionSource('browser');
|
||||||
setSortByDistance(true);
|
setSortByDistance(true);
|
||||||
|
// Save to search history
|
||||||
|
try {
|
||||||
|
fetch('/api/search-history', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
credentials: 'include',
|
||||||
|
body: JSON.stringify({
|
||||||
|
address: 'Ubicación actual',
|
||||||
|
latitude: pos.lat,
|
||||||
|
longitude: pos.lon,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error saving search history:', err);
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('[location] error', err);
|
console.error('[location] error', err);
|
||||||
let msg;
|
let msg;
|
||||||
|
|||||||
@@ -120,6 +120,21 @@ function SearchView({ currentUser, onLoginRequest }) {
|
|||||||
setUserPosition({ lat: savedLat, lon: savedLon });
|
setUserPosition({ lat: savedLat, lon: savedLon });
|
||||||
setPositionSource('profile');
|
setPositionSource('profile');
|
||||||
setSortByDistance(true);
|
setSortByDistance(true);
|
||||||
|
// Save to search history
|
||||||
|
try {
|
||||||
|
fetch('/api/search-history', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
credentials: 'include',
|
||||||
|
body: JSON.stringify({
|
||||||
|
address: currentUser?.address,
|
||||||
|
latitude: savedLat,
|
||||||
|
longitude: savedLon,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error saving search history:', err);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (userPosition) {
|
if (userPosition) {
|
||||||
@@ -132,6 +147,21 @@ function SearchView({ currentUser, onLoginRequest }) {
|
|||||||
setUserPosition(pos);
|
setUserPosition(pos);
|
||||||
setPositionSource('browser');
|
setPositionSource('browser');
|
||||||
setSortByDistance(true);
|
setSortByDistance(true);
|
||||||
|
// Save to search history
|
||||||
|
try {
|
||||||
|
fetch('/api/search-history', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
credentials: 'include',
|
||||||
|
body: JSON.stringify({
|
||||||
|
address: 'Ubicación actual',
|
||||||
|
latitude: pos.lat,
|
||||||
|
longitude: pos.lon,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error saving search history:', err);
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
let msg = 'No se pudo obtener tu ubicación';
|
let msg = 'No se pudo obtener tu ubicación';
|
||||||
if (err && typeof err.code === 'number') {
|
if (err && typeof err.code === 'number') {
|
||||||
|
|||||||
Reference in New Issue
Block a user