From 3803a43248014dea2c3ea6c997566a15e7804d55 Mon Sep 17 00:00:00 2001 From: Will Stensvold Date: Sat, 9 Aug 2025 09:31:12 -0500 Subject: [PATCH] Added a the sludgefest clicker. We'll see how broken it is --- src/lib/db/index.ts | 25 +++++++ src/routes/+page.svelte | 5 -- src/routes/fest/clicker/+page.server.ts | 24 +++++++ src/routes/fest/clicker/+page.svelte | 87 +++++++++++++++++++++++++ 4 files changed, 136 insertions(+), 5 deletions(-) create mode 100644 src/routes/fest/clicker/+page.server.ts create mode 100644 src/routes/fest/clicker/+page.svelte diff --git a/src/lib/db/index.ts b/src/lib/db/index.ts index f242799..0b959a9 100644 --- a/src/lib/db/index.ts +++ b/src/lib/db/index.ts @@ -27,6 +27,17 @@ db.exec(` ) `); +db.exec(` + CREATE TABLE IF NOT EXISTS + 'fest_count' ( + 'year' integer not null primary key, + 'people' integer not null default 0, + 'cars' integer not null default 0, + 'tents' integer not null default 0 + )`); + +db.exec('INSERT OR IGNORE INTO fest_count(year) VALUES (25)'); + // Close the database connection when the application shuts down process.on('SIGINT', () => { db.close(false); @@ -70,7 +81,21 @@ export function publish_blog(title, uri, body) { } +/** + * Clicker Stuff + * + * + */ +export function get_fest_counts(year = 25) { + return db.query('SELECT * FROM fest_count WHERE year = ?').get(year) +} + +export function add_fest_counts(people, tents, cars, year) { + console.log('asc', { people, tents, cars, year }) + db.query('UPDATE fest_count SET people = ?, tents = ?, cars = ? WHERE year = ?').get(people, tents, cars, year) + return true +} /** * Thread Stuff * diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 084a168..2a54498 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -2,11 +2,6 @@ let { data, form } = $props<{ html: string }>(); - - Sludge and Link - - -

Sludge and Friends

Here we make friends and mistakes

diff --git a/src/routes/fest/clicker/+page.server.ts b/src/routes/fest/clicker/+page.server.ts new file mode 100644 index 0000000..3d0afb2 --- /dev/null +++ b/src/routes/fest/clicker/+page.server.ts @@ -0,0 +1,24 @@ +import { get_fest_counts, add_fest_counts } from '$lib/db' + +export async function load() { + console.log('click') + let { people, tents, cars, year } = await get_fest_counts() + console.log({ people, tents, cars, year }) + return { + people, + tents, + cars, + year + } +} +export const actions = { + default: async ({ cookies, fetch, getClientAddress, locals, params, platform, request, route, setHeaders, url, isDataRequest }) => { + const data = await request.formData() + console.log("save", data) + const people = parseInt(data.get("people")) + const tents = parseInt(data.get("tents")) + const cars = parseInt(data.get("cars")) + const reply = add_fest_counts(people, tents, cars, 25) + console.log("reply", reply) + } +} diff --git a/src/routes/fest/clicker/+page.svelte b/src/routes/fest/clicker/+page.svelte new file mode 100644 index 0000000..e66436f --- /dev/null +++ b/src/routes/fest/clicker/+page.svelte @@ -0,0 +1,87 @@ + + +
+

How many people are at Sludge Fest {data.year}?

+
+
+

~{people} people

+ + +
+
+

~{tents} tents

+ + +
+
+

~{cars} cars

+ + +
+
+
+ + + + +
+
+ +