"use client"; import { useState } from "react"; import { useRouter } from "waku"; import { useRepo } from "@automerge/automerge-repo-react-hooks"; import { createPoll } from "../lib/poll.js"; import type { Poll } from "../lib/types.js"; export default function HomeClient() { const [title, setTitle] = useState(""); const [joinId, setJoinId] = useState(""); const repo = useRepo(); const router = useRouter(); const handleCreate = () => { if (!title.trim()) return; const handle = repo.create(); handle.change((doc) => { const poll = createPoll(title.trim()); doc.title = poll.title; doc.options = poll.options; }); router.push(`/poll/${handle.documentId}`); }; const handleJoin = () => { const id = joinId.trim(); if (!id) return; router.push(`/poll/${id}`); }; return (
P2P Poll {/* Create Poll */}

Create a New Poll

setTitle(e.target.value)} onKeyDown={(e) => e.key === "Enter" && handleCreate()} placeholder="Enter poll title..." className="flex-1 rounded-md border border-gray-300 px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500" />
{/* Join Poll */}

Join an Existing Poll

setJoinId(e.target.value)} onKeyDown={(e) => e.key === "Enter" && handleJoin()} placeholder="Paste poll ID or link..." className="flex-1 rounded-md border border-gray-300 px-3 py-2 text-sm focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500" />
); }