frontend/src/components/PreviewPanel.jsx

111 lines
2.9 KiB
React
Raw Normal View History

2025-04-28 12:13:10 -07:00
import React, { useState } from 'react';
2025-05-07 14:11:04 -07:00
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
2025-04-28 12:13:10 -07:00
export default function PreviewPanel({ code }) {
2025-05-07 14:11:04 -07:00
const [gameId, setGameId] = useState('');
const [submitted, setSubmitted] = useState(false);
const isValid = uuidRegex.test(gameId);
2025-04-28 12:13:10 -07:00
2025-05-07 14:11:04 -07:00
const handleClick = () => {
if (isValid) {
setSubmitted(true);
2025-04-28 12:13:10 -07:00
}
};
return (
2025-05-05 16:00:55 -07:00
<div style={{
flex: 1,
background: '#1a1a1a',
borderRadius: '12px',
boxShadow: '0 0 15px #d300c5, 0 0 25px #ff2a6d',
border: '1px solid #d300c5',
padding: '1rem',
color: '#eee',
display: 'flex',
flexDirection: 'column',
boxSizing: 'border-box'
}}>
<div style={{
backgroundColor: '#d300c5',
height: '6px',
borderRadius: '3px 3px 0 0',
marginBottom: '0.5rem'
}} />
<h3 style={{
fontSize: '1.2rem',
margin: '0 0 1rem',
color: '#d300c5',
textShadow: '0 0 5px #d300c5',
textAlign: 'center'
}}>
🎯 Live Arena Output
</h3>
2025-04-28 12:13:10 -07:00
2025-05-05 16:00:55 -07:00
<div style={{
background: 'rgba(255,255,255,0.05)',
border: '1px solid #ff2a6d',
borderRadius: '8px',
padding: '1rem',
marginBottom: '1rem'
}}>
2025-04-28 12:13:10 -07:00
<input
type="text"
2025-05-07 14:11:04 -07:00
placeholder="Game ID (UUID)"
value={gameId}
onChange={e => { setGameId(e.target.value.trim()); setSubmitted(false); }}
2025-05-05 16:00:55 -07:00
style={{
width: '100%',
padding: '0.5rem',
marginBottom: '0.75rem',
border: 'none',
borderRadius: 4,
background: 'transparent',
color: '#fff',
outline: 'none'
}}
2025-04-28 12:13:10 -07:00
/>
2025-05-07 14:11:04 -07:00
{!isValid && gameId && (
<p style={{ color: 'salmon', margin: '0 0 0.5rem' }}>
Invalid Game ID format.
</p>
)}
2025-05-05 16:00:55 -07:00
<button
type="button"
2025-05-07 14:11:04 -07:00
onClick={handleClick}
disabled={!isValid}
2025-05-05 16:00:55 -07:00
style={{
width: '100%',
padding: '0.75rem',
2025-05-07 14:11:04 -07:00
backgroundColor: isValid ? '#ff2a6d' : '#555',
2025-05-05 16:00:55 -07:00
border: 'none',
borderRadius: '20px',
color: '#fff',
fontWeight: 'bold',
2025-05-07 14:11:04 -07:00
cursor: isValid ? 'pointer' : 'not-allowed'
2025-05-05 16:00:55 -07:00
}}
>
2025-05-07 14:11:04 -07:00
{submitted ? 'Loaded' : 'LOAD BOARD'}
2025-04-28 12:13:10 -07:00
</button>
</div>
2025-05-05 16:00:55 -07:00
<div style={{
flex: 1,
overflow: 'hidden',
borderRadius: '8px'
}}>
2025-05-07 14:11:04 -07:00
{submitted && (
2025-04-28 12:13:10 -07:00
<iframe
2025-05-07 14:11:04 -07:00
src={`https://gameboard-service-aged-glitter-8141.fly.dev/?game=${encodeURIComponent(gameId)}&autoplay=false&showControls=true`}
2025-04-28 12:13:10 -07:00
title="Battlesnake Board"
2025-05-07 14:11:04 -07:00
style={{ width: '100%', height: '100%', border: 'none' }}
allowFullScreen
scrolling="no"
2025-04-28 12:13:10 -07:00
/>
2025-05-05 16:00:55 -07:00
)}
</div>
2025-04-28 12:13:10 -07:00
</div>
);
}