import React, { useState, useEffect } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import axios from 'axios'; import toast from 'react-hot-toast'; import ExampleCard from '../components/ExampleCard'; import { Shuffle, RefreshCw, Database } from 'lucide-react'; const Random = () => { const [currentExample, setCurrentExample] = useState(null); const [loading, setLoading] = useState(true); const [refreshing, setRefreshing] = useState(false); const [stats, setStats] = useState({ totalExamples: 0 }); const fetchRandomExample = async (showLoadingState = true) => { if (showLoadingState) { setRefreshing(true); } try { const response = await axios.get('/api/examples/random'); setCurrentExample(response.data.data); } catch (error) { toast.error('Failed to load random example'); console.error('Error fetching random example:', error); } finally { setLoading(false); setRefreshing(false); } }; const fetchStats = async () => { try { const response = await axios.get('/api/stats'); setStats(response.data.data); } catch (error) { console.error('Error fetching stats:', error); } }; useEffect(() => { fetchRandomExample(); fetchStats(); }, []); const handleNewExample = () => { fetchRandomExample(true); }; if (loading) { return (
Discover transcreation examples through serendipitous exploration. Each click reveals a new example to inspire and educate.
Please try again later.