Update AdventureCard component to include regionId and visited properties, and add country flag support
This commit is contained in:
@@ -89,6 +89,7 @@
|
||||
{#each data.regions as region (region.id)}
|
||||
<AdventureCard
|
||||
type="worldtravelregion"
|
||||
countryCode={data.countrycode}
|
||||
regionId={region.id}
|
||||
name={region.name}
|
||||
on:markVisited={markVisited}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import { db } from '$lib/db/db.server.js';
|
||||
import { userVisitedWorldTravel, worldTravelCountryRegions } from '$lib/db/schema.js';
|
||||
import { and, eq } from 'drizzle-orm';
|
||||
import type { PageServerLoad } from './$types';
|
||||
import InfoModal from '$lib/components/InfoModal.svelte';
|
||||
|
||||
export const load: PageServerLoad = async ({ params, locals }) => {
|
||||
const { regioncode } = params;
|
||||
|
||||
let info = await db
|
||||
.select({data: worldTravelCountryRegions})
|
||||
.from(worldTravelCountryRegions)
|
||||
.where(eq(worldTravelCountryRegions.id, regioncode))
|
||||
.limit(1)
|
||||
.execute();
|
||||
|
||||
let visited = false;
|
||||
if (locals.user) {
|
||||
let userVisited = await db
|
||||
.select({data: userVisitedWorldTravel})
|
||||
.from(userVisitedWorldTravel)
|
||||
.where(and(eq(userVisitedWorldTravel.userId, locals.user.id), eq(userVisitedWorldTravel.region_id, regioncode)))
|
||||
.limit(1)
|
||||
.execute();
|
||||
if (userVisited.length !== 0) {
|
||||
visited = true;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
info : info[0],
|
||||
visited : visited,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<script lang="ts">
|
||||
import { countryCodeToName } from "$lib";
|
||||
import type { RegionInfo } from "$lib/utils/types.js";
|
||||
|
||||
export let data;
|
||||
let info = data.info.data.info as RegionInfo;
|
||||
let country = countryCodeToName(data.info.data.country_code);
|
||||
let regionName = data.info.data.name;
|
||||
let visited = data.visited;
|
||||
</script>
|
||||
|
||||
<h1>Info About {regionName} in {country}</h1>
|
||||
{#if visited}
|
||||
<p>You have visited this region!</p>
|
||||
{/if}
|
||||
|
||||
<h2>Region Info</h2>
|
||||
{#if info.description}
|
||||
<p>{info.description}</p>
|
||||
{/if}
|
||||
Reference in New Issue
Block a user