mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-27 16:59:37 +02:00
Merge pull request #98 from seanmorley15/development
chore: Update TripListModal and setup page to insert event data durin…
This commit is contained in:
commit
aa7c85dd90
4 changed files with 162 additions and 18 deletions
|
@ -125,7 +125,7 @@
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{#if viewType == "url"}
|
{#if viewType == "url"}
|
||||||
<button class="btn btn-secondary" on:click={searchImage}
|
<button class="btn btn-secondary mb-2" on:click={searchImage}
|
||||||
>Search for Image</button
|
>Search for Image</button
|
||||||
>
|
>
|
||||||
<form method="dialog" style="width: 100%;" class="mb-4">
|
<form method="dialog" style="width: 100%;" class="mb-4">
|
||||||
|
@ -135,6 +135,7 @@
|
||||||
type="text"
|
type="text"
|
||||||
id="imageUrl"
|
id="imageUrl"
|
||||||
bind:value={imageUrl}
|
bind:value={imageUrl}
|
||||||
|
class="input input-bordered w-full max-w-xs"
|
||||||
placeholder="Enter the URL of the image"
|
placeholder="Enter the URL of the image"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -149,12 +150,13 @@
|
||||||
id="imageFile"
|
id="imageFile"
|
||||||
on:change={handleFileChange}
|
on:change={handleFileChange}
|
||||||
placeholder="Upload an image file"
|
placeholder="Upload an image file"
|
||||||
|
class="input input-bordered w-full max-w-xs"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<button class="btn btn-neutral" on:click={close}>Close</button>
|
|
||||||
<button class="btn btn-primary" on:click={submit}>Submit</button>
|
<button class="btn btn-primary" on:click={submit}>Submit</button>
|
||||||
|
<button class="btn btn-neutral" on:click={close}>Close</button>
|
||||||
</div>
|
</div>
|
||||||
</dialog>
|
</dialog>
|
||||||
|
|
|
@ -45,6 +45,9 @@
|
||||||
</button>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
{/each}
|
{/each}
|
||||||
|
{#if trips.length === 0}
|
||||||
|
<p>No trips found</p>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
<!-- close button -->
|
<!-- close button -->
|
||||||
<button class="btn btn-neutral" on:click={close}>Close</button>
|
<button class="btn btn-neutral" on:click={close}>Close</button>
|
||||||
|
|
|
@ -1,23 +1,162 @@
|
||||||
import { sql } from "drizzle-orm";
|
import { sql } from "drizzle-orm";
|
||||||
import { db } from "./db.server";
|
import { db } from "./db.server";
|
||||||
|
import { imagesTable } from "./schema";
|
||||||
|
|
||||||
export async function insertData() {
|
export async function insertData(event: { fetch: any }) {
|
||||||
// insets default featured adventures
|
// insets default featured adventures
|
||||||
console.log("Inserting default featured adventures...");
|
console.log("Inserting default featured adventures...");
|
||||||
await db.execute(sql`INSERT INTO "adventures" (name, location, type) VALUES
|
|
||||||
('Yellowstone National Park', 'Wyoming, Montana, Idaho, USA', 'featured'),
|
// upload image for featured adventures
|
||||||
('Yosemite National Park', 'California, USA', 'featured'),
|
|
||||||
('Banff National Park', 'Alberta, Canada', 'featured'),
|
const featuredImages = {
|
||||||
('Kruger National Park', 'Limpopo, South Africa', 'featured'),
|
"Yellowstone National Park": {
|
||||||
('Grand Canyon National Park', 'Arizona, USA', 'featured'),
|
location: "Wyoming, Montana, Idaho, USA",
|
||||||
('Great Smoky Mountains National Park', 'North Carolina, Tennessee, USA', 'featured'),
|
url: "https://upload.wikimedia.org/wikipedia/commons/7/73/Grand_Canyon_of_yellowstone.jpg",
|
||||||
('Zion National Park', 'Utah, USA', 'featured'),
|
key: "",
|
||||||
('Glacier National Park', 'Montana, USA', 'featured'),
|
},
|
||||||
('Rocky Mountain National Park', 'Colorado, USA', 'featured'),
|
"Yosemite National Park": {
|
||||||
('Everglades National Park', 'Florida, USA', 'featured'),
|
location: "California, USA",
|
||||||
('Arches National Park', 'Utah, USA', 'featured'),
|
url: "https://upload.wikimedia.org/wikipedia/commons/1/13/Tunnel_View%2C_Yosemite_Valley%2C_Yosemite_NP_-_Diliff.jpg",
|
||||||
('Acadia National Park', 'Maine, USA', 'featured'),
|
key: "",
|
||||||
('Sequoia National Park', 'California, USA', 'featured');`);
|
},
|
||||||
|
"Banff National Park": {
|
||||||
|
location: "Alberta, Canada",
|
||||||
|
url: "https://upload.wikimedia.org/wikipedia/commons/c/c5/Moraine_Lake_17092005.jpg",
|
||||||
|
key: "",
|
||||||
|
},
|
||||||
|
"Kruger National Park": {
|
||||||
|
location: "Limpopo, South Africa",
|
||||||
|
url: "https://upload.wikimedia.org/wikipedia/commons/f/f0/Kruger_Zebra.JPG",
|
||||||
|
key: "",
|
||||||
|
},
|
||||||
|
"Grand Canyon National Park": {
|
||||||
|
location: "Arizona, USA",
|
||||||
|
url: "https://upload.wikimedia.org/wikipedia/commons/a/aa/Dawn_on_the_S_rim_of_the_Grand_Canyon_%288645178272%29.jpg",
|
||||||
|
key: "",
|
||||||
|
},
|
||||||
|
"Great Smoky Mountains National Park": {
|
||||||
|
location: "North Carolina, Tennessee, USA",
|
||||||
|
url: "https://upload.wikimedia.org/wikipedia/commons/b/bc/View_atop_Cliff_Tops_on_Mount_LeConte%2C_GSMNP%2C_TN.jpg",
|
||||||
|
key: "",
|
||||||
|
},
|
||||||
|
"Zion National Park": {
|
||||||
|
location: "Utah, USA",
|
||||||
|
url: "https://upload.wikimedia.org/wikipedia/commons/1/10/Zion_angels_landing_view.jpg",
|
||||||
|
key: "",
|
||||||
|
},
|
||||||
|
"Glacier National Park": {
|
||||||
|
location: "Montana, USA",
|
||||||
|
url: "https://upload.wikimedia.org/wikipedia/commons/5/51/Mountain_Goat_at_Hidden_Lake.jpg",
|
||||||
|
key: "",
|
||||||
|
},
|
||||||
|
"Rocky Mountain National Park": {
|
||||||
|
location: "Colorado, USA",
|
||||||
|
url: "https://upload.wikimedia.org/wikipedia/commons/thumb/b/b9/Rocky_Mountain_National_Park_in_September_2011_-_view_from_Many_Parks_Curve.JPG/2560px-Rocky_Mountain_National_Park_in_September_2011_-_view_from_Many_Parks_Curve.JPG",
|
||||||
|
key: "",
|
||||||
|
},
|
||||||
|
"Everglades National Park": {
|
||||||
|
location: "Florida, USA",
|
||||||
|
url: "https://upload.wikimedia.org/wikipedia/commons/2/2a/Sunset_over_the_River_of_Grass%2C_NPSphoto%2C_G.Gardner_%289255157507%29.jpg",
|
||||||
|
key: "",
|
||||||
|
},
|
||||||
|
"Arches National Park": {
|
||||||
|
location: "Utah, USA",
|
||||||
|
url: "https://upload.wikimedia.org/wikipedia/commons/f/f0/Delicate_arch_sunset.jpg",
|
||||||
|
key: "",
|
||||||
|
},
|
||||||
|
"Acadia National Park": {
|
||||||
|
location: "Maine, USA",
|
||||||
|
url: "https://upload.wikimedia.org/wikipedia/commons/7/76/Bass_Harbor_Lighthouse_b.jpg",
|
||||||
|
key: "",
|
||||||
|
},
|
||||||
|
"Sequoia National Park": {
|
||||||
|
location: "California, USA",
|
||||||
|
url: "https://upload.wikimedia.org/wikipedia/commons/7/76/Bass_Harbor_Lighthouse_b.jpg",
|
||||||
|
key: "",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const [name, { url }] of Object.entries(featuredImages)) {
|
||||||
|
const response = await event.fetch(url);
|
||||||
|
const blob = await response.blob();
|
||||||
|
const uploadResponse = await event.fetch("/api/upload", {
|
||||||
|
method: "POST",
|
||||||
|
body: blob,
|
||||||
|
headers: {
|
||||||
|
bucket: "adventures",
|
||||||
|
type: "adventure",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
//console.log("uploadResponse", uploadResponse);
|
||||||
|
const waiting = await uploadResponse.json();
|
||||||
|
|
||||||
|
(featuredImages as { [key: string]: { url: string; key: string } })[
|
||||||
|
name
|
||||||
|
].key = waiting.key;
|
||||||
|
console.log(waiting.key as string);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(featuredImages);
|
||||||
|
|
||||||
|
// const insertValues = [];
|
||||||
|
|
||||||
|
// // Iterate over the featuredImages object to build the insertValues array
|
||||||
|
// for (const [name, { location, key }] of Object.entries(featuredImages)) {
|
||||||
|
// console.log(name, location, key);
|
||||||
|
// insertValues.push(`('${name}', '${location}', 'featured', '${key}')`);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // Construct the SQL query
|
||||||
|
// const sqlQuery = `
|
||||||
|
// INSERT INTO "adventures" (name, location, type, imageUrl) VALUES
|
||||||
|
// ${insertValues.join(", ")}
|
||||||
|
// `;
|
||||||
|
|
||||||
|
// // Now execute the SQL query using your database library (assuming `db` has a method like `execute`)
|
||||||
|
// await db.execute(sql`${sqlQuery}`);
|
||||||
|
|
||||||
|
await db.execute(sql`
|
||||||
|
INSERT INTO "adventures" (name, location, type, "imageUrl") VALUES
|
||||||
|
('Yellowstone National Park', 'Wyoming, Montana, Idaho, USA', 'featured', ${
|
||||||
|
featuredImages["Yellowstone National Park"].key
|
||||||
|
}),
|
||||||
|
('Yosemite National Park', 'California, USA', 'featured', ${
|
||||||
|
featuredImages["Yosemite National Park"].key
|
||||||
|
}),
|
||||||
|
('Banff National Park', 'Alberta, Canada', 'featured', ${
|
||||||
|
featuredImages["Banff National Park"].key
|
||||||
|
}),
|
||||||
|
('Kruger National Park', 'Limpopo, South Africa', 'featured', ${
|
||||||
|
featuredImages["Kruger National Park"].key
|
||||||
|
}),
|
||||||
|
('Grand Canyon National Park', 'Arizona, USA', 'featured', ${
|
||||||
|
featuredImages["Grand Canyon National Park"].key
|
||||||
|
}),
|
||||||
|
('Great Smoky Mountains National Park', 'North Carolina, Tennessee, USA', 'featured', ${
|
||||||
|
featuredImages["Great Smoky Mountains National Park"].key
|
||||||
|
}),
|
||||||
|
('Zion National Park', 'Utah, USA', 'featured', ${
|
||||||
|
featuredImages["Zion National Park"].key
|
||||||
|
}),
|
||||||
|
('Glacier National Park', 'Montana, USA', 'featured', ${
|
||||||
|
featuredImages["Glacier National Park"].key
|
||||||
|
}),
|
||||||
|
('Rocky Mountain National Park', 'Colorado, USA', 'featured', ${
|
||||||
|
featuredImages["Rocky Mountain National Park"].key || "default_key_value"
|
||||||
|
}), -- Handle undefined key
|
||||||
|
('Everglades National Park', 'Florida, USA', 'featured', ${
|
||||||
|
featuredImages["Everglades National Park"].key
|
||||||
|
}),
|
||||||
|
('Arches National Park', 'Utah, USA', 'featured', ${
|
||||||
|
featuredImages["Arches National Park"].key
|
||||||
|
}),
|
||||||
|
('Acadia National Park', 'Maine, USA', 'featured', ${
|
||||||
|
featuredImages["Acadia National Park"].key
|
||||||
|
}),
|
||||||
|
('Sequoia National Park', 'California, USA', 'featured', ${
|
||||||
|
featuredImages["Sequoia National Park"].key
|
||||||
|
});
|
||||||
|
`);
|
||||||
|
|
||||||
console.log("Inserting countries...");
|
console.log("Inserting countries...");
|
||||||
await db.execute(sql`INSERT INTO "worldTravelCountries" (name, country_code, continent)
|
await db.execute(sql`INSERT INTO "worldTravelCountries" (name, country_code, continent)
|
||||||
|
|
|
@ -119,7 +119,7 @@ export const actions: Actions = {
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
// inserts the data needed for all of the pre defined adventures and world travel regions
|
// inserts the data needed for all of the pre defined adventures and world travel regions
|
||||||
await insertData();
|
await insertData(event);
|
||||||
|
|
||||||
const session: any = await lucia.createSession(userId, {});
|
const session: any = await lucia.createSession(userId, {});
|
||||||
const sessionCookie: any = lucia.createSessionCookie(session.id);
|
const sessionCookie: any = lucia.createSessionCookie(session.id);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue