fix: make main a bit nicer

This commit is contained in:
Anish Lakhwara 2025-02-19 23:16:53 -08:00
parent 1a8ebaf88d
commit 0480be5ded

View file

@ -2,14 +2,15 @@ import { createRoot } from 'react-dom/client'
import './index.css' import './index.css'
import App from "./App.tsx"; import App from "./App.tsx";
import { DBAsync } from "@vlcn.io/xplat-api";
import initWasm from '@vlcn.io/crsqlite-wasm'; import initWasm from '@vlcn.io/crsqlite-wasm';
import wasmUrl from '@vlcn.io/crsqlite-wasm/crsqlite.wasm?url'; import wasmUrl from '@vlcn.io/crsqlite-wasm/crsqlite.wasm?url';
import tblrx from '@vlcn.io/rx-tbl'; import tblrx from '@vlcn.io/rx-tbl';
const sqlite = await initWasm(() => wasmUrl); const initDb = async () => {
const sqlite = await initWasm(() => wasmUrl);
const db = await sqlite.open("todo.db"); const db: DBAsync = await sqlite.open("todo.db");
await db.exec(` await db.exec(`
CREATE TABLE IF NOT EXISTS todos ( CREATE TABLE IF NOT EXISTS todos (
id BLOB PRIMARY KEY NOT NULL, id BLOB PRIMARY KEY NOT NULL,
description TEXT, description TEXT,
@ -22,16 +23,19 @@ await db.exec(`
completed INTEGER NOT NULL DEFAULT 0 completed INTEGER NOT NULL DEFAULT 0
); );
SELECT crsql_as_crr('todos'); SELECT crsql_as_crr('todos');
`); `);
const rx = tblrx(db);
return {db, rx};
}
const rx = tblrx(db); const init = async () => {
const ctx = { db, rx }; const ctx = await initDb();
createRoot(document.getElementById("root") as HTMLElement).render(
document.getElementById("root")!.classList.add("dark");
createRoot(document.getElementById("root") as HTMLElement).render(
<main className="min-h-screen flex flex-col py-12 bg-background text-gray-200"> <main className="min-h-screen flex flex-col py-12 bg-background text-gray-200">
<App ctx={ctx} /> <App ctx={ctx} />
</main> </main>
); );
}
document.getElementById("root")!.classList.add("dark");
init();