import { useEffect, useState } from "react"; import { ScrollView, StyleSheet, Text, View } from "react-native"; import type { Character } from "@kokorone/shared"; import { API_BASE_URL } from "../../lib/api"; const CHARACTER_ID = "seed-character-genki"; // Q-2 角色分頁:展示角色設定表(沿用 B 群組的 /characters 端點),驗證分頁本身可獨立運作、能打 API。 export default function CharacterScreen() { const [character, setCharacter] = useState(null); const [error, setError] = useState(null); useEffect(() => { fetch(`${API_BASE_URL}/characters`) .then((res) => res.json()) .then((characters: Character[]) => { setCharacter(characters.find((c) => c.id === CHARACTER_ID) ?? characters[0] ?? null); }) .catch(() => setError("角色資料載入失敗,請確認 api 服務是否已啟動")); }, []); const formalName = character?.aliases?.[0]?.formalName ?? character?.id ?? ""; return ( {formalName || "角色"} {error && {error}} {character && ( )} ); } function Field({ label, value }: { label: string; value: string }) { return ( {label} {value} ); } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: "#FFF5F7" }, content: { padding: 20, gap: 16 }, title: { fontSize: 22, fontWeight: "bold", color: "#FF7E9D" }, card: { gap: 14 }, field: { gap: 2 }, fieldLabel: { fontSize: 12, color: "#8a6b6f" }, fieldValue: { fontSize: 14, color: "#222" }, error: { color: "#FF7E9D", fontSize: 12 }, });