Fixing code and naming.

This commit is contained in:
Bradley Shellnut 2024-04-17 13:57:25 -07:00
parent 842e9c72bf
commit ad5062b91c
3 changed files with 28 additions and 28 deletions

View file

@ -34,7 +34,12 @@ export async function load(event) {
try { try {
const collection = await db.query.collections.findFirst({ const collection = await db.query.collections.findFirst({
where: and(eq(collections.user_id, user.id), eq(collections.id, id)), columns: {
id: true,
cuid: true,
name: true,
},
where: and(eq(collections.user_id, user.id), eq(collections.cuid, id)),
}); });
console.log('collection', collection); console.log('collection', collection);
@ -49,6 +54,10 @@ export async function load(event) {
} }
const collectionItems = await db.query.collection_items.findMany({ const collectionItems = await db.query.collection_items.findMany({
columns: {
collection_id: true,
times_played: true,
},
where: eq(collection_items.collection_id, collection.id), where: eq(collection_items.collection_id, collection.id),
with: { with: {
game: { game: {
@ -70,22 +79,22 @@ export async function load(event) {
console.log('item', item); console.log('item', item);
const game = item.game; const game = item.game;
if (game) { if (game) {
let collectionItem: ListGame = { items.push({
id: game.id, id: game.id,
collection_id: item.collection_id, collection_id: item.collection_id,
name: game.name, game_name: game.name ?? "Game doesn't have a name",
thumb_url: game.thumb_url, thumb_url: game.thumb_url,
times_played: item.times_played, times_played: item.times_played ?? 0,
in_collection: true, in_collection: true,
}; });
items.push(collectionItem);
} }
} }
return { return {
searchForm, searchForm,
listManageForm, listManageForm,
collection: items, collection,
items,
}; };
} catch (e) { } catch (e) {
console.error(e); console.error(e);
@ -94,7 +103,10 @@ export async function load(event) {
return { return {
searchForm, searchForm,
listManageForm, listManageForm,
collection: [], collection: {
name: "Collection doesn't have a name",
},
items: [],
}; };
} }

View file

@ -4,8 +4,9 @@
export let data; export let data;
console.log(`Page data: ${JSON.stringify(data)}`); console.log(`Page data: ${JSON.stringify(data)}`);
let collectionItems = data?.collection || []; let collection = data?.collection ?? {};
console.log('collectionItems', collectionItems); let items = data?.items || [];
console.log('items', items);
// async function handleNextPageEvent(event: CustomEvent) { // async function handleNextPageEvent(event: CustomEvent) {
// if (+event?.detail?.page === page + 1) { // if (+event?.detail?.page === page + 1) {
@ -29,18 +30,18 @@
</script> </script>
<svelte:head> <svelte:head>
<title>Your Collection | Bored Game</title> <title>{collection.name ?? 'Your Collection'} | Bored Game</title>
</svelte:head> </svelte:head>
<h1>Your Collection</h1> <h1>{collection.name ?? 'Your Collection'}</h1>
<!-- <input type="text" id="search" name="search" placeholder="Search Your Collection" bind:value={$searchStore.search} /> --> <!-- <input type="text" id="search" name="search" placeholder="Search Your Collection" bind:value={$searchStore.search} /> -->
<div class="games"> <div class="games">
<div class="games-list"> <div class="games-list">
{#if collectionItems.length === 0} {#if items.length === 0}
<h2>No games in your collection</h2> <h2>No games in your collection</h2>
{:else} {:else}
{#each collectionItems as game (game.game_id)} {#each items as game (game.game_id)}
<Game {game} /> <Game {game} />
{/each} {/each}
{/if} {/if}

View file

@ -26,23 +26,10 @@ export async function load(event) {
redirect(302, '/404'); redirect(302, '/404');
} }
const items = await db.query.wishlist_items.findMany({
where: eq(wishlist_items.wishlist_id, wishlist.id),
with: {
game: {
columns: {
id: true,
name: true,
thumb_url: true,
},
},
},
});
console.log('wishlist', wishlist); console.log('wishlist', wishlist);
return { return {
items, wishlist,
}; };
} catch (e) { } catch (e) {
console.error(e); console.error(e);