import { Center } from "~/components/Center"; import type { App } from "bknd"; import { useEntityQuery } from "bknd/client"; import type { SQLocalConnection } from "@bknd/sqlocal/src"; import { useEffect, useState } from "react"; export default function IndexPage({ app }: { app: App }) { //const user = app.getApi().getUser(); const limit = 5; const { data: todos, ...$q } = useEntityQuery("todos", undefined, { limit, sort: "-id", }); // @ts-ignore const total = todos?.body.meta.total || 0; return (
bknd

local

What's next? ({total})

{total > limit && (
{total - limit} more todo(s) hidden
)}
{todos && [...todos].reverse().map((todo) => (
{ await $q.update({ done: !todo.done }, todo.id); }} />
{todo.title}
))}
t.id).join()} action={async (formData: FormData) => { const title = formData.get("title") as string; await $q.create({ title }); }} >
Go to Admin ➝ {/*
{user ? (

Authenticated as {user.email}

) : ( Login )}
*/}
); } function Debug({ app }: { app: App }) { const [info, setInfo] = useState(); const connection = app.em.connection as SQLocalConnection; useEffect(() => { (async () => { setInfo(await connection.client.getDatabaseInfo()); app.emgr.onAny( async () => { setInfo(await connection.client.getDatabaseInfo()); }, { mode: "sync", id: "debug" }, ); })(); }, []); async function download() { const databaseFile = await connection.client.getDatabaseFile(); const fileUrl = URL.createObjectURL(databaseFile); const a = document.createElement("a"); a.href = fileUrl; a.download = "database.sqlite3"; a.click(); a.remove(); URL.revokeObjectURL(fileUrl); } return (
{JSON.stringify(info, null, 2)}
); }