import { Link, Route, Router, Routes, SignInWithGoogle, signOut, useAuth, useMutation, useQuery } from "lakebed/client"; import { useState } from "preact/hooks"; import { cleanTodoText, type Todo } from "../shared/todo"; function AuthAvatar({ label, picture }: { label: string; picture?: string }) { const initial = label.trim().slice(0, 1).toUpperCase() || "?"; if (picture) { return ( ); } return ( {initial} ); } function TodoPage() { const todos = useQuery("todos"); const addTodo = useMutation<[text: string], void>("addTodo"); async function onSubmit(event: SubmitEvent) { event.preventDefault(); const form = event.currentTarget as HTMLFormElement; const data = new FormData(form); const text = cleanTodoText(String(data.get("text") ?? "")); if (!text) { return; } await addTodo(text); form.reset(); } return ( {{CAPSULE_TITLE}} void onSubmit(event)}> Add {todos.map((todo) => ( {todo.text} ))} ); } function StatusPage() { const [status, setStatus] = useState("not checked"); async function checkStatus() { const response = await fetch("api/status"); setStatus(response.ok ? await response.text() : "error " + response.status); } return ( Status This route calls the server endpoint at /api/status. void checkStatus()}> Check endpoint endpoint: {status} ); } export function App() { const auth = useAuth(); const authLabel = auth.displayName; const authStatus = auth.isLoading && auth.isGuest ? "checking session" : "signed in as " + authLabel; return ( {!auth.isLoading ? : null} {authStatus} {!auth.isLoading && auth.isGuest ? ( ) : !auth.isLoading ? ( signOut()}> Sign out ) : null} Todos Status } /> } /> Not foundBack to todos} /> ); }
This route calls the server endpoint at /api/status.
endpoint: {status}
{authStatus}