import { useState, useEffect } from 'react'; import { Smile, ThumbsUp, ThumbsDown, RefreshCw, Award } from 'lucide-react'; export default function JokeGenerator() { const [joke, setJoke] = useState(''); const [punchline, setPunchline] = useState(''); const [showPunchline, setShowPunchline] = useState(false); const [loading, setLoading] = useState(false); const [reaction, setReaction] = useState(null); const [likedJokes, setLikedJokes] = useState([]); const [jokeIndex, setJokeIndex] = useState(0); // Collection of jokes const jokes = [ { setup: "Why don't scientists trust atoms?", punchline: "Because they make up everything!" }, { setup: "Why did the scarecrow win an award?", punchline: "Because he was outstanding in his field!" }, { setup: "What's the best thing about Switzerland?", punchline: "I don't know, but the flag is a big plus!" }, { setup: "Did you hear about the mathematician who's afraid of negative numbers?", punchline: "He'll stop at nothing to avoid them!" }, { setup: "Why don't eggs tell jokes?", punchline: "They'd crack each other up!" }, { setup: "How do you organize a space party?", punchline: "You planet!" }, { setup: "Why did the bicycle fall over?", punchline: "It was two tired!" }, { setup: "What do you call a fake noodle?", punchline: "An impasta!" }, { setup: "How does a penguin build its house?", punchline: "Igloos it together!" }, { setup: "Why don't skeletons fight each other?", punchline: "They don't have the guts!" } ]; // Load a joke on initial render useEffect(() => { getNewJoke(); }, []); const getNewJoke = () => { setLoading(true); setShowPunchline(false); setReaction(null); // Simulate loading setTimeout(() => { const newIndex = (jokeIndex + 1) % jokes.length; setJokeIndex(newIndex); setJoke(jokes[newIndex].setup); setPunchline(jokes[newIndex].punchline); setLoading(false); }, 600); }; const revealPunchline = () => { setShowPunchline(true); // Trigger a laugh animation setReaction('laugh'); setTimeout(() => setReaction(null), 2000); }; const rateJoke = (liked) => { if (liked) { setLikedJokes([...likedJokes, { setup: joke, punchline }]); setReaction('thumbsUp'); } else { setReaction('thumbsDown'); } setTimeout(() => { setReaction(null); getNewJoke(); }, 1000); }; return (

Joke Generator

{likedJokes.length} Liked
{loading ? (

Finding a good one...

) : ( <>

{joke}

{!showPunchline ? ( ) : (

{punchline}

)}
)}
{/* Reaction animations */}
{reaction === 'laugh' && (
)} {reaction === 'thumbsUp' && (
)} {reaction === 'thumbsDown' && (
)}
{likedJokes.length > 0 && (

Your Favorite Jokes

{likedJokes.map((likedJoke, index) => (

{likedJoke.setup}

{likedJoke.punchline}

))}
)}
); }