import React, { useState, useEffect } from 'react'; import { PhoneFrame } from './sketchy'; import { screens, getScreen } from '../screens'; import { getStoriesForScreen, categoryLabels, categoryColors, priorityColors } from '../data'; import { getStoryUrl } from '../router'; import { ThemeToggle } from './ThemeToggle'; function useIsMobile(breakpoint = 768) { const [isMobile, setIsMobile] = useState(window.innerWidth < breakpoint); useEffect(() => { const handleResize = () => setIsMobile(window.innerWidth < breakpoint); window.addEventListener('resize', handleResize); return () => window.removeEventListener('resize', handleResize); }, [breakpoint]); return isMobile; } interface DemoModeProps { initialScreenId: string; onBack: () => void; onNavigateToStory: (storyId: string) => void; } export function DemoMode({ initialScreenId, onBack, onNavigateToStory }: DemoModeProps) { const [currentScreenId, setCurrentScreenId] = useState(initialScreenId); const [history, setHistory] = useState([initialScreenId]); const [historyIndex, setHistoryIndex] = useState(0); const [sidebarOpen, setSidebarOpen] = useState(false); const isMobile = useIsMobile(); const currentScreen = getScreen(currentScreenId); const ScreenComponent = currentScreen?.component; const linkedStories = getStoriesForScreen(currentScreenId); const navigate = (screenId: string) => { const newHistory = [...history.slice(0, historyIndex + 1), screenId]; setHistory(newHistory); setHistoryIndex(newHistory.length - 1); setCurrentScreenId(screenId); }; const canGoBack = historyIndex > 0; const canGoForward = historyIndex < history.length - 1; const goBack = () => { if (canGoBack) { const newIndex = historyIndex - 1; setHistoryIndex(newIndex); const screenId = history[newIndex]; if (screenId) setCurrentScreenId(screenId); } }; const goForward = () => { if (canGoForward) { const newIndex = historyIndex + 1; setHistoryIndex(newIndex); const screenId = history[newIndex]; if (screenId) setCurrentScreenId(screenId); } }; return (
{/* Mobile overlay */} {isMobile && sidebarOpen && (
setSidebarOpen(false)} style={{ position: 'fixed', inset: 0, background: 'rgba(0,0,0,0.5)', zIndex: 40, }} /> )} {/* Left Sidebar */}
{/* Back button and theme toggle */}
{/* Current screen & navigation */}
Écran actuel
{currentScreen?.name}
{/* User Stories for this screen */} {linkedStories.length > 0 && (
User Stories ({linkedStories.length})
{linkedStories.map((story) => ( { e.preventDefault(); onNavigateToStory(story.id); }} style={{ display: 'block', padding: '8px 16px', borderBottom: '1px solid var(--tool-border-light)', textDecoration: 'none', color: 'var(--tool-text)', cursor: 'pointer', }} >
P{story.priority} {categoryLabels[story.category]}
{story.title}
))}
)} {/* Screen list */}
Tous les écrans
{screens.map((s) => (
navigate(s.id)} style={{ padding: '10px 16px', fontFamily: 'var(--font-sketch)', fontSize: 14, cursor: 'pointer', background: s.id === currentScreenId ? 'var(--tool-border-light)' : 'transparent', borderLeft: s.id === currentScreenId ? '3px solid var(--tool-text)' : '3px solid transparent', color: 'var(--tool-text)', }} > {s.name}
))}
{/* Phone preview area */}
{/* Mobile header */} {isMobile && (
{currentScreen?.name}
)}
{ScreenComponent && }
); } function ScaledPhoneFrame({ children, isMobile = false }: { children: React.ReactNode; isMobile?: boolean }) { const phoneWidth = 375; const phoneHeight = 812; // Calculate scale to fit in viewport with some padding const [scale, setScale] = React.useState(1); React.useEffect(() => { const calculateScale = () => { const mobileHeaderHeight = isMobile ? 56 : 0; const padding = isMobile ? 24 : 48; const sidebarWidth = isMobile ? 0 : 280; const availableHeight = window.innerHeight - padding - mobileHeaderHeight; const availableWidth = window.innerWidth - sidebarWidth - padding; const scaleByHeight = availableHeight / phoneHeight; const scaleByWidth = availableWidth / phoneWidth; const newScale = Math.min(scaleByHeight, scaleByWidth, 1); setScale(Math.max(0.4, newScale)); // minimum 40% scale for mobile }; calculateScale(); window.addEventListener('resize', calculateScale); return () => window.removeEventListener('resize', calculateScale); }, [isMobile]); return (
{children}
); }