Files
react-website/src/demo/threats/ThreatDemosSlider.tsx
T
MehboobKandClaude Sonnet 5 7024269bf6 Add family safe-zone location demo, wire into Mobile SDK demo slider
Cinematic 30s player showing safe-zone creation and leave-zone alerts,
matching the existing threat-demo pattern. Added as a 6th rotating
slide in ThreatDemosSlider (live on /mobile-sdk and /threat-demos),
plus a standalone /location-demo route for recording.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-02 19:06:53 +05:00

121 lines
6.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { AnimatePresence, motion } from 'framer-motion'
import { THREAT_SCENARIOS, type ThreatScenario } from './scenarios'
import { ThreatCinematic } from './ThreatDemo'
import { LocationCinematic } from '../location/LocationDemo'
import '../demo.css'
const ACCENT = '#3BB586'
// The slider mixes the threat-detection scenarios with the location/geofencing
// demo, which has its own timeline and player rather than a ThreatScenario shape.
type DemoSlide =
| { kind: 'threat'; scenario: ThreatScenario }
| { kind: 'location' }
const DEMO_SLIDES: DemoSlide[] = [
...THREAT_SCENARIOS.map((scenario) => ({ kind: 'threat' as const, scenario })),
{ kind: 'location' },
]
function slideId(s: DemoSlide): string {
return s.kind === 'threat' ? s.scenario.id : 'location'
}
function slideTitle(s: DemoSlide): string {
return s.kind === 'threat' ? s.scenario.title : 'Family Safe Zones'
}
function slideProduct(s: DemoSlide): string {
return s.kind === 'threat' ? s.scenario.product : 'Mobile SDK'
}
// Isolated so useNavigate() is only ever invoked when this is actually mounted
// under a <Router> — the embedded (no-router) instance never renders it.
function BackToSiteButton() {
const navigate = useNavigate()
return (
<button onClick={() => navigate('/')} style={{ display: 'inline-flex', alignItems: 'center', gap: 7, fontFamily: 'inherit', fontSize: 13, fontWeight: 500, color: 'rgba(255,255,255,.8)', background: 'rgba(255,255,255,.05)', border: '1px solid rgba(255,255,255,.12)', borderRadius: 100, padding: '7px 14px', cursor: 'pointer', flexShrink: 0 }}>← Back to site</button>
)
}
export default function ThreatDemosSlider({ embedded = false }: { embedded?: boolean } = {}) {
const [idx, setIdx] = useState(0)
const [dir, setDir] = useState(1)
const slide = DEMO_SLIDES[idx]
const n = DEMO_SLIDES.length
const go = (next: number) => {
setDir(next > idx ? 1 : -1)
setIdx((next + n) % n)
}
return (
<div className="bd-demo-root" style={{ position: 'relative', height: embedded ? '100%' : '100vh', overflow: 'hidden', background: '#010e14', fontFamily: "'Ubuntu', -apple-system, system-ui, sans-serif", display: 'flex', flexDirection: 'column' }}>
{/* ── Top bar (reserved) — standalone /threat-demos only ── */}
{!embedded && (
<div style={{ flexShrink: 0, height: 60, display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: '0 20px', borderBottom: '1px solid rgba(255,255,255,.06)', background: 'rgba(1,14,20,.7)', backdropFilter: 'blur(10px)', zIndex: 80 }}>
<BackToSiteButton />
<div style={{ textAlign: 'center', color: '#e8f4f3', minWidth: 0 }}>
<div style={{ fontSize: 14, fontWeight: 600, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{slideTitle(slide)}</div>
<div style={{ fontSize: 10.5, color: '#8aa5ab' }}>{idx + 1} / {n} · {slideProduct(slide)}</div>
</div>
<div style={{ display: 'flex', alignItems: 'center', gap: 6, background: 'rgba(0,0,0,.4)', border: '1px solid rgba(255,255,255,.1)', borderRadius: 100, padding: '5px 11px', flexShrink: 0 }}>
<motion.span animate={{ opacity: [1, 0, 1] }} transition={{ duration: 1.2, repeat: Infinity }} style={{ width: 7, height: 7, borderRadius: '50%', background: '#ef4444', display: 'inline-block' }} />
<span style={{ fontSize: 10, fontWeight: 700, color: '#fff', letterSpacing: '.5px' }}>REC</span>
</div>
</div>
)}
{/* ── Stage (flex, holds the sliding players) ── */}
<div style={{ position: 'relative', flex: 1, minHeight: 0, overflow: 'hidden' }}>
<AnimatePresence initial={false} custom={dir} mode="popLayout">
<motion.div
key={slideId(slide)}
custom={dir}
initial={{ x: dir > 0 ? '100%' : '-100%' }}
animate={{ x: 0 }}
exit={{ x: dir > 0 ? '-100%' : '100%' }}
transition={{ type: 'spring', stiffness: 260, damping: 30 }}
style={{ position: 'absolute', inset: 0 }}>
{slide.kind === 'threat'
? <ThreatCinematic scenario={slide.scenario} autoPlay={!embedded} chrome={false} />
: <LocationCinematic autoPlay={!embedded} chrome={false} />}
</motion.div>
</AnimatePresence>
{/* Prev / Next arrows (inside the stage, vertically centred) */}
<button onClick={() => go(idx - 1)} aria-label="Previous" style={navBtn('left')}>‹</button>
<button onClick={() => go(idx + 1)} aria-label="Next" style={navBtn('right')}>›</button>
</div>
{/* ── Bottom: scenario tabs (reserved) — moves above the stage on mobile via .bd-demo-tabs media query ── */}
<div className="bd-demo-tabs" style={{ flexShrink: 0, minHeight: 56, display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 8, flexWrap: 'wrap', padding: '10px 16px', borderTop: '1px solid rgba(255,255,255,.06)', background: 'rgba(1,14,20,.7)', backdropFilter: 'blur(10px)', zIndex: 80 }}>
{DEMO_SLIDES.map((s, i) => (
<button key={slideId(s)} onClick={() => go(i)}
style={{
fontFamily: 'inherit', fontSize: 11, fontWeight: 500, cursor: 'pointer',
padding: '6px 12px', borderRadius: 100,
border: `1px solid ${i === idx ? ACCENT : 'rgba(255,255,255,.12)'}`,
background: i === idx ? 'rgba(59,181,134,0.18)' : 'rgba(255,255,255,.03)',
color: i === idx ? ACCENT : 'rgba(255,255,255,.6)', whiteSpace: 'nowrap',
}}>
{slideTitle(s)}
</button>
))}
</div>
</div>
)
}
function navBtn(side: 'left' | 'right'): React.CSSProperties {
return {
position: 'absolute', top: '50%', transform: 'translateY(-50%)', [side]: 16,
zIndex: 70, width: 44, height: 44, borderRadius: '50%',
background: 'rgba(0,0,0,.45)', backdropFilter: 'blur(10px)',
border: '1px solid rgba(255,255,255,.14)', color: '#e8f4f3',
fontSize: 22, lineHeight: 1, cursor: 'pointer', fontFamily: 'inherit',
display: 'flex', alignItems: 'center', justifyContent: 'center',
} as React.CSSProperties
}