is visited

This commit is contained in:
Sean Morley
2024-10-31 09:51:04 -04:00
parent 9d42dbac98
commit 727daf0cfd
10 changed files with 284 additions and 281 deletions

View File

@@ -16,7 +16,6 @@
import CollectionLink from './CollectionLink.svelte';
import DotsHorizontal from '~icons/mdi/dots-horizontal';
import DeleteWarning from './DeleteWarning.svelte';
import { isAdventureVisited } from '$lib';
import CardCarousel from './CardCarousel.svelte';
import { t } from 'svelte-i18n';
@@ -132,7 +131,7 @@
<div>
<div class="badge badge-primary">{$t(`adventures.activities.${adventure.type}`)}</div>
<div class="badge badge-success">
{isAdventureVisited(adventure) ? $t('adventures.visited') : $t('adventures.planned')}
{adventure.is_visited ? $t('adventures.visited') : $t('adventures.planned')}
</div>
<div class="badge badge-secondary">
{adventure.is_public ? $t('adventures.public') : $t('adventures.private')}

View File

@@ -28,6 +28,7 @@
import ActivityComplete from './ActivityComplete.svelte';
import { appVersion } from '$lib/config';
import { ADVENTURE_TYPES } from '$lib';
import RegionCard from './RegionCard.svelte';
let wikiError: string = '';
@@ -629,7 +630,11 @@ it would also work to just use on:click on the MapLibre component itself. -->
{#if reverseGeocodePlace}
<div class="mt-2">
<p>{reverseGeocodePlace.region}, {reverseGeocodePlace.country}</p>
<p>{reverseGeocodePlace.is_visited ? 'Visited' : 'Not Visited'}</p>
<p>
{reverseGeocodePlace.is_visited
? $t('adventures.visited')
: $t('adventures.not_visited')}
</p>
</div>
{#if !reverseGeocodePlace.is_visited}
<div role="alert" class="alert alert-info mt-2">
@@ -647,10 +652,15 @@ it would also work to just use on:click on the MapLibre component itself. -->
></path>
</svg>
<span
>Mark region {reverseGeocodePlace.region}, {reverseGeocodePlace.country} as visited?</span
>{$t('adventures.mark_region_as_visited', {
values: {
region: reverseGeocodePlace.region,
country: reverseGeocodePlace.country
}
})}</span
>
<button type="button" class="btn btn-neutral" on:click={markVisited}>
Mark as Visited
{$t('adventures.mark_visited')}
</button>
</div>
{/if}

View File

@@ -253,28 +253,6 @@ export let ADVENTURE_TYPES = [
{ type: 'other', label: 'Other' }
];
/**
* Checks if an adventure has been visited.
*
* This function determines if the `adventure.visits` array contains at least one visit
* with a `start_date` that is before the current date.
*
* @param adventure - The adventure object to check.
* @returns `true` if the adventure has been visited, otherwise `false`.
*/
export function isAdventureVisited(adventure: Adventure) {
const currentTime = Date.now();
// Check if any visit's start_date is before the current time.
return (
adventure.visits &&
adventure.visits.some((visit) => {
const visitStartTime = new Date(visit.start_date).getTime();
return visit.start_date && visitStartTime <= currentTime;
})
);
}
export function getRandomBackground() {
const randomIndex = Math.floor(Math.random() * randomBackgrounds.backgrounds.length);
return randomBackgrounds.backgrounds[randomIndex] as Background;

View File

@@ -37,6 +37,7 @@ export type Adventure = {
is_public: boolean;
created_at?: string | null;
updated_at?: string | null;
is_visited?: boolean;
};
export type Country = {