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 (
local
What's next? ({total})
{total > limit && (
{total - limit} more todo(s) hidden
)}
{todos &&
[...todos].reverse().map((todo) => (
))}
);
}
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)}
);
}