From 2bbeefa26a76cd5961d216a48e4083c9fd996ccb Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Tue, 6 Feb 2024 13:05:52 -0500 Subject: [PATCH 1/2] add listing stats --- package.json | 4 +-- src/lib/components/BggUser.svelte | 13 +++++++ src/routes/+layout.svelte | 21 ++++++------ src/routes/+page.svelte | 3 +- src/routes/stats/+page.svelte | 56 +++++++++++++++++++++++++++++++ 5 files changed, 82 insertions(+), 15 deletions(-) create mode 100644 src/lib/components/BggUser.svelte create mode 100644 src/routes/stats/+page.svelte diff --git a/package.json b/package.json index 2387378..e29b348 100644 --- a/package.json +++ b/package.json @@ -17,8 +17,7 @@ "devDependencies": { "@changesets/cli": "^2.27.1", "@playwright/test": "^1.28.1", - "@sveltejs/adapter-auto": "^3.0.0", - "@sveltejs/kit": "^2.0.0", + "@sveltejs/kit": "^2.5.0", "@sveltejs/vite-plugin-svelte": "^3.0.0", "@types/eslint": "8.56.0", "eslint": "^8.56.0", @@ -34,7 +33,6 @@ }, "type": "module", "dependencies": { - "@sveltejs/adapter-node": "^4.0.1", "@sveltejs/adapter-static": "^3.0.1", "@vincjo/datatables": "^1.14.4", "@yanick/updeep-remeda": "^2.2.0", diff --git a/src/lib/components/BggUser.svelte b/src/lib/components/BggUser.svelte new file mode 100644 index 0000000..655171f --- /dev/null +++ b/src/lib/components/BggUser.svelte @@ -0,0 +1,13 @@ +{username} + + + + diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 3dad5c6..9d64f03 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -15,7 +15,7 @@ const prefix = dev ? '/dev/' : '/db/'; - const games = readable([], async (set) => { + const games = readable([], (set) => { if (!browser) return () => {}; fetch(prefix + 'games.json') @@ -26,17 +26,18 @@ }); setContext('games', games); - const sellers = readable({}, async (set) => { + const sellers = readable({}, (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]), - ), - ); + const sellers_list = fetch(prefix + 'sellers.json') + .then((doc) => doc.json()) + .then((sellers_list) => + set( + Object.fromEntries( + sellers_list.map((seller) => [seller.username, seller]), + ), + ), + ); return () => {}; }); setContext('sellers', sellers); diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 8919ede..153cfce 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1,7 +1,7 @@
@@ -27,7 +27,6 @@ const games = getContext('games'); const sellers = getContext('sellers'); - $: console.log($sellers); function pretty_date(date) { if (!date) return ''; diff --git a/src/routes/stats/+page.svelte b/src/routes/stats/+page.svelte new file mode 100644 index 0000000..d7f5499 --- /dev/null +++ b/src/routes/stats/+page.svelte @@ -0,0 +1,56 @@ +
+ +
+ +
+

Currently listing {nbr_games} games from {nbr_sellers} sellers.

+ + {#each Object.keys($sellers).sort() as username (username)} +
+ + + {#if $sellers[username].neighbourhood} + ({$sellers[username].neighbourhood}) + {/if} + + + {nbr_games_for(username)} + +
+ {/each} +
+ + + + From 23359b86ee1dbe509c42d014ab7bf7afd082c460 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Tue, 6 Feb 2024 15:40:47 -0500 Subject: [PATCH 2/2] add the stats and the menu --- src/lib/directives/clickOutside.js | 15 +++++++++ src/routes/+layout.svelte | 3 ++ src/routes/+page.svelte | 9 ------ src/routes/AppTop.svelte | 50 ++++++++++++++++++++++++++++++ src/routes/about/+page.svelte | 9 ------ src/routes/stats/+page.svelte | 14 +++------ 6 files changed, 72 insertions(+), 28 deletions(-) create mode 100644 src/lib/directives/clickOutside.js create mode 100644 src/routes/AppTop.svelte diff --git a/src/lib/directives/clickOutside.js b/src/lib/directives/clickOutside.js new file mode 100644 index 0000000..ccaa7de --- /dev/null +++ b/src/lib/directives/clickOutside.js @@ -0,0 +1,15 @@ +export default function clickOutside(node) { + const handleClick = (event) => { + if (node && !node.contains(event.target) && !event.defaultPrevented) { + node.dispatchEvent(new CustomEvent('click_outside', node)); + } + }; + + document.addEventListener('click', handleClick, true); + + return { + destroy() { + document.removeEventListener('click', handleClick, true); + }, + }; +} diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 9d64f03..285837c 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -2,16 +2,19 @@ Ottawa board games, trades and sales
+
+ + diff --git a/src/routes/about/+page.svelte b/src/routes/about/+page.svelte index fbe1276..624a567 100644 --- a/src/routes/about/+page.svelte +++ b/src/routes/about/+page.svelte @@ -1,12 +1,3 @@ -
- -
-

bgg.babyl.ca is an aggregation of board games for sale or diff --git a/src/routes/stats/+page.svelte b/src/routes/stats/+page.svelte index d7f5499..587ebb3 100644 --- a/src/routes/stats/+page.svelte +++ b/src/routes/stats/+page.svelte @@ -1,12 +1,3 @@ -

- -
-

Currently listing {nbr_games} games from {nbr_sellers} sellers.

@@ -27,7 +18,6 @@