mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-31 02:39:38 +02:00
Refactor database schema, remove unused SQL files, and update components
This commit is contained in:
parent
08579289a6
commit
9837cc4e64
7 changed files with 23 additions and 300 deletions
|
@ -15,8 +15,6 @@
|
|||
export let regionId: String | undefined = undefined;
|
||||
export let visited: Boolean | undefined = undefined;
|
||||
export let countryCode: String | undefined = undefined;
|
||||
export let activityTypes: String[] | undefined = undefined;
|
||||
export let description: String | undefined = undefined;
|
||||
|
||||
function remove() {
|
||||
dispatch("remove", id);
|
||||
|
@ -41,13 +39,12 @@
|
|||
}
|
||||
</script>
|
||||
|
||||
{#if type === "mylog"}
|
||||
<div
|
||||
class="card min-w-max lg:w-96 md:w-80 sm:w-60 xs:w-40 bg-primary-content shadow-xl overflow-hidden text-base-content"
|
||||
>
|
||||
<div class="card-body">
|
||||
<h2 class="card-title overflow-ellipsis">{name}</h2>
|
||||
{#if location !== ""}
|
||||
{#if location && location !== ""}
|
||||
<div class="inline-flex items-center">
|
||||
<iconify-icon icon="mdi:map-marker" class="text-xl"></iconify-icon>
|
||||
<p class="ml-.5">{location}</p>
|
||||
|
@ -60,109 +57,13 @@
|
|||
</div>
|
||||
{/if}
|
||||
<div class="card-actions justify-end">
|
||||
{#if type == "mylog"}
|
||||
<button class="btn btn-primary" on:click={edit}>Edit</button>
|
||||
<button class="btn btn-secondary" on:click={remove}>Remove</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if type === "featured"}
|
||||
<div
|
||||
class="card min-w-max lg:w-96 md:w-80 sm:w-60 xs:w-40 bg-primary-content shadow-xl overflow-hidden text-base-content"
|
||||
>
|
||||
<div class="card-body">
|
||||
<h2 class="card-title overflow-ellipsis">{name}</h2>
|
||||
{#if location && location != ""}
|
||||
<div class="inline-flex items-center">
|
||||
<iconify-icon icon="mdi:map-marker" class="text-xl"></iconify-icon>
|
||||
<p class="ml-.5">{location}</p>
|
||||
</div>
|
||||
{/if}
|
||||
<div class="card-actions justify-end">
|
||||
{#if type == "featured"}
|
||||
<button class="btn btn-primary" on:click={add}>Add</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if type === "shared"}
|
||||
<div
|
||||
class="card min-w-max lg:w-96 md:w-80 sm:w-60 xs:w-40 bg-primary-content shadow-xl overflow-hidden text-base-content"
|
||||
>
|
||||
<div class="card-body">
|
||||
<h2 class="card-title overflow-ellipsis">{name}</h2>
|
||||
{#if location && location !== ""}
|
||||
<div class="inline-flex items-center">
|
||||
<iconify-icon icon="mdi:map-marker" class="text-xl"></iconify-icon>
|
||||
<p class="ml-.5">{location}</p>
|
||||
</div>
|
||||
{/if}
|
||||
{#if date !== ""}
|
||||
<div class="inline-flex items-center">
|
||||
<iconify-icon icon="mdi:calendar" class="text-xl"></iconify-icon>
|
||||
<p class="ml-1">{date}</p>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if type === "worldtravelregion"}
|
||||
<div
|
||||
class="card min-w-max lg:w-96 md:w-80 sm:w-60 xs:w-40 bg-primary-content shadow-xl overflow-hidden text-base-content"
|
||||
>
|
||||
<div class="card-body">
|
||||
<h2 class="card-title overflow-ellipsis">{name}</h2>
|
||||
<p>{regionId}</p>
|
||||
<div class="card-actions justify-end">
|
||||
<!-- <button class="btn btn-info" on:click={moreInfo}>More Info</button> -->
|
||||
{#if !visited}
|
||||
<button class="btn btn-primary" on:click={markVisited}
|
||||
>Mark Visited</button
|
||||
>
|
||||
{/if}
|
||||
{#if visited}
|
||||
<button class="btn btn-warning" on:click={removeVisit}>Remove</button>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if type === "planner"}
|
||||
<div
|
||||
class="card min-w-max lg:w-96 md:w-80 sm:w-60 xs:w-40 bg-primary-content shadow-xl overflow-hidden text-base-content"
|
||||
>
|
||||
<div class="card-body">
|
||||
<h2 class="card-title overflow-ellipsis">{name}</h2>
|
||||
{#if location != ""}
|
||||
<div class="inline-flex items-center">
|
||||
<iconify-icon icon="mdi:map-marker" class="text-xl"></iconify-icon>
|
||||
<p class="ml-.5">{location}</p>
|
||||
</div>
|
||||
{/if}
|
||||
{#if activityTypes && activityTypes.length > 0}
|
||||
{#each activityTypes as activity}
|
||||
<div
|
||||
class="relative grid select-none items-center whitespace-nowrap rounded-lg bg-gray-900 py-1.5 px-3 font-sans text-xs font-bold uppercase text-white"
|
||||
>
|
||||
<span class="">{activity}</span>
|
||||
</div>
|
||||
{/each}
|
||||
{/if}
|
||||
{#if description && description.length > 0}
|
||||
<p>{description}</p>
|
||||
{/if}
|
||||
{#if date && date != undefined}
|
||||
<div class="inline-flex items-center">
|
||||
<iconify-icon icon="mdi:calendar" class="text-xl"></iconify-icon>
|
||||
<p class="ml-1">{date}</p>
|
||||
</div>
|
||||
{/if}
|
||||
<div class="card-actions justify-end">
|
||||
<button class="btn btn-primary" on:click={add}>Add</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
|
|
@ -78,10 +78,6 @@
|
|||
<button class="btn btn-primary my-2 md:my-0 md:mr-4" on:click={goToLog}
|
||||
>My Log</button
|
||||
>
|
||||
<button
|
||||
class="btn btn-primary my-2 md:my-0 md:mr-4"
|
||||
on:click={() => goto("/planner")}>Planner</button
|
||||
>
|
||||
{/if}
|
||||
<button
|
||||
class="btn btn-primary my-2 md:my-0 md:mr-4"
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
import { db } from "$lib/db/db.server";
|
||||
import { userPlannedAdventures } from "$lib/db/schema";
|
||||
import { eq } from "drizzle-orm";
|
||||
import type { LayoutServerLoad } from "../$types";
|
||||
import { redirect } from "@sveltejs/kit";
|
||||
|
||||
export const load: LayoutServerLoad = async (event) => {
|
||||
if (event.locals.user) {
|
||||
let plannedAdventures = await db
|
||||
.select()
|
||||
.from(userPlannedAdventures)
|
||||
.where(eq(userPlannedAdventures.userId, event.locals.user.id));
|
||||
return {
|
||||
user: event.locals.user,
|
||||
isServerSetup: event.locals.isServerSetup,
|
||||
plannedAdventures,
|
||||
};
|
||||
} else {
|
||||
return redirect(302, "/login");
|
||||
}
|
||||
};
|
|
@ -1,31 +0,0 @@
|
|||
<script lang="ts">
|
||||
import { page } from "$app/stores";
|
||||
import type { Adventure } from "$lib/utils/types";
|
||||
import { onMount } from "svelte";
|
||||
import AdventureCard from "$lib/components/AdventureCard.svelte";
|
||||
|
||||
let plannedAdventures: Adventure[] = [];
|
||||
|
||||
onMount(async () => {
|
||||
plannedAdventures = $page.data.plannedAdventures;
|
||||
console.log(plannedAdventures);
|
||||
});
|
||||
</script>
|
||||
|
||||
<h1 class="font-extrabold text-center text-4xl">My Planned Adventures</h1>
|
||||
|
||||
<div
|
||||
class="grid xl:grid-cols-3 lg:grid-cols-3 md:grid-cols-2 sm:grid-cols-1 gap-4 mt-4 content-center auto-cols-auto ml-6 mr-6"
|
||||
>
|
||||
{#each plannedAdventures as adventure (adventure.id)}
|
||||
<AdventureCard
|
||||
type="planner"
|
||||
id={adventure.id}
|
||||
name={adventure.name}
|
||||
location={adventure.location}
|
||||
activityTypes={adventure.activityTypes}
|
||||
description={adventure?.description}
|
||||
date={adventure?.date}
|
||||
/>
|
||||
{/each}
|
||||
</div>
|
|
@ -6,6 +6,7 @@
|
|||
import { goto } from "$app/navigation";
|
||||
import { onMount } from "svelte";
|
||||
import Us from "$lib/components/maps/US.svelte";
|
||||
import WorldTravelCard from "$lib/components/WorldTravelCard.svelte";
|
||||
|
||||
let viewType: String = "cards";
|
||||
|
||||
|
@ -87,8 +88,7 @@
|
|||
class="grid xl:grid-cols-3 lg:grid-cols-3 md:grid-cols-2 sm:grid-cols-1 gap-4 mt-4 content-center auto-cols-auto ml-6 mr-6"
|
||||
>
|
||||
{#each data.regions as region (region.id)}
|
||||
<AdventureCard
|
||||
type="worldtravelregion"
|
||||
<WorldTravelCard
|
||||
countryCode={data.countrycode}
|
||||
regionId={region.id}
|
||||
name={region.name}
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
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,
|
||||
};
|
||||
}
|
|
@ -1,88 +0,0 @@
|
|||
<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>
|
||||
|
||||
{#if info}
|
||||
<div class="flex justify-center content-center text-center">
|
||||
<article class="prose">
|
||||
<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}
|
||||
{#if info.capital}
|
||||
<p><b>Capital:</b> {info.capital}</p>
|
||||
{/if}
|
||||
{#if info.population}
|
||||
<p>
|
||||
<b>Population:</b>
|
||||
{info.population.estimate} ({info.population.year})
|
||||
</p>
|
||||
{/if}
|
||||
{#if info.area}
|
||||
<p><b>Area:</b> {info.area.total} {info.area.units}</p>
|
||||
{/if}
|
||||
{#if info.state_flower}
|
||||
<p><b>State Flower:</b> {info.state_flower}</p>
|
||||
{/if}
|
||||
{#if info.state_bird}
|
||||
<p><b>State Bird:</b> {info.state_bird}</p>
|
||||
{/if}
|
||||
{#if info.state_tree}
|
||||
<p><b>State Tree:</b> {info.state_tree}</p>
|
||||
{/if}
|
||||
{#if info.climate}
|
||||
<p><b>Climate:</b> {info.climate.description}</p>
|
||||
<p><b>Summer Highs:</b> {info.climate.summer_highs}</p>
|
||||
<p><b>Winter Lows:</b> {info.climate.winter_lows}</p>
|
||||
<p><b>Precipitation:</b> {info.climate.precipitation}</p>
|
||||
{/if}
|
||||
{#if info.economy}
|
||||
{#if info.economy.industries && info.economy.industries.length}
|
||||
<p>
|
||||
<b>Industries:</b>
|
||||
{info.economy.industries.join(", ")}
|
||||
</p>
|
||||
{/if}
|
||||
{#if info.economy.agricultural_products && info.economy.agricultural_products.length}
|
||||
<p>
|
||||
<b>Agricultural Products:</b>
|
||||
{info.economy.agricultural_products.join(", ")}
|
||||
</p>
|
||||
{/if}
|
||||
{/if}
|
||||
{#if info.tourism}
|
||||
{#if info.tourism.attractions && info.tourism.attractions.length}
|
||||
<p>
|
||||
<b>Tourism Attractions:</b>
|
||||
{info.tourism.attractions.join(", ")}
|
||||
</p>
|
||||
{/if}
|
||||
{/if}
|
||||
{#if info.major_sports_teams && info.major_sports_teams.length}
|
||||
<p>
|
||||
<b>Major Sports Teams:</b>
|
||||
{info.major_sports_teams.join(", ")}
|
||||
</p>
|
||||
{/if}
|
||||
</article>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="flex justify-center content-center text-center">
|
||||
<article class="prose">
|
||||
<h1>Region Not Found</h1>
|
||||
<p>Sorry, we couldn't find the region you were looking for.</p>
|
||||
</article>
|
||||
</div>
|
||||
{/if}
|
Loading…
Add table
Add a link
Reference in a new issue