import { useState } from "preact/hooks"; import Input from "../components/form/Input.tsx"; import Button from "../components/form/Button.tsx"; import ThemeToggle from "./ThemeToggle.tsx"; interface SharePasswordFormProps { id: string; title: string; } export default function SharePasswordFrame(props: SharePasswordFormProps) { const [password, setPassword] = useState(""); const [error, setError] = useState(false); const handleSubmit = async () => { if (!password) { setError(true); return; } const resp = await fetch("/api/share/verify", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ id: props.id, password }), }); const respJson = await resp.json(); if (respJson.success) { location.reload(); } else { setError(true); } }; return (

{props.title}

This post is password protected.

{ setError(false); setPassword((e.target as HTMLInputElement).value); }} onKeyDown={(e) => { if (e.key === "Enter") handleSubmit(); }} />
); }