From 3a024e1e18b844cbd587ebb3277f4bcde2b25399 Mon Sep 17 00:00:00 2001
From: Sean Morley
Date: Fri, 3 Jan 2025 12:05:02 -0500
Subject: [PATCH] feat: implement logic to determine if an adventure will be
marked as visited based on visit dates
---
.../src/lib/components/AdventureModal.svelte | 49 +++++++++++++++----
1 file changed, 39 insertions(+), 10 deletions(-)
diff --git a/frontend/src/lib/components/AdventureModal.svelte b/frontend/src/lib/components/AdventureModal.svelte
index 138ff3d..584f72d 100644
--- a/frontend/src/lib/components/AdventureModal.svelte
+++ b/frontend/src/lib/components/AdventureModal.svelte
@@ -164,6 +164,33 @@
close();
}
+ let willBeMarkedVisited: boolean = false;
+
+ $: {
+ willBeMarkedVisited = false; // Reset before evaluating
+
+ const today = new Date(); // Cache today's date to avoid redundant calculations
+
+ for (const visit of adventure.visits) {
+ const startDate = new Date(visit.start_date);
+ const endDate = visit.end_date ? new Date(visit.end_date) : null;
+
+ // If the visit has both a start date and an end date, check if it started by today
+ if (startDate && endDate && startDate <= today) {
+ willBeMarkedVisited = true;
+ break; // Exit the loop since we've determined the result
+ }
+
+ // If the visit has a start date but no end date, check if it started by today
+ if (startDate && !endDate && startDate <= today) {
+ willBeMarkedVisited = true;
+ break; // Exit the loop since we've determined the result
+ }
+ }
+
+ console.log('WMBV:', willBeMarkedVisited);
+ }
+
let previousCoords: { lat: number; lng: number } | null = null;
$: if (markers.length > 0) {
@@ -515,6 +542,9 @@
addToast('error', $t('adventures.adventure_update_error'));
}
}
+ if (adventure.is_visited) {
+ markVisited();
+ }
}
@@ -761,7 +791,12 @@ it would also work to just use on:click on the MapLibre component itself. -->
: $t('adventures.not_visited')}
{$t('adventures.mark_region_as_visited', {
- values: {
- region: reverseGeocodePlace.region,
- country: reverseGeocodePlace.country
- }
- })}{reverseGeocodePlace.region},
+ {reverseGeocodePlace.country} will be marked as visited once the adventure is
+ saved.
-