import { memo } from 'react'; import { Handle, Position, NodeProps } from '@xyflow/react'; import { ChoiceNode as ChoiceNodeData } from '../../types/dialogue'; import { useValidation } from '../../hooks/useValidation'; import { useDialogueStore } from '../../store/dialogueStore'; import styles from './nodes.module.css'; export const ChoiceNode = memo(({ data, selected }: NodeProps & { data: ChoiceNodeData }) => { const { hasError, hasWarning } = useValidation(); const startId = useDialogueStore(s => { const id = s.selectedDialogueId; return s.file?.dialogues.find(d => d.id === id)?.start; }); const isStart = data.id === startId; const error = hasError(data.id); const warning = !error && hasWarning(data.id); return (
{isStart &&
▶ START
}
{data.speaker || '(no speaker)'} Choice
{data.id}
{data.choices.length === 0 ? ( (no choices) ) : ( data.choices.map((choice, i) => (
{choice.kind} {choice.text || '(empty)'}
)) )}
); });