mirror of
https://github.com/BradNut/boredgame
synced 2025-09-08 17:40:22 +00:00
Showing different content based on logged in status. Probably not the best way.
This commit is contained in:
parent
b02609f009
commit
d111482708
3 changed files with 75 additions and 79 deletions
|
|
@ -1,35 +1,24 @@
|
||||||
import { error } from '@sveltejs/kit';
|
import { error } from '@sveltejs/kit';
|
||||||
|
import prisma from '$lib/prisma.js';
|
||||||
import { boardGameApi } from '../../api';
|
import { boardGameApi } from '../../api';
|
||||||
|
|
||||||
export const load = async ({ params, setHeaders }) => {
|
export const load = async ({ params, setHeaders, locals }) => {
|
||||||
const queryParams = {
|
try {
|
||||||
ids: `${params?.id}`,
|
const { user } = locals;
|
||||||
fields:
|
const { id } = params;
|
||||||
'id,name,price,min_age,min_players,max_players,thumb_url,playtime,min_playtime,max_playtime,min_age,description,year_published,url,image_url'
|
const game = await prisma.game.findUnique({
|
||||||
};
|
where: {
|
||||||
|
id
|
||||||
const response = await boardGameApi('get', `search`, queryParams);
|
}
|
||||||
|
|
||||||
if (response.status === 200) {
|
|
||||||
const gameResponse = await response.json();
|
|
||||||
|
|
||||||
setHeaders({
|
|
||||||
'Cache-Control': 'max-age=3600'
|
|
||||||
});
|
});
|
||||||
|
console.log('found game', game);
|
||||||
const game = gameResponse?.games[0];
|
|
||||||
if (game.min_players) {
|
|
||||||
game.players = `${game.min_players}-${game.max_players}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (game.min_playtime) {
|
|
||||||
game.playtime = `${game.min_playtime}-${game.max_playtime}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
game
|
game,
|
||||||
|
user
|
||||||
};
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw error(response.status, 'not found');
|
throw error(404, 'not found');
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -32,16 +32,19 @@
|
||||||
$: wishlistText = existsInWishlist ? 'Remove from wishlist' : 'Add to wishlist';
|
$: wishlistText = existsInWishlist ? 'Remove from wishlist' : 'Add to wishlist';
|
||||||
|
|
||||||
export let data: PageData;
|
export let data: PageData;
|
||||||
let game: GameType;
|
console.log('data', data);
|
||||||
$: ({ game } = data);
|
// let game: GameType;
|
||||||
|
$: ({ game, user } = data);
|
||||||
|
// let game = data?.game;
|
||||||
// export let game: GameType = data?.game;
|
// export let game: GameType = data?.game;
|
||||||
let seeMore: boolean = false;
|
let seeMore: boolean = false;
|
||||||
let firstParagraphEnd = 0;
|
console.log('game', game);
|
||||||
if (game?.description?.indexOf('</p>') > 0) {
|
// let firstParagraphEnd = 0;
|
||||||
firstParagraphEnd = game?.description?.indexOf('</p>') + 4;
|
// if (game?.description?.indexOf('</p>') > 0) {
|
||||||
} else if (game?.description?.indexOf('</ p>') > 0) {
|
// firstParagraphEnd = game?.description?.indexOf('</p>') + 4;
|
||||||
firstParagraphEnd = game?.description?.indexOf('</ p>') + 5;
|
// } else if (game?.description?.indexOf('</ p>') > 0) {
|
||||||
}
|
// firstParagraphEnd = game?.description?.indexOf('</ p>') + 5;
|
||||||
|
// }
|
||||||
|
|
||||||
function onCollectionClick() {
|
function onCollectionClick() {
|
||||||
if (existsInCollection) {
|
if (existsInCollection) {
|
||||||
|
|
@ -100,8 +103,8 @@
|
||||||
{#if game?.year_published}
|
{#if game?.year_published}
|
||||||
<p>Year: {game?.year_published}</p>
|
<p>Year: {game?.year_published}</p>
|
||||||
{/if}
|
{/if}
|
||||||
{#if game?.players}
|
{#if game?.min_players && game?.max_players}
|
||||||
<p>Players: {game.players}</p>
|
<p>Players: {game.min_players} - {game.max_players}</p>
|
||||||
{/if}
|
{/if}
|
||||||
{#if game?.playtime}
|
{#if game?.playtime}
|
||||||
<p>Playtime: {game.playtime} minutes</p>
|
<p>Playtime: {game.playtime} minutes</p>
|
||||||
|
|
@ -109,13 +112,11 @@
|
||||||
{#if game?.min_age}
|
{#if game?.min_age}
|
||||||
<p>Minimum Age: {game.min_age}</p>
|
<p>Minimum Age: {game.min_age}</p>
|
||||||
{/if}
|
{/if}
|
||||||
{#if +game?.price !== 0.0}
|
|
||||||
<p>Price: ${game?.price}</p>
|
|
||||||
{/if}
|
|
||||||
<LinkWithIcon external ariaLabel={`Board Game Atlas Link for ${game.name}`} url={game.url}>
|
<LinkWithIcon external ariaLabel={`Board Game Atlas Link for ${game.name}`} url={game.url}>
|
||||||
Board Game Atlas <ExternalLinkIcon width="24" height="24" />
|
Board Game Atlas <ExternalLinkIcon width="24" height="24" />
|
||||||
</LinkWithIcon>
|
</LinkWithIcon>
|
||||||
</div>
|
</div>
|
||||||
|
{#if user?.username}
|
||||||
<div style="display: grid; gap: 1.5rem; place-content: center;">
|
<div style="display: grid; gap: 1.5rem; place-content: center;">
|
||||||
<Button size="md" kind={existsInCollection ? 'danger' : 'primary'} icon on:click={onCollectionClick}>
|
<Button size="md" kind={existsInCollection ? 'danger' : 'primary'} icon on:click={onCollectionClick}>
|
||||||
{collectionText}
|
{collectionText}
|
||||||
|
|
@ -134,17 +135,22 @@
|
||||||
{/if}
|
{/if}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
{:else}
|
||||||
|
<span>
|
||||||
|
<a href="/auth/signup">Sign Up</a> or <a href="/auth/signin">Sign In</a> to collect this game
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
{#if firstParagraphEnd > 0}
|
{#if game?.description_preview}
|
||||||
<section class="description" style="margin-top: 2rem;">
|
{#if !seeMore}
|
||||||
{@html game?.description?.substring(0, firstParagraphEnd)}
|
<section class="description" style="margin-top: 2rem;" in:fly={{ opacity: 0, x: 100 }} out:fly={{ opacity: 0, x: -100 }}>
|
||||||
|
{`${game?.description_preview.substring(0, 250)}...`}
|
||||||
</section>
|
</section>
|
||||||
{#if game?.description?.substring(firstParagraphEnd + 1) !== ''}
|
{/if}
|
||||||
<section class="description">
|
|
||||||
{#if seeMore}
|
{#if seeMore}
|
||||||
<div class="overflow-description" in:fly={{ opacity: 0, x: 100 }} out:fade>
|
<div class="overflow-description" in:fly={{ opacity: 0, x: 100 }} out:fade>
|
||||||
{@html game?.description?.substring(firstParagraphEnd + 1)}
|
{@html game?.description}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
<button class="btn button-icon" type="button" on:click={() => (seeMore = !seeMore)}
|
<button class="btn button-icon" type="button" on:click={() => (seeMore = !seeMore)}
|
||||||
|
|
@ -155,8 +161,6 @@
|
||||||
Less <MinusIcon width="24" height="24" />
|
Less <MinusIcon width="24" height="24" />
|
||||||
{/if}
|
{/if}
|
||||||
</button>
|
</button>
|
||||||
</section>
|
|
||||||
{/if}
|
|
||||||
{:else}
|
{:else}
|
||||||
<section class="description">
|
<section class="description">
|
||||||
<span>
|
<span>
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ async function searchForGames(urlQueryParams: SearchQuery) {
|
||||||
lte: urlQueryParams?.max_playtime || 5000
|
lte: urlQueryParams?.max_playtime || 5000
|
||||||
},
|
},
|
||||||
min_age: {
|
min_age: {
|
||||||
gte: urlQueryParams?.min_age || 130
|
gte: urlQueryParams?.min_age || 0
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
skip: urlQueryParams?.skip,
|
skip: urlQueryParams?.skip,
|
||||||
|
|
@ -79,7 +79,7 @@ async function searchForGames(urlQueryParams: SearchQuery) {
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
totalCount: dbGames.length,
|
totalCount: dbGames.length,
|
||||||
dbGames
|
games: dbGames
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
@ -98,6 +98,8 @@ async function createOrUpdateGame(game: GameType) {
|
||||||
const mechanicIds = game.mechanics.map((mechanic) => ({
|
const mechanicIds = game.mechanics.map((mechanic) => ({
|
||||||
external_id: mechanic.id
|
external_id: mechanic.id
|
||||||
}));
|
}));
|
||||||
|
console.log('categoryIds', categoryIds);
|
||||||
|
console.log('mechanicIds', mechanicIds);
|
||||||
return await prisma.game.upsert({
|
return await prisma.game.upsert({
|
||||||
where: {
|
where: {
|
||||||
external_id: game.id
|
external_id: game.id
|
||||||
|
|
@ -154,7 +156,8 @@ async function createOrUpdateGame(game: GameType) {
|
||||||
},
|
},
|
||||||
create: {
|
create: {
|
||||||
external_id: game.primary_publisher.id,
|
external_id: game.primary_publisher.id,
|
||||||
name: game.primary_publisher.name
|
name: game.primary_publisher.name,
|
||||||
|
slug: kebabCase(game.primary_publisher.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue