Files
Negotiation_daegu/frontend/src/components/CardCatalog.tsx
T
민헌andClaude Fable 5 178f6daa17 카드 번호순 정렬 + 봇 메시지 문단 분리 (표시 전용)
- 카드 팝업: card_id 오름차순 정렬 (NC26-000~008)
- 긴 봇 스크립트를 종결어미("~다."/"~요.") 경계에서 2문장씩 끊어 빈 줄 삽입 —
  서버 원문·기존 줄바꿈은 유지, 90자 미만 줄은 건드리지 않음

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UFZ7JWdwCaQAwNYJErL8pP
2026-08-31 15:11:22 +09:00

113 lines
4.4 KiB
TypeScript

import { useRef, useState } from 'react'
import { fetchCards, type CardCatalogResponse, type CardInfo } from '../lib/api'
/**
* 협상 카드 카탈로그 팝업 — 엔진이 보유한 카드 전체를 정본(서버)에서 받아 보여준다.
* 현재 발동 중인 카드는 하이라이트된다.
*/
export function CardCatalog({ activeCardId }: { activeCardId: string | null }) {
const dialogRef = useRef<HTMLDialogElement>(null)
const [data, setData] = useState<CardCatalogResponse | null>(null)
const [failed, setFailed] = useState(false)
const open = async () => {
dialogRef.current?.showModal()
if (data) return
try {
setFailed(false)
const res = await fetchCards()
setData({
cards: [...res.cards].sort((a, b) => a.card_id.localeCompare(b.card_id)),
wild_cards: res.wild_cards,
})
} catch {
setFailed(true)
}
}
const CardRow = ({ card }: { card: CardInfo }) => {
const active = card.card_id === activeCardId
return (
<li
className={`rounded-field p-3.5 ${
active ? 'bg-primary/6 ring-1 ring-primary/30' : 'bg-base-200/50'
}`}
>
<div className="flex flex-wrap items-center gap-2">
<span className="num rounded-full bg-base-100 px-2 py-px font-mono text-[11px] font-semibold text-base-content/55">
{card.card_id}
</span>
<span className="text-sm font-bold">{card.card_name}</span>
{active && (
<span className="rounded-full bg-primary/10 px-2 py-px text-[11px] font-semibold text-primary">
발동 중
</span>
)}
</div>
<p className="mt-2 text-[13px] leading-relaxed whitespace-pre-line text-base-content/60">
{card.script}
</p>
</li>
)
}
return (
<>
<button type="button" onClick={open} className="btn btn-ghost btn-xs -mr-1 text-base-content/55">
전체 카드
</button>
<dialog ref={dialogRef} className="modal">
<div className="modal-box max-w-xl rounded-box p-0">
<div className="flex items-start justify-between gap-3 border-b border-base-300/60 px-6 py-4">
<div>
<h3 className="text-base font-bold">협상 카드 목록</h3>
<p className="mt-0.5 text-[13px] text-base-content/55">
엔진이 상황에 맞춰 꺼내 쓰는 카드입니다. {'{...}'} 부분은 협상 시점의 실제 값으로 채워집니다.
</p>
</div>
<form method="dialog">
<button className="btn btn-ghost btn-sm btn-circle" aria-label="닫기">
<svg viewBox="0 0 12 12" className="w-3.5" aria-hidden>
<path d="M1 1l10 10M11 1L1 11" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" />
</svg>
</button>
</form>
</div>
<div className="max-h-[65vh] overflow-y-auto px-6 py-4">
{failed ? (
<p className="py-6 text-center text-[13px] text-base-content/55">
카드 목록을 불러오지 못했어요. 엔진 연결을 확인한 뒤 다시 열어 주세요.
</p>
) : !data ? (
<p className="flex items-center justify-center gap-2 py-6 text-[13px] text-base-content/55">
<span className="loading loading-dots loading-sm" aria-hidden />
카드 목록을 불러오고 있어요
</p>
) : (
<>
<h4 className="text-xs font-semibold text-base-content/45">
일반 협상 카드 {data.cards.length}종
</h4>
<ol className="mt-2 flex flex-col gap-2">
{data.cards.map((c) => <CardRow key={c.card_id} card={c} />)}
</ol>
<h4 className="mt-5 text-xs font-semibold text-base-content/45">
와일드카드 {data.wild_cards.length}종 — 마지막 라운드 승부수
</h4>
<ol className="mt-2 flex flex-col gap-2">
{data.wild_cards.map((c) => <CardRow key={c.card_id} card={c} />)}
</ol>
</>
)}
</div>
</div>
<form method="dialog" className="modal-backdrop">
<button aria-label="닫기">닫기</button>
</form>
</dialog>
</>
)
}