1
0
Fork 0
mirror of https://github.com/seanmorley15/AdventureLog.git synced 2025-07-23 06:49:37 +02:00

Added new regions

This commit is contained in:
Sean Morley 2024-05-25 14:23:59 +00:00
parent 8f0ae40534
commit fb749d0cb2
7 changed files with 188 additions and 61 deletions

View file

@ -36,7 +36,12 @@ export async function insertData() {
('Australia', 'au', 'Oceania'),
('New Zealand', 'nz', 'Oceania'),
('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;`);
console.log("Inserting regions...");
@ -94,6 +99,8 @@ export async function insertData() {
ON CONFLICT (id) DO NOTHING;
`);
console.log("Inserting Canada regions...");
await db.execute(sql`INSERT INTO "worldTravelCountryRegions" (id, name, country_code)
VALUES
('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)
VALUES
('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)
VALUES
('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)
VALUES
('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)
VALUES
('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)
VALUES
('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)
VALUES
('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)
VALUES
('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)
VALUES
('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)
VALUES
('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)
VALUES
('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)
VALUES
('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)
VALUES
('EG-ALX', 'Alexandria', 'eg'),
@ -464,10 +495,10 @@ ON CONFLICT (id) DO NOTHING;
('EG-ESI', 'Ismailia', 'eg')
ON CONFLICT (id) DO NOTHING;
`);
console.log("Inserting Brazil regions...");
await db.execute(sql`INSERT INTO "worldTravelCountryRegions" (id, name, country_code)
VALUES
('BR-AC', 'Acre', 'br'),
@ -497,9 +528,129 @@ VALUES
('BR-SP', 'São Paulo', 'br'),
('BR-SE', 'Sergipe', 'br'),
('BR-TO', 'Tocantins', 'br')
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 countryCodes from "./json/countries.json";
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.
* @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

@ -158,7 +158,7 @@
}
</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="dropdown dropdown-top dropdown-end">
<div tabindex="0" role="button" class="btn m-1 size-16 btn-primary">

View file

@ -189,7 +189,7 @@
<SucessToast action={toastAction} />
{/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="dropdown dropdown-top dropdown-end">
<div tabindex="0" role="button" class="btn m-1 size-16 btn-primary">

View file

@ -1,19 +1,28 @@
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 { db } from "$lib/db/db.server.js";
import {
userVisitedWorldTravel,
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 }) => {
const { countrycode } = params;
let data = await db
.select()
.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) {
let countryCode = params.countrycode
let countryCode = params.countrycode;
visitedRegions = await db
.select()
.from(userVisitedWorldTravel)
@ -27,8 +36,9 @@ export const load: PageServerLoad = async ({ params, locals }) => {
}
return {
regions : data,
regions: data,
countrycode: countrycode,
visitedRegions: visitedRegions,
countryName: countryName[0].name,
};
}
};

View file

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