"use client"; import { useEffect, useState } from "react"; import { useRouter } from "next/navigation"; import { createRoom, listCharacters, type CharacterSummary, type RoomMode } from "../../lib/api"; const USER_ID = "seed-user-primary"; // K-7 建房介面:建立後導向 /room/[roomId](T19-P2 起的通用房間畫面,含 SSE/立繪舞台/語音/靜音, // 見 T19-P3),不再自己維護一份較舊、功能較少的房間顯示邏輯。 export function RoomView() { const router = useRouter(); const [characters, setCharacters] = useState([]); const [selectedCharacterIds, setSelectedCharacterIds] = useState([]); const [mode, setMode] = useState("GROUP"); const [topicSeed, setTopicSeed] = useState(""); const [pending, setPending] = useState(false); const [error, setError] = useState(null); useEffect(() => { void listCharacters().then(setCharacters); }, []); async function handleCreateRoom() { if (selectedCharacterIds.length === 0 || pending) return; setPending(true); setError(null); try { const created = await createRoom(USER_ID, selectedCharacterIds, mode, topicSeed || undefined); router.push(`/room/${created.id}`); } catch { setError("房間建立失敗,請確認 api 服務是否已啟動"); setPending(false); } } return (

建立房間

{characters.map((character) => { const checked = selectedCharacterIds.includes(character.id); return ( ); })}
setTopicSeed(event.target.value)} placeholder="話題種子(選填)" className="rounded-full border bg-transparent px-3 py-1.5 text-xs" style={{ borderColor: "var(--line)", color: "var(--ink)" }} /> {error && (

{error}

)}
); }