Add link field to collection and fix the visited counter in collection page

This commit is contained in:
Sean Morley
2024-10-07 23:16:27 -04:00
parent 7d9bc16588
commit 1e61032692
8 changed files with 68 additions and 14 deletions

View File

@@ -53,6 +53,11 @@ export const actions: Actions = {
const description = formData.get('description') as string | null;
const start_date = formData.get('start_date') as string | null;
const end_date = formData.get('end_date') as string | null;
let link = formData.get('link') as string | null;
if (link) {
link = checkLink(link);
}
if (!name) {
return {
@@ -66,6 +71,7 @@ export const actions: Actions = {
formDataToSend.append('description', description || '');
formDataToSend.append('start_date', start_date || '');
formDataToSend.append('end_date', end_date || '');
formDataToSend.append('link', link || '');
let auth = event.cookies.get('auth');
if (!auth) {
@@ -142,6 +148,7 @@ export const actions: Actions = {
let is_public = formData.get('is_public') as string | null | boolean;
const start_date = formData.get('start_date') as string | null;
const end_date = formData.get('end_date') as string | null;
let link = formData.get('link') as string | null;
if (is_public) {
is_public = true;
@@ -149,6 +156,10 @@ export const actions: Actions = {
is_public = false;
}
if (link) {
link = checkLink(link);
}
if (!name) {
return {
status: 400,
@@ -162,6 +173,7 @@ export const actions: Actions = {
formDataToSend.append('is_public', is_public.toString());
formDataToSend.append('start_date', start_date || '');
formDataToSend.append('end_date', end_date || '');
formDataToSend.append('link', link || '');
let auth = event.cookies.get('auth');

View File

@@ -20,7 +20,8 @@
groupAdventuresByDate,
groupNotesByDate,
groupTransportationsByDate,
groupChecklistsByDate
groupChecklistsByDate,
isAdventureVisited
} from '$lib';
import ChecklistCard from '$lib/components/ChecklistCard.svelte';
import ChecklistModal from '$lib/components/ChecklistModal.svelte';
@@ -43,8 +44,8 @@
let numberOfDays: number = NaN;
$: {
numAdventures = adventures.filter((a) => a.type === 'visited' || a.type === 'planned').length;
numVisited = adventures.filter((a) => a.type === 'visited').length;
numAdventures = adventures.length;
numVisited = adventures.filter(isAdventureVisited).length;
}
let notFound: boolean = false;
@@ -371,6 +372,14 @@
{#if collection.name}
<h1 class="text-center font-extrabold text-4xl mb-2">{collection.name}</h1>
{/if}
{#if collection.link}
<div class="flex items-center justify-center mb-2">
<a href={collection.link} target="_blank" rel="noopener noreferrer" class="btn btn-primary">
Visit Link
</a>
</div>
{/if}
{#if collection.description}
<p class="text-center text-lg mb-2">{collection.description}</p>
{/if}