diff --git a/apps/desktop/src/components/WhiteboardModal.tsx b/apps/desktop/src/components/WhiteboardModal.tsx new file mode 100644 index 0000000..9f044bd --- /dev/null +++ b/apps/desktop/src/components/WhiteboardModal.tsx @@ -0,0 +1,197 @@ +import { useEffect, useState } from 'react'; +import { useTranslation } from 'react-i18next'; + +import { useWhiteboardStrokes } from '../hooks/useWhiteboardStrokes'; +import { XIcon } from './icons'; +import { + WhiteboardCanvas, + type WhiteboardColor, + type WhiteboardTool, + type WhiteboardWidth, +} from './WhiteboardCanvas'; + +interface Props { + whiteboardId: string; + onClose: () => void; +} + +const COLORS: WhiteboardColor[] = ['#000000', '#ef4444', '#3b82f6', '#22c55e', '#facc15', '#a855f7']; +const WIDTHS: WhiteboardWidth[] = [2, 4, 8]; + +export function WhiteboardModal({ whiteboardId, onClose }: Props) { + const { t } = useTranslation(); + const { strokes, loading, error, insertStroke, clearAll } = useWhiteboardStrokes(whiteboardId); + const [tool, setTool] = useState('pen'); + const [color, setColor] = useState('#000000'); + const [width, setWidth] = useState(4); + const [confirmClear, setConfirmClear] = useState(false); + + useEffect(() => { + const onKey = (e: KeyboardEvent) => { + if (e.key === 'Escape') onClose(); + }; + window.addEventListener('keydown', onKey); + return () => window.removeEventListener('keydown', onKey); + }, [onClose]); + + const handleConfirmClear = async () => { + setConfirmClear(false); + try { + await clearAll(); + } catch (err) { + console.error('clearAll failed', err); + } + }; + + return ( +
+
+

+ {t('app:whiteboard.title', { defaultValue: 'Whiteboard' })} +

+ +
+ +
+ {loading ? ( +

+ {t('app:whiteboard.loading', { defaultValue: 'Lädt…' })} +

+ ) : error ? ( +

+ {t('app:whiteboard.error', { defaultValue: 'Whiteboard konnte nicht geladen werden.' })} +

+ ) : ( + void insertStroke(payload)} + /> + )} +
+ + +
+ ); +}