diff --git a/pony-frontend/src/App.js b/pony-frontend/src/App.js index 49ccc45..68ae3f1 100644 --- a/pony-frontend/src/App.js +++ b/pony-frontend/src/App.js @@ -6,13 +6,26 @@ import './App.css'; const API = window.location.origin.replace('3001', '8082'); -const PONIES = [ +// Fallback pony data if API fails to load +const DEFAULT_PONIES = [ { navn: 'Jordpony', emoji: '🐴', img: 'jordpony.png', bonus: 'Stærk 💪', color: '#8B4513', diceBonus: 1 }, { navn: 'Pegasus', emoji: '🦅', img: 'pegasus.png', bonus: 'Flyver 🪽', color: '#87CEEB', diceBonus: 1 }, { navn: 'Enhjørning', emoji: '🦄', img: 'enhjorning.png', bonus: 'Magisk horn ✨', color: '#9370DB', diceBonus: 2 }, - { navn: 'Alicorn', emoji: '👑', img: 'alicorn.png', bonus: 'Magi + vinger 🌟', color: '#FFD700', diceBonus: 2 }, + { name: 'Alicorn', emoji: '👑', img: 'alicorn.png', bonus: 'Magi + vinger 🌟', color: '#FFD700', diceBonus: 2 }, ]; +// Fetch content (ponies + themes) from backend +async function loadContent() { + try { + const r = await fetch(`${API}/api/content`); + if (r.ok) { + const data = await r.json(); + return { ponies: data.ponies, themes: data.themes }; + } + } catch (e) { /* fall through */ } + return { ponies: DEFAULT_PONIES, themes: [] }; +} + // Achievement system function useAchievements() { const [stats, setStats] = useState(() => { @@ -290,10 +303,17 @@ function App() { const [volume, setVolume] = useState(0.5); const [showAchievements, setShowAchievements] = useState(false); const [soundEnabled, setSoundEnabled] = useState(false); + const [selectedTheme, setSelectedTheme] = useState(0); + const [content, setContent] = useState({ ponies: DEFAULT_PONIES, themes: [] }); const scrollRef = useRef(null); const { stats, recordGame } = useAchievements(); const { shown: tutorialShown, markSeen } = useTutorial(); + // Load content from backend on mount + useEffect(() => { + loadContent().then(setContent); + }, []); + // Auto-scroll history feed useEffect(() => { if (scrollRef.current && data && data.history && data.history.length > 0) { @@ -320,7 +340,7 @@ function App() { method: 'POST', headers: { 'Content-Type': 'application/json' }, credentials: 'include', - body: JSON.stringify({ type: typeIdx, tema: 0 }) + body: JSON.stringify({ type: typeIdx, tema: selectedTheme }) }); if (!r.ok) throw new Error('Server fejl'); const json = await r.json(); @@ -475,7 +495,7 @@ function App() { {/* Tutorial overlay */} {!tutorialShown && soundEnabled && !showAchievements && ( - { markSeen(); navigateTo('start'); }} /> + { markSeen(); setSelectedTheme(0); navigateTo('theme'); }} /> )} @@ -556,7 +576,7 @@ function App() { whileHover={{ scale: 1.1 }} whileTap={{ scale: 0.95 }} className="btn-start" - onClick={() => navigateTo('start')} + onClick={() => { setSelectedTheme(0); navigateTo('theme'); }} aria-label="Start nyt spil" > 🎮 Start Nyt Spil! @@ -565,6 +585,57 @@ function App() { )} + {/* CHOOSE THEME */} + {page === 'theme' && soundEnabled && ( + + 0 ? 'home' : 'none'} /> +
+ +
+ + + Vælg et eventyr! 📖 + + + Hvilken historie vil du opleve? + +
+ {content.themes.map((t, i) => ( + { setSelectedTheme(i); navigateTo('start'); }} + role="button" + tabIndex={0} + aria-label={`Vælg ${t.titel}`} + onKeyDown={(e) => { if (e.key === 'Enter' || e.key === ' ') { setSelectedTheme(i); navigateTo('start'); } }} + > +
{t.emoji}
+

{t.titel}

+

{t.sceneCount || 5} scener

+
+ ))} +
+ navigateTo('home')} aria-label="Tilbage til forsiden"> + Tilbage + +
+ )} + {/* CHOOSE PONY */} {page === 'start' && soundEnabled && (
- {PONIES.map((p, i) => ( + {content.ponies.map((p, i) => (