From b8ac795ad69f59e796c1fa0e034a17a7422aec4d Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Mon, 5 Feb 2024 14:35:35 -0500 Subject: [PATCH] can hide games --- package.json | 2 + src/routes/+layout.svelte | 18 ++++- src/routes/GameList.svelte | 139 ++++++++++++++++++++++++++----------- 3 files changed, 117 insertions(+), 42 deletions(-) diff --git a/package.json b/package.json index f9e063f..2387378 100644 --- a/package.json +++ b/package.json @@ -37,10 +37,12 @@ "@sveltejs/adapter-node": "^4.0.1", "@sveltejs/adapter-static": "^3.0.1", "@vincjo/datatables": "^1.14.4", + "@yanick/updeep-remeda": "^2.2.0", "beercss": "^3.4.13", "better-sqlite3": "^9.3.0", "cheerio": "1.0.0-rc.12", "node-fetch": "^3.3.2", + "svelte-persisted-store": "^0.9.0", "vite-multiple-assets": "^1.2.10" } } diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 2c863f5..3dad5c6 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -9,7 +9,9 @@ import 'beercss/dist/cdn/beer.min.css'; import { setContext } from 'svelte'; import { dev, browser } from '$app/environment'; - import { readable } from 'svelte/store'; + import { readable, writable } from 'svelte/store'; + import { persisted } from 'svelte-persisted-store'; + import u from '@yanick/updeep-remeda'; const prefix = dev ? '/dev/' : '/db/'; @@ -38,6 +40,20 @@ return () => {}; }); setContext('sellers', sellers); + + const games_hidden = writable( + JSON.parse(localStorage.getItem('games_hidden') || '{}'), + ); + games_hidden.toggle = (username, bgg_id) => { + console.log({ username, bgg_id }); + games_hidden.update( + u.updateIn([username, bgg_id].join('!'), (v) => !v), + ); + }; + setContext('games_hidden', games_hidden); + games_hidden.subscribe((data) => + localStorage.setItem('games_hidden', JSON.stringify(data)), + );