Skip to content

Commit

Permalink
feat: implement logic to determine if an adventure will be marked as …
Browse files Browse the repository at this point in the history
…visited based on visit dates
  • Loading branch information
seanmorley15 committed Jan 3, 2025
1 parent 57e367d commit 3a024e1
Showing 1 changed file with 39 additions and 10 deletions.
49 changes: 39 additions & 10 deletions frontend/src/lib/components/AdventureModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -515,6 +542,9 @@
addToast('error', $t('adventures.adventure_update_error'));
}
}
if (adventure.is_visited) {
markVisited();
}
}
</script>

Expand Down Expand Up @@ -761,7 +791,12 @@ it would also work to just use on:click on the MapLibre component itself. -->
: $t('adventures.not_visited')}
</p>
</div>
{#if !reverseGeocodePlace.is_visited}
{#if !reverseGeocodePlace.is_visited && !willBeMarkedVisited}
<button type="button" class="btn btn-neutral" on:click={markVisited}>
{$t('adventures.mark_visited')}
</button>
{/if}
{#if !reverseGeocodePlace.is_visited && willBeMarkedVisited}
<div role="alert" class="alert alert-info mt-2">
<svg
xmlns="http://www.w3.org/2000/svg"
Expand All @@ -777,16 +812,10 @@ it would also work to just use on:click on the MapLibre component itself. -->
></path>
</svg>
<span
>{$t('adventures.mark_region_as_visited', {
values: {
region: reverseGeocodePlace.region,
country: reverseGeocodePlace.country
}
})}</span
>{reverseGeocodePlace.region},
{reverseGeocodePlace.country} will be marked as visited once the adventure is
saved.</span
>
<button type="button" class="btn btn-neutral" on:click={markVisited}>
{$t('adventures.mark_visited')}
</button>
</div>
{/if}
{/if}
Expand Down

0 comments on commit 3a024e1

Please sign in to comment.