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

chore: Add created_at field to Adventure and Collection models

This commit is contained in:
Sean Morley 2024-07-18 15:48:14 -04:00
parent 040d5a755f
commit 704eb6f6de
6 changed files with 87 additions and 4 deletions

View file

@ -25,6 +25,7 @@ export type Adventure = {
latitude: number | null;
longitude: number | null;
is_public: boolean;
created_at?: string;
};
export type Country = {
@ -61,6 +62,7 @@ export type Collection = {
description: string;
is_public: boolean;
adventures: Adventure[];
created_at?: string;
};
export type OpenStreetMapPlace = {

View file

@ -300,6 +300,15 @@
/>
<br />
<p class="text-md font-semibold mt-2 mb-2">Order By</p>
<label for="name">Created At</label>
<input
type="radio"
name="order_by"
id="created_at"
class="radio radio-primary"
checked
value="created_at"
/>
<label for="name">Name</label>
<input
type="radio"

View file

@ -1,8 +1,10 @@
<script lang="ts">
import AdventureCard from '$lib/components/AdventureCard.svelte';
import NotFound from '$lib/components/NotFound.svelte';
import type { Adventure } from '$lib/types';
import type { Adventure, OpenStreetMapPlace } from '$lib/types';
import { onMount } from 'svelte';
import type { PageData } from './$types';
import { page } from '$app/stores';
export let data: PageData;
@ -10,6 +12,29 @@
adventures = adventures.filter((adventure) => adventure.id !== event.detail);
}
let osmResults: OpenStreetMapPlace[] = [];
let query: string | null = '';
onMount(() => {
const urlParams = new URLSearchParams(window.location.search);
query = urlParams.get('query');
fetchData();
});
async function fetchData() {
let res = await fetch(`https://nominatim.openstreetmap.org/search?q=${query}&format=jsonv2`);
const data = await res.json();
osmResults = data;
}
onMount(async () => {
let res = await fetch(`https://nominatim.openstreetmap.org/search?q=${query}&format=jsonv2`);
const data = await res.json();
osmResults = data;
});
console.log(data);
let adventures: Adventure[] = [];
if (data.props) {
@ -17,12 +42,24 @@
}
</script>
{#if adventures.length === 0}
{#if adventures.length === 0 && osmResults.length === 0}
<NotFound error={data.error} />
{:else}
<h2 class="text-center font-bold text-2xl mb-4">AdventureLog Results</h2>
<div class="flex flex-wrap gap-4 mr-4 justify-center content-center">
{#each adventures as adventure}
<AdventureCard type={adventure.type} {adventure} on:delete={deleteAdventure} />
{/each}
</div>
<div class="divider"></div>
<h2 class="text-center font-bold text-2xl mb-4">Online Results</h2>
<div class="flex flex-wrap gap-4 mr-4 justify-center content-center">
{#each osmResults as result}
<div class="bg-base-300 rounded-lg shadow-md p-4 w-96">
<h2 class="text-xl font-bold">{result.display_name}</h2>
<p>{result.type}</p>
<p>{result.lat}, {result.lon}</p>
</div>
{/each}
</div>
{/if}