import React, { useState, useEffect } from 'react'; import { Link } from 'react-router-dom'; import { createPageUrl } from '@/utils'; import { motion, AnimatePresence } from 'framer-motion'; import { Eye, Activity, Smile, ArrowLeft, BookOpen } from 'lucide-react'; import { Button } from '@/components/ui/button'; import SlideNavigation from '@/components/lessons/SlideNavigation'; import SlideContainer from '@/components/lessons/SlideContainer'; import { chapter1Slides } from '@/components/lessons/Chapter1Slides'; import { chapter2Slides } from '@/components/lessons/Chapter2Slides'; import { chapter3Slides } from '@/components/lessons/Chapter3Slides'; const chapters = [ { id: 1, title: "Object Detection", subtitle: "How computers find things", icon: Eye, color: "from-blue-500 to-cyan-500", slides: chapter1Slides }, { id: 2, title: "Pose Estimation", subtitle: "Tracking body movement", icon: Activity, color: "from-purple-500 to-pink-500", slides: chapter2Slides }, { id: 3, title: "Emotion Recognition", subtitle: "Understanding feelings", icon: Smile, color: "from-emerald-500 to-teal-500", slides: chapter3Slides } ]; // 60-minute TTL storage (localStorage has no built-in expiration) [web:17] const COMPLETED_KEY = 'completedChapters_v1'; const TTL_MS = 60 * 60 * 1000; function loadCompletedChapters() { try { const raw = localStorage.getItem(COMPLETED_KEY); if (!raw) return []; const parsed = JSON.parse(raw); const savedAt = parsed?.savedAt; const value = parsed?.value; if (!Array.isArray(value) || typeof savedAt !== 'number') return []; if (Date.now() - savedAt > TTL_MS) { localStorage.removeItem(COMPLETED_KEY); // remove expired key [web:16] return []; } return value; } catch { return []; } } function saveCompletedChapters(next) { localStorage.setItem( COMPLETED_KEY, JSON.stringify({ value: next, savedAt: Date.now() }) ); } export default function Lessons() { const [selectedChapter, setSelectedChapter] = useState(null); const [currentSlide, setCurrentSlide] = useState(0); const [completedChapters, setCompletedChapters] = useState(loadCompletedChapters); useEffect(() => { const urlParams = new URLSearchParams(window.location.search); const chapterParam = urlParams.get('chapter'); if (chapterParam) { const chapterIndex = parseInt(chapterParam) - 1; if (chapterIndex >= 0 && chapterIndex < chapters.length) { setSelectedChapter(chapterIndex); } } }, []); const handleChapterSelect = (index) => { setSelectedChapter(index); setCurrentSlide(0); }; const handleNext = () => { const chapter = chapters[selectedChapter]; if (currentSlide < chapter.slides.length - 1) { setCurrentSlide(currentSlide + 1); } }; const handleMarkComplete = () => { if (!completedChapters.includes(selectedChapter)) { const updated = [...completedChapters, selectedChapter]; setCompletedChapters(updated); saveCompletedChapters(updated); } // Return to chapter selection setSelectedChapter(null); setCurrentSlide(0); }; const handlePrev = () => { if (currentSlide > 0) { setCurrentSlide(currentSlide - 1); } }; const handleHome = () => { setSelectedChapter(null); setCurrentSlide(0); }; const allChaptersCompleted = completedChapters.length === chapters.length; // Chapter Selection View if (selectedChapter === null) { return (
Select a chapter to start learning
{chapter.subtitle} • {chapter.slides.length} slides
Ready to test your knowledge?
> ) : ( <>Complete all lessons to unlock the quiz!
> )}Chapter {chapter.id}