show the neighbourhood

This commit is contained in:
Yanick Champoux 2024-02-05 10:30:23 -05:00
parent e83f25461d
commit 08d391010d
6 changed files with 59 additions and 25 deletions

View File

@ -9,9 +9,11 @@ tasks:
export-db: export-db:
cmds: cmds:
- sqlite3 /home/bggsell/games.db '.mode json' '.once /home/bggsell/db/games.json' 'select * from game' - sqlite3 /home/bggsell/games.db '.mode json' '.once /home/bggsell/db/games.json' 'select * from game'
- sqlite3 /home/bggsell/games.db '.mode json' '.once /home/bggsell/db/sellers.json' 'select * from bgg_user'
export-db:dev: export-db:dev:
cmds: cmds:
- sqlite3 games.db '.mode json' '.once static/dev/games.json' 'select * from game' - sqlite3 games.db '.mode json' '.once static/dev/games.json' 'select * from game'
- sqlite3 games.db '.mode json' '.once static/dev/sellers.json' 'select * from bgg_user'
deploy: deploy:
deps: [build] deps: [build]

View File

@ -7,7 +7,37 @@
<script> <script>
import 'beercss/dist/cdn/beer.min.css'; import 'beercss/dist/cdn/beer.min.css';
//import beercss from "./dist/cdn/beer.min.js"; import { setContext } from 'svelte';
import { dev, browser } from '$app/environment';
import { readable } from 'svelte/store';
const prefix = dev ? '/dev/' : '/db/';
const games = readable([], async (set) => {
if (!browser) return () => {};
fetch(prefix + 'games.json')
.then((doc) => doc.json())
.then(set);
return () => {};
});
setContext('games', games);
const sellers = readable({}, async (set) => {
if (!browser) return () => {};
const sellers_list = await fetch(prefix + 'sellers.json').then((doc) =>
doc.json(),
);
set(
Object.fromEntries(
sellers_list.map((seller) => [seller.username, seller]),
),
);
return () => {};
});
setContext('sellers', sellers);
</script> </script>
<style> <style>

View File

@ -1,9 +0,0 @@
import { dev, browser } from '$app/environment';
export async function load({ fetch }) {
const url = dev ? '/dev/games.json' : '/games.json';
return {
games: browser ? fetch(url).then((doc) => doc.json()) : [],
};
}

View File

@ -8,7 +8,7 @@
</header> </header>
<article> <article>
{#await data.games} {#await $games}
<div class="medium-height middle-align center-align"> <div class="medium-height middle-align center-align">
<div class="center-align"> <div class="center-align">
<progress class="circle"></progress> <progress class="circle"></progress>
@ -17,17 +17,17 @@
</div> </div>
</div> </div>
{:then games} {:then games}
<GameList {games} /> <GameList {games} sellers={$sellers} />
{/await} {/await}
</article> </article>
<script> <script>
// TODO hide games I'm not interested in import { getContext } from 'svelte';
// TODO add cart
// TODO prettify via beercss
import GameList from './GameList.svelte'; import GameList from './GameList.svelte';
export let data; const games = getContext('games');
const sellers = getContext('sellers');
$: console.log($sellers);
function pretty_date(date) { function pretty_date(date) {
if (!date) return ''; if (!date) return '';

View File

@ -17,15 +17,20 @@
</strong> </strong>
</div> </div>
<div class="s3"> <div class="s3">
<a <div>
target="_blank" <a
href={`https://boardgamegeek.com/collection/user/${game.username}?trade=1&subtype=boardgame&ff=1`} target="_blank"
>{game.username}</a> href={`https://boardgamegeek.com/collection/user/${game.username}?trade=1&subtype=boardgame&ff=1`}
&nbsp; >{game.username}</a>
<a &nbsp;
target="_blank" <a
href={`https://boardgamegeek.com/geekmail/compose?touser=${game.username}`}> target="_blank"
<i>email</i></a> href={`https://boardgamegeek.com/geekmail/compose?touser=${game.username}`}>
<i>email</i></a>
</div>
<div class="neighbourhood">
{sellers[game.username]?.neighbourhood ?? ''}
</div>
</div> </div>
<div class="s1 right-align"> <div class="s1 right-align">
{game.price ? '$' + game.price : ''} {game.price ? '$' + game.price : ''}
@ -44,6 +49,7 @@
<script> <script>
export let games; export let games;
export let sellers = {};
// add filter // add filter
// add sort (user, game, price) // add sort (user, game, price)
@ -78,4 +84,7 @@
.updated-at::before { .updated-at::before {
content: 'last update: '; content: 'last update: ';
} }
.neighbourhood {
font-size: smaller;
}
</style> </style>

2
static/dev/sellers.json Normal file
View File

@ -0,0 +1,2 @@
[{"username":"yenzie","neighbourhood":"Bells Corners"},
{"username":"jmarkmoss","neighbourhood":null}]