fix: make main a bit nicer
This commit is contained in:
parent
1a8ebaf88d
commit
0480be5ded
|
@ -2,14 +2,15 @@ import { createRoot } from 'react-dom/client'
|
|||
import './index.css'
|
||||
import App from "./App.tsx";
|
||||
|
||||
import { DBAsync } from "@vlcn.io/xplat-api";
|
||||
import initWasm from '@vlcn.io/crsqlite-wasm';
|
||||
import wasmUrl from '@vlcn.io/crsqlite-wasm/crsqlite.wasm?url';
|
||||
import tblrx from '@vlcn.io/rx-tbl';
|
||||
|
||||
const sqlite = await initWasm(() => wasmUrl);
|
||||
|
||||
const db = await sqlite.open("todo.db");
|
||||
await db.exec(`
|
||||
const initDb = async () => {
|
||||
const sqlite = await initWasm(() => wasmUrl);
|
||||
const db: DBAsync = await sqlite.open("todo.db");
|
||||
await db.exec(`
|
||||
CREATE TABLE IF NOT EXISTS todos (
|
||||
id BLOB PRIMARY KEY NOT NULL,
|
||||
description TEXT,
|
||||
|
@ -22,16 +23,19 @@ await db.exec(`
|
|||
completed INTEGER NOT NULL DEFAULT 0
|
||||
);
|
||||
SELECT crsql_as_crr('todos');
|
||||
`);
|
||||
`);
|
||||
const rx = tblrx(db);
|
||||
return {db, rx};
|
||||
}
|
||||
|
||||
const rx = tblrx(db);
|
||||
const ctx = { db, rx };
|
||||
const init = async () => {
|
||||
const ctx = await initDb();
|
||||
createRoot(document.getElementById("root") as HTMLElement).render(
|
||||
<main className="min-h-screen flex flex-col py-12 bg-background text-gray-200">
|
||||
<App ctx={ctx} />
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
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">
|
||||
<App ctx={ctx} />
|
||||
</main>
|
||||
);
|
||||
|
||||
init();
|
||||
|
|
Loading…
Reference in a new issue