import React, { useEffect, useState } from 'react'; import { ipcChannels } from '../../shared/ipc/contracts'; import { DICE_SIDES, type DiceSides } from '../../shared/types/diceRoll'; import { useEditorI18n } from '../editor/i18n/EditorI18nContext'; import { getDndApi } from '../shared/dndApi'; import { useDiceRollState } from '../shared/dice/useDiceRollState'; import { Button } from '../shared/ui/controls'; import styles from './DiceApp.module.css'; export function DiceApp() { const { t } = useEditorI18n(); const api = getDndApi(); const [state, diceApi] = useDiceRollState(); const [sides, setSides] = useState(20); const [count, setCount] = useState(1); useEffect(() => { const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') { void api.invoke(ipcChannels.windows.closeDice, {}); } }; window.addEventListener('keydown', onKey); return () => window.removeEventListener('keydown', onKey); }, [api]); return (
{t('dice.sides')}
{DICE_SIDES.map((s) => ( ))}
{t('dice.count')}
{count}
{state && state.values.length > 0 ? (
{t('dice.result')}
{state.notation}
{state.values.map((v, i) => ( {v} ))}
{t('dice.total')}: {state.total}
{state.active ?
{t('dice.rolling')}
: null}
) : (
{t('dice.noResult')}
)}
); }