diff --git a/src/Debug.tsx b/src/Debug.tsx index f59d13e..a5c1840 100644 --- a/src/Debug.tsx +++ b/src/Debug.tsx @@ -1,7 +1,42 @@ -import { createResource, ErrorBoundary } from "solid-js"; -import { openDatabase } from "./data"; +import { createResource, ErrorBoundary, Show } from "solid-js"; +import { openDatabase, type Database, type Entry } from "./data"; import Graph from "./Graph"; +async function loadDebugData(database: Database) { + await database.clear("entries"); + + const debugEntries: Entry[] = [ + { + weight: 83.6, + timestamp: new Date("2025-08-12T10:56:00.000+02:00"), + }, + { + weight: 84.6, + timestamp: new Date("2025-08-13T09:23:00.000+02:00"), + }, + { + weight: 84.1, + timestamp: new Date("2025-08-13T10:30:00.000+02:00"), + }, + { + weight: 84, + timestamp: new Date("2025-08-14T09:28:00.000+02:00"), + }, + { + weight: 83.6, + timestamp: new Date("2025-08-15T13:38:00.000+02:00"), + }, + { + weight: 83.9, + timestamp: new Date("2025-08-16T10:20:00.000+02:00"), + }, + ]; + + const adds = debugEntries.map((entry) => + database.add("entries", entry, entry.timestamp.getTime()) + ); + await Promise.all(adds); +} export default function Debug() { const [database] = createResource(openDatabase); @@ -29,6 +64,14 @@ export default function Debug() { > entries() ?? []} /> + + + {(database) => ( + + )} + ); } diff --git a/src/data.ts b/src/data.ts index 65cb9bc..367190d 100644 --- a/src/data.ts +++ b/src/data.ts @@ -1,4 +1,4 @@ -import { openDB, type DBSchema } from "idb"; +import { openDB, type DBSchema, type IDBPDatabase } from "idb"; export type Entry = { weight: number; @@ -9,6 +9,8 @@ interface Schema extends DBSchema { entries: { key: number; value: Entry; indexes: { timestamp: Date } }; } +export type Database = IDBPDatabase; + export async function openDatabase() { return await openDB("waight", 1, { upgrade(database, _oldVersion, _newVersion, _transaction, _event) {