Spaces:
Build error
Build error
Download components/WorkoutGenerator.jsx from rbachina/anycoder-d4f3e582: direct link, hf CLI and curl.
- Browser
- Download file 4.59 kB
-
https://huggingface.co/spaces/rbachina/anycoder-d4f3e582/resolve/main/components/WorkoutGenerator.jsx
- Command line
-
hf download hf://spaces/rbachina/anycoder-d4f3e582/components/WorkoutGenerator.jsx
-
curl -L -o WorkoutGenerator.jsx https://huggingface.co/spaces/rbachina/anycoder-d4f3e582/resolve/main/components/WorkoutGenerator.jsx
4.59 kB
| import { useState, useEffect } from 'react'; | |
| import { Shuffle, Filter, Sparkles } from 'lucide-react'; | |
| import WorkoutCard from './WorkoutCard'; | |
| const categories = [ | |
| { id: 'all', label: 'All Snacks', icon: '🎯' }, | |
| { id: 'strength', label: 'Strength', icon: '💪' }, | |
| { id: 'cardio', label: 'Cardio', icon: '❤️' }, | |
| { id: 'stretch', label: 'Stretch', icon: '🧘' }, | |
| { id: 'mindfulness', label: 'Mind', icon: '🧠' }, | |
| { id: 'wellness', label: 'Wellness', icon: '✨' } | |
| ]; | |
| export default function WorkoutGenerator({ favorites, onToggleFavorite }) { | |
| const [workouts, setWorkouts] = useState([]); | |
| const [currentWorkout, setCurrentWorkout] = useState(null); | |
| const [selectedCategory, setSelectedCategory] = useState('all'); | |
| const [loading, setLoading] = useState(false); | |
| useEffect(() => { | |
| fetchWorkouts(); | |
| }, [selectedCategory]); | |
| const fetchWorkouts = async () => { | |
| setLoading(true); | |
| try { | |
| const res = await fetch(`/api/workouts?category=${selectedCategory}`); | |
| const data = await res.json(); | |
| setWorkouts(data); | |
| if (data.length > 0) { | |
| setCurrentWorkout(data[Math.floor(Math.random() * data.length)]); | |
| } | |
| } catch (error) { | |
| console.error('Failed to fetch workouts:', error); | |
| } | |
| setLoading(false); | |
| }; | |
| const generateRandom = async () => { | |
| setLoading(true); | |
| try { | |
| const res = await fetch(`/api/workouts?category=${selectedCategory}&random=true`); | |
| const data = await res.json(); | |
| if (data.length > 0) { | |
| setCurrentWorkout(data[0]); | |
| } | |
| } catch (error) { | |
| console.error('Failed to generate workout:', error); | |
| } | |
| setLoading(false); | |
| }; | |
| return ( | |
| <div className="space-y-6"> | |
| <div className="bg-gradient-to-r from-primary-600 to-primary-700 rounded-2xl p-8 text-white shadow-xl"> | |
| <div className="flex flex-col md:flex-row items-start md:items-center justify-between gap-4 mb-6"> | |
| <div> | |
| <h2 className="text-3xl font-bold mb-2 flex items-center gap-2"> | |
| <Sparkles className="w-8 h-8 text-yellow-300" /> | |
| Workout Snack Generator | |
| </h2> | |
| <p className="text-primary-100">Quick desk-friendly exercises to keep you energized throughout the day</p> | |
| </div> | |
| <a | |
| href="https://huggingface.co/spaces/akhaliq/anycoder" | |
| target="_blank" | |
| rel="noopener noreferrer" | |
| className="text-sm bg-white/20 hover:bg-white/30 px-4 py-2 rounded-full transition-colors backdrop-blur-sm" | |
| > | |
| Built with anycoder → | |
| </a> | |
| </div> | |
| <div className="flex flex-wrap gap-2 mb-6"> | |
| {categories.map(cat => ( | |
| <button | |
| key={cat.id} | |
| onClick={() => setSelectedCategory(cat.id)} | |
| className={`px-4 py-2 rounded-full text-sm font-medium transition-all duration-200 ${selectedCategory === cat.id ? 'bg-white text-primary-700 shadow-lg' : 'bg-primary-500/50 text-white hover:bg-primary-500'}`} | |
| > | |
| <span className="mr-1">{cat.icon}</span> {cat.label} | |
| </button> | |
| ))} | |
| </div> | |
| <button | |
| onClick={generateRandom} | |
| disabled={loading} | |
| className="w-full md:w-auto bg-white text-primary-700 hover:bg-primary-50 font-bold py-3 px-8 rounded-xl shadow-lg hover:shadow-xl transition-all duration-200 flex items-center justify-center gap-2 disabled:opacity-50" | |
| > | |
| <Shuffle className={`w-5 h-5 ${loading ? 'animate-spin' : ''}`} /> | |
| {loading ? 'Generating...' : 'Generate Random Snack'} | |
| </button> | |
| </div> | |
| {currentWorkout && ( | |
| <div className="max-w-2xl mx-auto"> | |
| <div className="text-center mb-4"> | |
| <span className="inline-block px-4 py-1 bg-accent-100 text-accent-700 rounded-full text-sm font-semibold"> | |
| Your Daily Snack | |
| </span> | |
| </div> | |
| <WorkoutCard | |
| workout={currentWorkout} | |
| isFavorite={favorites.includes(currentWorkout.id)} | |
| onToggleFavorite={onToggleFavorite} | |
| /> | |
| </div> | |
| )} | |
| <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6"> | |
| {workouts.filter(w => w.id !== currentWorkout?.id).map(workout => ( | |
| <WorkoutCard | |
| key={workout.id} | |
| workout={workout} | |
| isFavorite={favorites.includes(workout.id)} | |
| onToggleFavorite={onToggleFavorite} | |
| /> | |
| ))} | |
| </div> | |
| </div> | |
| ); | |
| } |