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

Merge pull request #73 from seanmorley15/development

Add new Regions
This commit is contained in:
Sean Morley 2024-05-26 09:58:12 -04:00 committed by GitHub
commit 8168bafb7b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 261 additions and 85 deletions

View file

@ -5,7 +5,7 @@
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/base:jammy", "image": "mcr.microsoft.com/devcontainers/base:jammy",
"features": { "features": {
"ghcr.io/devcontainers-contrib/features/node-asdf:0": {}, "ghcr.io/devcontainers/features/node:1": {},
"ghcr.io/devcontainers/features/docker-in-docker:2": {} "ghcr.io/devcontainers/features/docker-in-docker:2": {}
} }

View file

@ -10,8 +10,11 @@ WORKDIR /app
# Copy all local files into the image # Copy all local files into the image
COPY . . COPY . .
# Clean install all node modules # Install pnpm
RUN npm ci RUN npm install -g pnpm
# Clean install all node modules using pnpm
RUN pnpm install
# Build SvelteKit app # Build SvelteKit app
RUN npm run build RUN npm run build
@ -19,13 +22,10 @@ RUN npm run build
# Expose the port that the app is listening on # Expose the port that the app is listening on
EXPOSE 3000 EXPOSE 3000
RUN chmod +x ./startup.sh RUN chmod +x ./startup.sh
# The USER instruction sets the user name to use as the default user for the remainder of the current stage # The USER instruction sets the user name to use as the default user for the remainder of the current stage
USER node:node USER node:node
# get permission to run startup script
# Run startup.sh instead of the default command # Run startup.sh instead of the default command
CMD ["./startup.sh"] CMD ["./startup.sh"]

View file

@ -9,6 +9,7 @@
location: "", location: "",
date: "", date: "",
activityTypes: [], activityTypes: [],
imageUrl: "",
}; };
import { createEventDispatcher } from "svelte"; import { createEventDispatcher } from "svelte";
@ -121,6 +122,16 @@
class="input input-bordered w-full max-w-xs" class="input input-bordered w-full max-w-xs"
/> />
</div> </div>
<div>
<label for="rating">Image URL</label>
<input
type="url"
id="iamgeUrl"
bind:value={newAdventure.imageUrl}
class="input input-bordered w-full max-w-xs"
/>
</div>
<button <button
type="submit" type="submit"
class="btn btn-primary mr-4 mt-4" class="btn btn-primary mr-4 mt-4"

View file

@ -110,6 +110,15 @@
class="input input-bordered w-full max-w-xs" class="input input-bordered w-full max-w-xs"
/> />
</div> </div>
<div>
<label for="rating">Image URL</label>
<input
type="url"
id="imageUrl"
bind:value={adventureToEdit.imageUrl}
class="input input-bordered w-full max-w-xs"
/>
</div>
<button class="btn btn-primary mr-4 mt-4" on:click={submit}>Save</button <button class="btn btn-primary mr-4 mt-4" on:click={submit}>Save</button
> >
<!-- if there is a button in form, it will close the modal --> <!-- if there is a button in form, it will close the modal -->

View file

@ -36,7 +36,12 @@ export async function insertData() {
('Australia', 'au', 'Oceania'), ('Australia', 'au', 'Oceania'),
('New Zealand', 'nz', 'Oceania'), ('New Zealand', 'nz', 'Oceania'),
('South Africa', 'za', 'Africa'), ('South Africa', 'za', 'Africa'),
('Egypt', 'eg', 'Africa') ('Egypt', 'eg', 'Africa'),
('Sweden', 'se', 'Europe'),
('Ireland', 'ie', 'Europe'),
('Spain', 'es', 'Europe'),
('Switzerland', 'ch', 'Europe'),
('Italy', 'it', 'Europe')
ON CONFLICT (country_code) DO NOTHING;`); ON CONFLICT (country_code) DO NOTHING;`);
console.log("Inserting regions..."); console.log("Inserting regions...");
@ -94,6 +99,8 @@ export async function insertData() {
ON CONFLICT (id) DO NOTHING; ON CONFLICT (id) DO NOTHING;
`); `);
console.log("Inserting Canada regions...");
await db.execute(sql`INSERT INTO "worldTravelCountryRegions" (id, name, country_code) await db.execute(sql`INSERT INTO "worldTravelCountryRegions" (id, name, country_code)
VALUES VALUES
('CA-AB', 'Alberta', 'ca'), ('CA-AB', 'Alberta', 'ca'),
@ -113,6 +120,8 @@ ON CONFLICT (id) DO NOTHING;
`); `);
console.log("Inserting Germany regions...");
await db.execute(sql`INSERT INTO "worldTravelCountryRegions" (id, name, country_code) await db.execute(sql`INSERT INTO "worldTravelCountryRegions" (id, name, country_code)
VALUES VALUES
('DE-BW', 'Baden-Württemberg', 'de'), ('DE-BW', 'Baden-Württemberg', 'de'),
@ -136,6 +145,8 @@ ON CONFLICT (id) DO NOTHING;
`); `);
console.log("Inserting France regions...");
await db.execute(sql`INSERT INTO "worldTravelCountryRegions" (id, name, country_code) await db.execute(sql`INSERT INTO "worldTravelCountryRegions" (id, name, country_code)
VALUES VALUES
('FR-ARA', 'Auvergne-Rhône-Alpes', 'fr'), ('FR-ARA', 'Auvergne-Rhône-Alpes', 'fr'),
@ -161,6 +172,8 @@ ON CONFLICT (id) DO NOTHING;
`); `);
console.log("Inserting United Kingdom regions...");
await db.execute(sql`INSERT INTO "worldTravelCountryRegions" (id, name, country_code) await db.execute(sql`INSERT INTO "worldTravelCountryRegions" (id, name, country_code)
VALUES VALUES
('GB-ENG', 'England', 'gb'), ('GB-ENG', 'England', 'gb'),
@ -172,6 +185,8 @@ ON CONFLICT (id) DO NOTHING;
`); `);
console.log("Inserting Argentina regions...");
await db.execute(sql`INSERT INTO "worldTravelCountryRegions" (id, name, country_code) await db.execute(sql`INSERT INTO "worldTravelCountryRegions" (id, name, country_code)
VALUES VALUES
('AR-C', 'Ciudad Autónoma de Buenos Aires', 'ar'), ('AR-C', 'Ciudad Autónoma de Buenos Aires', 'ar'),
@ -203,6 +218,8 @@ ON CONFLICT (id) DO NOTHING;
`); `);
console.log("Inerting Mexico regions...");
await db.execute(sql`INSERT INTO "worldTravelCountryRegions" (id, name, country_code) await db.execute(sql`INSERT INTO "worldTravelCountryRegions" (id, name, country_code)
VALUES VALUES
('MX-AGU', 'Aguascalientes', 'mx'), ('MX-AGU', 'Aguascalientes', 'mx'),
@ -241,6 +258,8 @@ ON CONFLICT (id) DO NOTHING;
`); `);
console.log("Inserting Japan regions...");
await db.execute(sql`INSERT INTO "worldTravelCountryRegions" (id, name, country_code) await db.execute(sql`INSERT INTO "worldTravelCountryRegions" (id, name, country_code)
VALUES VALUES
('JP-01', 'Hokkaido', 'jp'), ('JP-01', 'Hokkaido', 'jp'),
@ -295,6 +314,8 @@ ON CONFLICT (id) DO NOTHING;
`); `);
console.log("Inserting China regions...");
await db.execute(sql`INSERT INTO "worldTravelCountryRegions" (id, name, country_code) await db.execute(sql`INSERT INTO "worldTravelCountryRegions" (id, name, country_code)
VALUES VALUES
('CN-BJ', 'Beijing', 'cn'), ('CN-BJ', 'Beijing', 'cn'),
@ -333,6 +354,8 @@ ON CONFLICT (id) DO NOTHING;
`); `);
console.log("Inserting India regions...");
await db.execute(sql`INSERT INTO "worldTravelCountryRegions" (id, name, country_code) await db.execute(sql`INSERT INTO "worldTravelCountryRegions" (id, name, country_code)
VALUES VALUES
('IN-AN', 'Andaman and Nicobar Islands', 'in'), ('IN-AN', 'Andaman and Nicobar Islands', 'in'),
@ -376,6 +399,8 @@ ON CONFLICT (id) DO NOTHING;
`); `);
console.log("Inserting Australia regions...");
await db.execute(sql`INSERT INTO "worldTravelCountryRegions" (id, name, country_code) await db.execute(sql`INSERT INTO "worldTravelCountryRegions" (id, name, country_code)
VALUES VALUES
('AU-NSW', 'New South Wales', 'au'), ('AU-NSW', 'New South Wales', 'au'),
@ -392,6 +417,8 @@ ON CONFLICT (id) DO NOTHING;
`); `);
console.log("Inserting New Zealand regions...");
await db.execute(sql`INSERT INTO "worldTravelCountryRegions" (id, name, country_code) await db.execute(sql`INSERT INTO "worldTravelCountryRegions" (id, name, country_code)
VALUES VALUES
('NZ-N', 'Northland', 'nz'), ('NZ-N', 'Northland', 'nz'),
@ -416,6 +443,8 @@ ON CONFLICT (id) DO NOTHING;
`); `);
console.log("Inserting South Africa regions...");
await db.execute(sql`INSERT INTO "worldTravelCountryRegions" (id, name, country_code) await db.execute(sql`INSERT INTO "worldTravelCountryRegions" (id, name, country_code)
VALUES VALUES
('ZA-EC', 'Eastern Cape', 'za'), ('ZA-EC', 'Eastern Cape', 'za'),
@ -433,6 +462,8 @@ ON CONFLICT (id) DO NOTHING;
`); `);
console.log("Inserting Egypt regions...");
await db.execute(sql`INSERT INTO "worldTravelCountryRegions" (id, name, country_code) await db.execute(sql`INSERT INTO "worldTravelCountryRegions" (id, name, country_code)
VALUES VALUES
('EG-ALX', 'Alexandria', 'eg'), ('EG-ALX', 'Alexandria', 'eg'),
@ -464,10 +495,10 @@ ON CONFLICT (id) DO NOTHING;
('EG-ESI', 'Ismailia', 'eg') ('EG-ESI', 'Ismailia', 'eg')
ON CONFLICT (id) DO NOTHING; ON CONFLICT (id) DO NOTHING;
`); `);
console.log("Inserting Brazil regions...");
await db.execute(sql`INSERT INTO "worldTravelCountryRegions" (id, name, country_code) await db.execute(sql`INSERT INTO "worldTravelCountryRegions" (id, name, country_code)
VALUES VALUES
('BR-AC', 'Acre', 'br'), ('BR-AC', 'Acre', 'br'),
@ -497,9 +528,129 @@ VALUES
('BR-SP', 'São Paulo', 'br'), ('BR-SP', 'São Paulo', 'br'),
('BR-SE', 'Sergipe', 'br'), ('BR-SE', 'Sergipe', 'br'),
('BR-TO', 'Tocantins', 'br') ('BR-TO', 'Tocantins', 'br')
ON CONFLICT (id) DO NOTHING; ON CONFLICT (id) DO NOTHING;
`);
console.log("Inserting Sweden regions...");
await db.execute(sql`INSERT INTO "worldTravelCountryRegions" (id, name, country_code)
VALUES
('SE-AB', 'Stockholm', 'se'),
('SE-AC', 'Västerbotten', 'se'),
('SE-BD', 'Norrbotten', 'se'),
('SE-C', 'Uppsala', 'se'),
('SE-D', 'Södermanland', 'se'),
('SE-E', 'Östergötland', 'se'),
('SE-F', 'Jönköping', 'se'),
('SE-G', 'Kronoberg', 'se'),
('SE-H', 'Kalmar', 'se'),
('SE-I', 'Gotland', 'se'),
('SE-K', 'Blekinge', 'se'),
('SE-M', 'Skåne', 'se'),
('SE-N', 'Halland', 'se'),
('SE-O', 'Västra Götaland', 'se'),
('SE-S', 'Värmland', 'se'),
('SE-T', 'Örebro', 'se'),
('SE-U', 'Västmanland', 'se'),
('SE-W', 'Dalarna', 'se'),
('SE-X', 'Gävleborg', 'se'),
('SE-Y', 'Västernorrland', 'se'),
('SE-Z', 'Jämtland', 'se')
ON CONFLICT (id) DO NOTHING;
`);
console.log("Inserting Ireland regions...");
await db.execute(sql`INSERT INTO "worldTravelCountryRegions" (id, name, country_code)
VALUES
('IE-C', 'Connacht', 'ie'),
('IE-L', 'Leinster', 'ie'),
('IE-M', 'Munster', 'ie'),
('IE-U', 'Ulster', 'ie')
ON CONFLICT (id) DO NOTHING;
`);
console.log("Inserting Spain regions...");
await db.execute(sql`INSERT INTO "worldTravelCountryRegions" (id, name, country_code)
VALUES
('ES-AN', 'Andalucía', 'es'),
('ES-AR', 'Aragón', 'es'),
('ES-AS', 'Asturias', 'es'),
('ES-CB', 'Cantabria', 'es'),
('ES-CL', 'Castilla y León', 'es'),
('ES-CM', 'Castilla-La Mancha', 'es'),
('ES-CN', 'Canarias', 'es'),
('ES-CT', 'Cataluña', 'es'),
('ES-EX', 'Extremadura', 'es'),
('ES-GA', 'Galicia', 'es'),
('ES-IB', 'Islas Baleares', 'es'),
('ES-MD', 'Madrid', 'es'),
('ES-MC', 'Murcia', 'es'),
('ES-NC', 'Navarra', 'es'),
('ES-PV', 'País Vasco', 'es'),
('ES-RI', 'La Rioja', 'es'),
('ES-VC', 'Comunidad Valenciana', 'es')
ON CONFLICT (id) DO NOTHING;
`);
console.log("Inserting Switzerland regions...");
await db.execute(sql`INSERT INTO "worldTravelCountryRegions" (id, name, country_code)
VALUES
('CH-AG', 'Aargau', 'ch'),
('CH-AR', 'Appenzell Ausserrhoden', 'ch'),
('CH-AI', 'Appenzell Innerrhoden', 'ch'),
('CH-BL', 'Basel-Landschaft', 'ch'),
('CH-BS', 'Basel-Stadt', 'ch'),
('CH-BE', 'Bern', 'ch'),
('CH-FR', 'Fribourg', 'ch'),
('CH-GE', 'Genève', 'ch'),
('CH-GL', 'Glarus', 'ch'),
('CH-GR', 'Graubünden', 'ch'),
('CH-JU', 'Jura', 'ch'),
('CH-LU', 'Luzern', 'ch'),
('CH-NE', 'Neuchâtel', 'ch'),
('CH-NW', 'Nidwalden', 'ch'),
('CH-OW', 'Obwalden', 'ch'),
('CH-SH', 'Schaffhausen', 'ch'),
('CH-SZ', 'Schwyz', 'ch'),
('CH-SO', 'Solothurn', 'ch'),
('CH-SG', 'St. Gallen', 'ch'),
('CH-TG', 'Thurgau', 'ch'),
('CH-TI', 'Ticino', 'ch'),
('CH-UR', 'Uri', 'ch'),
('CH-VS', 'Valais', 'ch'),
('CH-VD', 'Vaud', 'ch'),
('CH-ZG', 'Zug', 'ch'),
('CH-ZH', 'Zürich', 'ch')
ON CONFLICT (id) DO NOTHING;
`);
console.log("Inserting Italy regions...");
await db.execute(sql`INSERT INTO "worldTravelCountryRegions" (id, name, country_code)
VALUES
('IT-65', 'Abruzzo', 'it'),
('IT-77', 'Basilicata', 'it'),
('IT-78', 'Calabria', 'it'),
('IT-72', 'Campania', 'it'),
('IT-45', 'Emilia-Romagna', 'it'),
('IT-36', 'Friuli Venezia Giulia', 'it'),
('IT-62', 'Lazio', 'it'),
('IT-42', 'Liguria', 'it'),
('IT-25', 'Lombardia', 'it'),
('IT-57', 'Marche', 'it'),
('IT-67', 'Molise', 'it'),
('IT-21', 'Piemonte', 'it'),
('IT-75', 'Puglia', 'it'),
('IT-88', 'Sardegna', 'it'),
('IT-82', 'Sicilia', 'it'),
('IT-52', 'Toscana', 'it'),
('IT-32', 'Trentino-Alto Adige', 'it'),
('IT-55', 'Umbria', 'it'),
('IT-23', 'Valle d''Aosta', 'it'),
('IT-34', 'Veneto', 'it')
ON CONFLICT (id) DO NOTHING;
`); `);
} }

View file

@ -1,20 +1,6 @@
import inspirationalQuotes from "./json/quotes.json"; import inspirationalQuotes from "./json/quotes.json";
import countryCodes from "./json/countries.json";
import type { Adventure } from "./utils/types"; import type { Adventure } from "./utils/types";
/**
* Converts a country code to its corresponding country name.
* @param countryCode - The country code to convert.
* @returns The country name if found, otherwise null.
*/
export function countryCodeToName(countryCode: string): string | null {
// Look up the country name using the provided country code
const countryName =
countryCodes[countryCode.toLowerCase() as keyof typeof countryCodes];
// Return the country name if found, otherwise return null
return countryName || null;
}
/** /**
* Generates the URL for a flag image based on the specified size and country code. * Generates the URL for a flag image based on the specified size and country code.
* @param size - The desired height of the flag image. Avaliable sizes: 20, 24, 40, 60, 80, 120, 240. * @param size - The desired height of the flag image. Avaliable sizes: 20, 24, 40, 60, 80, 120, 240.

View file

@ -1,17 +0,0 @@
{
"us": "United States",
"de": "Germany",
"fr": "France",
"gb": "United Kingdom",
"ar": "Argentina",
"mx": "Mexico",
"jp": "Japan",
"cn": "China",
"in": "India",
"au": "Australia",
"nz": "New Zealand",
"za": "South Africa",
"eg": "Egypt",
"ca": "Canada",
"br": "Brazil"
}

View file

@ -28,8 +28,8 @@ export const GET: RequestHandler = async ({ url, locals }) => {
.where( .where(
and( and(
eq(adventureTable.id, Number(id)), // Convert id to number eq(adventureTable.id, Number(id)), // Convert id to number
eq(adventureTable.userId, user.id), eq(adventureTable.userId, user.id)
eq(adventureTable.type, "mylog") // eq(adventureTable.type, "mylog")
) )
) )
.limit(1) .limit(1)

View file

@ -109,8 +109,16 @@ export async function POST(event: RequestEvent): Promise<Response> {
}); });
} }
const { name, location, date, description, activityTypes, rating, tripId } = const {
body.detailAdventure; name,
location,
date,
description,
activityTypes,
rating,
tripId,
imageUrl,
} = body.detailAdventure;
if (!name) { if (!name) {
return error(400, { return error(400, {
@ -139,6 +147,7 @@ export async function POST(event: RequestEvent): Promise<Response> {
description: description || null, description: description || null,
activityTypes: JSON.stringify(activityTypes) || null, activityTypes: JSON.stringify(activityTypes) || null,
rating: rating || null, rating: rating || null,
imageUrl: imageUrl || null,
}) })
.returning({ insertedId: adventureTable.id }) .returning({ insertedId: adventureTable.id })
.execute(); .execute();
@ -182,8 +191,16 @@ export async function PUT(event: RequestEvent): Promise<Response> {
}); });
} }
const { name, location, date, description, activityTypes, id, rating } = const {
body.detailAdventure; name,
location,
date,
description,
activityTypes,
id,
rating,
imageUrl,
} = body.detailAdventure;
if (!name) { if (!name) {
return error(400, { return error(400, {
@ -201,6 +218,7 @@ export async function PUT(event: RequestEvent): Promise<Response> {
description: description, description: description,
rating: rating, rating: rating,
activityTypes: JSON.stringify(activityTypes), activityTypes: JSON.stringify(activityTypes),
imageUrl: imageUrl,
}) })
.where( .where(
and( and(

View file

@ -108,7 +108,7 @@ export async function POST(event: RequestEvent): Promise<Response> {
}); });
} }
const { name, location, date, description, activityTypes, rating } = const { name, location, date, description, activityTypes, rating, imageUrl } =
body.detailAdventure; body.detailAdventure;
if (!name) { if (!name) {
@ -137,6 +137,7 @@ export async function POST(event: RequestEvent): Promise<Response> {
description: description || null, description: description || null,
activityTypes: JSON.stringify(activityTypes) || null, activityTypes: JSON.stringify(activityTypes) || null,
rating: rating || null, rating: rating || null,
imageUrl: imageUrl || null,
}) })
.returning({ insertedId: adventureTable.id }) .returning({ insertedId: adventureTable.id })
.execute(); .execute();
@ -180,8 +181,17 @@ export async function PUT(event: RequestEvent): Promise<Response> {
}); });
} }
const { name, location, date, description, activityTypes, id, rating, type } = const {
body.detailAdventure; name,
location,
date,
description,
activityTypes,
id,
rating,
type,
imageUrl,
} = body.detailAdventure;
if (!name) { if (!name) {
return error(400, { return error(400, {
@ -206,6 +216,7 @@ export async function PUT(event: RequestEvent): Promise<Response> {
description: description, description: description,
rating: rating, rating: rating,
activityTypes: JSON.stringify(activityTypes), activityTypes: JSON.stringify(activityTypes),
imageUrl: imageUrl,
}) })
.where( .where(
and( and(

View file

@ -158,7 +158,7 @@
} }
</script> </script>
<div class="fixed bottom-4 right-4"> <div class="fixed bottom-4 right-4 z-[999]">
<div class="flex flex-row items-center justify-center gap-4"> <div class="flex flex-row items-center justify-center gap-4">
<div class="dropdown dropdown-top dropdown-end"> <div class="dropdown dropdown-top dropdown-end">
<div tabindex="0" role="button" class="btn m-1 size-16 btn-primary"> <div tabindex="0" role="button" class="btn m-1 size-16 btn-primary">

View file

@ -189,7 +189,7 @@
<SucessToast action={toastAction} /> <SucessToast action={toastAction} />
{/if} {/if}
<div class="fixed bottom-4 right-4"> <div class="fixed bottom-4 right-4 z-[999]">
<div class="flex flex-row items-center justify-center gap-4"> <div class="flex flex-row items-center justify-center gap-4">
<div class="dropdown dropdown-top dropdown-end"> <div class="dropdown dropdown-top dropdown-end">
<div tabindex="0" role="button" class="btn m-1 size-16 btn-primary"> <div tabindex="0" role="button" class="btn m-1 size-16 btn-primary">

View file

@ -98,6 +98,13 @@ export const actions: Actions = {
const formData = await event.request.formData(); const formData = await event.request.formData();
const formUsername = formData.get("username"); const formUsername = formData.get("username");
let username = formUsername?.toString().toLocaleLowerCase(); let username = formUsername?.toString().toLocaleLowerCase();
let role = formData.get("role");
if (!role) {
role = "user";
} else {
role = "admin";
}
console.log("role", role);
if (typeof formUsername !== "string") { if (typeof formUsername !== "string") {
return fail(400, { message: "Invalid username" }); return fail(400, { message: "Invalid username" });
@ -187,18 +194,11 @@ export const actions: Actions = {
last_name: lastName, last_name: lastName,
hashed_password: hashedPassword, hashed_password: hashedPassword,
signup_date: new Date(), signup_date: new Date(),
role: "admin", role: role,
last_login: new Date(), last_login: new Date(),
} as DatabaseUser) } as DatabaseUser)
.execute(); .execute();
const session = await lucia.createSession(userId, {});
const sessionCookie = lucia.createSessionCookie(session.id);
event.cookies.set(sessionCookie.name, sessionCookie.value, {
path: ".",
...sessionCookie.attributes,
});
return { success: true }; return { success: true };
}, },
}; };

View file

@ -1,19 +1,28 @@
import { db } from '$lib/db/db.server.js'; import { db } from "$lib/db/db.server.js";
import { userVisitedWorldTravel, worldTravelCountryRegions } from '$lib/db/schema.js'; import {
import { and, eq } from 'drizzle-orm'; userVisitedWorldTravel,
import type { PageServerLoad } from './$types'; worldTravelCountries,
worldTravelCountryRegions,
} from "$lib/db/schema.js";
import { and, eq } from "drizzle-orm";
import type { PageServerLoad } from "./$types";
export const load: PageServerLoad = async ({ params, locals }) => { export const load: PageServerLoad = async ({ params, locals }) => {
const { countrycode } = params; const { countrycode } = params;
let data = await db let data = await db
.select() .select()
.from(worldTravelCountryRegions) .from(worldTravelCountryRegions)
.where(eq(worldTravelCountryRegions.country_code, countrycode)) .where(eq(worldTravelCountryRegions.country_code, countrycode));
let visitedRegions: { id: number; userId: string; region_id: string; }[] = []; let countryName = await db
.select()
.from(worldTravelCountries)
.where(eq(worldTravelCountries.country_code, countrycode))
.execute();
let visitedRegions: { id: number; userId: string; region_id: string }[] = [];
if (locals.user) { if (locals.user) {
let countryCode = params.countrycode let countryCode = params.countrycode;
visitedRegions = await db visitedRegions = await db
.select() .select()
.from(userVisitedWorldTravel) .from(userVisitedWorldTravel)
@ -27,8 +36,9 @@ export const load: PageServerLoad = async ({ params, locals }) => {
} }
return { return {
regions : data, regions: data,
countrycode: countrycode, countrycode: countrycode,
visitedRegions: visitedRegions, visitedRegions: visitedRegions,
countryName: countryName[0].name,
}; };
} };

View file

@ -1,7 +1,6 @@
<script lang="ts"> <script lang="ts">
export let data; export let data;
import AdventureCard from "$lib/components/AdventureCard.svelte"; import AdventureCard from "$lib/components/AdventureCard.svelte";
import { countryCodeToName } from "$lib";
import { getFlag } from "$lib"; import { getFlag } from "$lib";
import { goto } from "$app/navigation"; import { goto } from "$app/navigation";
import { onMount } from "svelte"; import { onMount } from "svelte";
@ -57,7 +56,7 @@
</script> </script>
<h1 class="text-center text-4xl font-bold"> <h1 class="text-center text-4xl font-bold">
Regions in {countryCodeToName(data.countrycode)} Regions in {data.countryName}
<img <img
src={getFlag(40, data.countrycode)} src={getFlag(40, data.countrycode)}
class="inline-block -mt-1 mr-1" class="inline-block -mt-1 mr-1"
@ -109,11 +108,9 @@
{/if} {/if}
<svelte:head> <svelte:head>
<title>{countryCodeToName(data.countrycode)} Regions | AdventureLog</title> <title>{data.countryName} Regions | AdventureLog</title>
<meta <meta
name="description" name="description"
content="Explore the regions in {countryCodeToName( content="Explore the regions in {data.countryName} and add them to your visited list!"
data.countrycode
)} and add them to your visited list!"
/> />
</svelte:head> </svelte:head>