1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-08-03 20:25:18 +02:00

Update map filtering

This commit is contained in:
Sean Morley 2024-10-04 09:49:35 -04:00
parent 5ff4f66fdb
commit d0791faad5
5 changed files with 56 additions and 26 deletions

View file

@ -19,7 +19,7 @@
import DotsHorizontal from '~icons/mdi/dots-horizontal';
import DeleteWarning from './DeleteWarning.svelte';
import ImageDisplayModal from './ImageDisplayModal.svelte';
import { typeToString } from '$lib';
import { isAdventureVisited, typeToString } from '$lib';
export let type: string;
export let user: User | null;
@ -28,7 +28,6 @@
let isCollectionModalOpen: boolean = false;
let isWarningModalOpen: boolean = false;
let keyword: string = '';
let image_url: string | null = null;
export let adventure: Adventure;
@ -201,7 +200,7 @@
</div>
<div>
<div class="badge badge-primary">{typeToString(adventure.type)}</div>
<div class="badge badge-success">{adventure.visits.length > 0 ? 'Visited' : 'Planned'}</div>
<div class="badge badge-success">{isAdventureVisited(adventure) ? 'Visited' : 'Planned'}</div>
<div class="badge badge-secondary">{adventure.is_public ? 'Public' : 'Private'}</div>
</div>
{#if adventure.location && adventure.location !== ''}

View file

@ -27,13 +27,12 @@
}
</script>
<div class="collapse collapse-plus bg-base-300 mb-4 overflow-visible">
<div class="collapse collapse-plus mb-4">
<input type="checkbox" />
<div class="collapse-title text-xl font-medium">Category Filter</div>
<div class="collapse-content">
<button class="btn btn-wide mb-1 btn-neutral-300" on:click={clearTypes}>Clear</button>
<div class="collapse-title text-xl bg-base-300 font-medium">Category Filter</div>
<div class="collapse-content bg-base-300">
<button class="btn btn-wide btn-neutral-300" on:click={clearTypes}>Clear</button>
{#each ADVENTURE_TYPES as type}
<!-- checkbox for each -->
<li>
<label class="cursor-pointer">
<input

View file

@ -252,3 +252,22 @@ export function typeToString(type: string) {
return 'Unknown';
}
}
/**
* 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.some((visit) => {
const visitStartTime = new Date(visit.start_date).getTime();
return visit.start_date && visitStartTime <= currentTime;
});
}