import { useState, useEffect, useMemo } from 'react'; import Admin from './Admin'; // <-- THÊM DÒNG IMPORT NÀY // Định nghĩa kiểu dữ liệu cho Video bài tập interface ExerciseVideo { id: string; title: string; category: string; level: string; youtube_id: string; } // BƯỚC 1: Đổi tên App cũ của bạn thành MainApp function MainApp() { const [videos, setVideos] = useState([]); const [selectedVideo, setSelectedVideo] = useState(null); const [activeCategory, setActiveCategory] = useState('All'); const [loading, setLoading] = useState(true); // Lấy dữ liệu từ thư mục con /data/ và chống Cache useEffect(() => { fetch('/data/data.json?t=' + new Date().getTime()) .then((res) => res.json()) .then((data: ExerciseVideo[]) => { setVideos(data); if (data.length > 0) { setSelectedVideo(data[0]); // Mặc định chọn video đầu tiên } setLoading(false); }) .catch((err) => { console.error('Lỗi khi tải dữ liệu bài tập:', err); setLoading(false); }); }, []); // Tự động trích xuất các danh mục (category) không trùng lặp const categories = useMemo(() => { const uniqueCategories = new Set(videos.map((v) => v.category)); return ['All', ...Array.from(uniqueCategories)]; }, [videos]); // Lọc danh sách video theo category đang chọn const filteredVideos = useMemo(() => { if (activeCategory === 'All') return videos; return videos.filter((v) => v.category === activeCategory); }, [videos, activeCategory]); if (loading) { return
Đang tải dữ liệu...
; } return (

Hệ Thống Bài Tập Thể Dục

{/* PHẦN 1: TRÌNH PHÁT VIDEO */} {selectedVideo && (

{selectedVideo.title}

{selectedVideo.category} {selectedVideo.level}
)} {/* PHẦN 2: THANH LỌC (FILTER) */}
{categories.map((cat) => ( ))}
{/* PHẦN 3: DANH SÁCH BÀI TẬP (CARDS) */}
{filteredVideos.map((video) => (
{ setSelectedVideo(video); window.scrollTo({ top: 0, behavior: 'smooth' }); // Tự động cuộn lên trình phát }} className={`cursor-pointer rounded-xl p-4 border-2 transition-all duration-200 flex flex-col justify-between gap-3 bg-white hover:shadow-md ${selectedVideo?.id === video.id ? 'border-blue-500 shadow-md' : 'border-transparent shadow-sm'} `} >
Thumbnail

{video.title}

{video.category} {video.level}
))}
); } // BƯỚC 2: Tạo App mới làm người gác cổng kiểm tra URL function App() { const isAdmin = window.location.search.includes('admin=true'); if (isAdmin) { return ; } return ; } export default App;