mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-25 07:49:37 +02:00
Add mark_visited_region action to ReverseGeocodeViewSet and update AdventureModal for region tracking
This commit is contained in:
parent
a7a49227c4
commit
b60455b50a
3 changed files with 65 additions and 35 deletions
|
@ -28,7 +28,6 @@
|
|||
import ActivityComplete from './ActivityComplete.svelte';
|
||||
import { appVersion } from '$lib/config';
|
||||
import { ADVENTURE_TYPES } from '$lib';
|
||||
import RegionCard from './RegionCard.svelte';
|
||||
|
||||
let wikiError: string = '';
|
||||
|
||||
|
@ -82,6 +81,12 @@
|
|||
|
||||
images = adventure.images || [];
|
||||
|
||||
if (longitude && latitude) {
|
||||
adventure.latitude = latitude;
|
||||
adventure.longitude = longitude;
|
||||
reverseGeocode();
|
||||
}
|
||||
|
||||
if (adventure.longitude && adventure.latitude) {
|
||||
markers = [];
|
||||
markers = [
|
||||
|
@ -94,12 +99,6 @@
|
|||
];
|
||||
}
|
||||
|
||||
if (longitude && latitude) {
|
||||
adventure.latitude = latitude;
|
||||
adventure.longitude = longitude;
|
||||
reverseGeocode();
|
||||
}
|
||||
|
||||
$: {
|
||||
if (!adventure.rating) {
|
||||
adventure.rating = NaN;
|
||||
|
@ -143,23 +142,24 @@
|
|||
close();
|
||||
}
|
||||
|
||||
let previousCoords: { lat: number; lng: number } | null = null;
|
||||
|
||||
$: if (markers.length > 0) {
|
||||
adventure.latitude = Math.round(markers[0].lngLat.lat * 1e6) / 1e6;
|
||||
adventure.longitude = Math.round(markers[0].lngLat.lng * 1e6) / 1e6;
|
||||
if (!adventure.location) {
|
||||
adventure.location = markers[0].location;
|
||||
const newLat = Math.round(markers[0].lngLat.lat * 1e6) / 1e6;
|
||||
const newLng = Math.round(markers[0].lngLat.lng * 1e6) / 1e6;
|
||||
|
||||
if (!previousCoords || previousCoords.lat !== newLat || previousCoords.lng !== newLng) {
|
||||
adventure.latitude = newLat;
|
||||
adventure.longitude = newLng;
|
||||
previousCoords = { lat: newLat, lng: newLng };
|
||||
reverseGeocode();
|
||||
}
|
||||
|
||||
if (!adventure.name) {
|
||||
adventure.name = markers[0].name;
|
||||
}
|
||||
}
|
||||
|
||||
$: {
|
||||
if (adventure.longitude && adventure.latitude) {
|
||||
reverseGeocode();
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchImage() {
|
||||
let res = await fetch(url);
|
||||
let data = await res.blob();
|
||||
|
|
|
@ -44,20 +44,20 @@
|
|||
// URL.revokeObjectURL(url);
|
||||
// }
|
||||
|
||||
// async function checkVisitedRegions() {
|
||||
// let res = await fetch('/api/countries/region_check_all_adventures/', {
|
||||
// method: 'POST',
|
||||
// headers: {
|
||||
// 'Content-Type': 'application/json'
|
||||
// }
|
||||
// });
|
||||
// let data = await res.json();
|
||||
// if (res.ok) {
|
||||
// addToast('success', `${data.regions_visited} regions updated`);
|
||||
// } else {
|
||||
// addToast('error', 'Error updating visited regions');
|
||||
// }
|
||||
// }
|
||||
async function checkVisitedRegions() {
|
||||
let res = await fetch('/api/reverse-geocode/mark_visited_region/', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
let data = await res.json();
|
||||
if (res.ok) {
|
||||
addToast('success', `${data.new_regions} regions updated`);
|
||||
} else {
|
||||
addToast('error', 'Error updating visited regions');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<h1 class="text-center font-extrabold text-4xl mb-6">{$t('settings.settings_page')}</h1>
|
||||
|
@ -182,7 +182,7 @@
|
|||
</form>
|
||||
</div>
|
||||
|
||||
<!-- <div class="flex flex-col items-center mt-4">
|
||||
<div class="flex flex-col items-center mt-4">
|
||||
<h1 class="text-center font-extrabold text-xl mt-4 mb-2">Visited Region Check</h1>
|
||||
<p>
|
||||
By selecting this, the server will check all of your visited adventures and mark the regions
|
||||
|
@ -193,7 +193,7 @@
|
|||
>
|
||||
<p>This may take longer depending on the number of adventures you have.</p>
|
||||
</div>
|
||||
|
||||
<!--
|
||||
<div class="flex flex-col items-center mt-4">
|
||||
<h1 class="text-center font-extrabold text-xl mt-4 mb-2">Data Export</h1>
|
||||
<button class="btn btn-neutral mb-4" on:click={exportAdventures}> Export to JSON </button>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue