Spaces:
Build error
Build error
Download components/WeeklyCalendar.jsx from rbachina/anycoder-d4f3e582: direct link, hf CLI and curl.
- Browser
- Download file 7.83 kB
-
https://huggingface.co/spaces/rbachina/anycoder-d4f3e582/resolve/main/components/WeeklyCalendar.jsx
- Command line
-
hf download hf://spaces/rbachina/anycoder-d4f3e582/components/WeeklyCalendar.jsx
-
curl -L -o WeeklyCalendar.jsx https://huggingface.co/spaces/rbachina/anycoder-d4f3e582/resolve/main/components/WeeklyCalendar.jsx
7.83 kB
| import { useState, useEffect } from 'react'; | |
| import { Calendar as CalendarIcon, Clock, Trash2, Bell } from 'lucide-react'; | |
| const days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']; | |
| const timeSlots = ['9:00 AM', '11:00 AM', '2:00 PM', '4:00 PM', '5:30 PM']; | |
| export default function WeeklyCalendar({ workouts, favorites }) { | |
| const [schedule, setSchedule] = useState({}); | |
| const [selectedSlot, setSelectedSlot] = useState(null); | |
| const [showAlert, setShowAlert] = useState(false); | |
| useEffect(() => { | |
| const saved = localStorage.getItem('microfit_schedule'); | |
| if (saved) { | |
| setSchedule(JSON.parse(saved)); | |
| } | |
| }, []); | |
| useEffect(() => { | |
| localStorage.setItem('microfit_schedule', JSON.stringify(schedule)); | |
| }, [schedule]); | |
| const addToSchedule = (day, time, workoutId) => { | |
| const key = `${day}-${time}`; | |
| const workout = workouts.find(w => w.id === workoutId); | |
| setSchedule(prev => ({ | |
| ...prev, | |
| [key]: workout | |
| })); | |
| setSelectedSlot(null); | |
| setShowAlert(true); | |
| setTimeout(() => setShowAlert(false), 3000); | |
| }; | |
| const removeFromSchedule = (key) => { | |
| setSchedule(prev => { | |
| const newSchedule = { ...prev }; | |
| delete newSchedule[key]; | |
| return newSchedule; | |
| }); | |
| }; | |
| const getWorkoutForSlot = (day, time) => { | |
| const key = `${day}-${time}`; | |
| return schedule[key]; | |
| }; | |
| return ( | |
| <div className="bg-white rounded-xl shadow-lg p-6 border border-gray-100"> | |
| <div className="flex items-center justify-between mb-6"> | |
| <div className="flex items-center gap-3"> | |
| <div className="p-3 bg-primary-100 rounded-lg"> | |
| <CalendarIcon className="w-6 h-6 text-primary-600" /> | |
| </div> | |
| <div> | |
| <h2 className="text-2xl font-bold text-gray-900">Weekly Snack Schedule</h2> | |
| <p className="text-gray-500 text-sm">Plan your desk breaks throughout the week</p> | |
| </div> | |
| </div> | |
| <div className="flex items-center gap-2 text-sm text-gray-600 bg-yellow-50 px-4 py-2 rounded-lg border border-yellow-200"> | |
| <Bell className="w-4 h-4 text-yellow-600" /> | |
| <span>Alerts enabled</span> | |
| </div> | |
| </div> | |
| {showAlert && ( | |
| <div className="mb-4 p-4 bg-accent-50 border border-accent-200 rounded-lg flex items-center gap-2 text-accent-700 animate-pulse"> | |
| <Bell className="w-5 h-5" /> | |
| <span className="font-medium">Workout snack scheduled! We'll remind you when it's time.</span> | |
| </div> | |
| )} | |
| <div className="overflow-x-auto"> | |
| <div className="min-w-[800px]"> | |
| <div className="grid grid-cols-8 gap-2 mb-2"> | |
| <div className="text-sm font-semibold text-gray-500 p-2">Time</div> | |
| {days.map(day => ( | |
| <div key={day} className="text-sm font-bold text-gray-700 p-2 text-center bg-gray-50 rounded-lg"> | |
| {day.slice(0, 3)} | |
| </div> | |
| ))} | |
| </div> | |
| {timeSlots.map(time => ( | |
| <div key={time} className="grid grid-cols-8 gap-2 mb-2"> | |
| <div className="text-xs font-medium text-gray-500 p-2 flex items-center"> | |
| <Clock className="w-3 h-3 mr-1" /> {time} | |
| </div> | |
| {days.map(day => { | |
| const workout = getWorkoutForSlot(day, time); | |
| return ( | |
| <div key={`${day}-${time}`} className="relative"> | |
| {workout ? ( | |
| <div className="p-2 bg-primary-50 border border-primary-200 rounded-lg text-xs group hover:bg-primary-100 transition-colors cursor-pointer relative"> | |
| <div className="font-semibold text-primary-800 truncate">{workout.title}</div> | |
| <div className="text-primary-600 text-xs">{workout.duration} min</div> | |
| <button | |
| onClick={() => removeFromSchedule(`${day}-${time}`)} | |
| className="absolute -top-2 -right-2 bg-red-500 text-white p-1 rounded-full opacity-0 group-hover:opacity-100 transition-opacity shadow-sm" | |
| > | |
| <Trash2 className="w-3 h-3" /> | |
| </button> | |
| </div> | |
| ) : ( | |
| <button | |
| onClick={() => setSelectedSlot({ day, time })} | |
| className="w-full h-full p-2 border-2 border-dashed border-gray-200 rounded-lg text-gray-400 hover:border-primary-300 hover:text-primary-500 transition-all text-xs flex items-center justify-center min-h-[60px]" | |
| > | |
| + Add | |
| </button> | |
| )} | |
| </div> | |
| ); | |
| })} | |
| </div> | |
| ))} | |
| </div> | |
| </div> | |
| {selectedSlot && ( | |
| <div className="fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4"> | |
| <div className="bg-white rounded-xl shadow-2xl max-w-md w-full max-h-[80vh] overflow-y-auto"> | |
| <div className="p-6 border-b border-gray-100"> | |
| <h3 className="text-lg font-bold text-gray-900"> | |
| Schedule for {selectedSlot.day} at {selectedSlot.time} | |
| </h3> | |
| <p className="text-gray-500 text-sm mt-1">Choose a workout snack from your favorites or all workouts</p> | |
| </div> | |
| <div className="p-4 space-y-2"> | |
| {favorites.length > 0 && ( | |
| <div className="mb-4"> | |
| <h4 className="text-xs font-semibold text-gray-500 uppercase tracking-wider mb-2">From Favorites</h4> | |
| {workouts.filter(w => favorites.includes(w.id)).map(workout => ( | |
| <button | |
| key={workout.id} | |
| onClick={() => addToSchedule(selectedSlot.day, selectedSlot.time, workout.id)} | |
| className="w-full text-left p-3 rounded-lg hover:bg-gray-50 border border-gray-200 mb-2 flex items-center gap-3 transition-colors" | |
| > | |
| <span className="text-2xl">💪</span> | |
| <div> | |
| <div className="font-medium text-gray-900">{workout.title}</div> | |
| <div className="text-xs text-gray-500">{workout.duration} min • {workout.category}</div> | |
| </div> | |
| </button> | |
| ))} | |
| </div> | |
| )} | |
| <div> | |
| <h4 className="text-xs font-semibold text-gray-500 uppercase tracking-wider mb-2">All Workouts</h4> | |
| {workouts.filter(w => !favorites.includes(w.id)).map(workout => ( | |
| <button | |
| key={workout.id} | |
| onClick={() => addToSchedule(selectedSlot.day, selectedSlot.time, workout.id)} | |
| className="w-full text-left p-3 rounded-lg hover:bg-gray-50 border border-gray-200 mb-2 flex items-center gap-3 transition-colors" | |
| > | |
| <span className="text-2xl">💪</span> | |
| <div> | |
| <div className="font-medium text-gray-900">{workout.title}</div> | |
| <div className="text-xs text-gray-500">{workout.duration} min • {workout.category}</div> | |
| </div> | |
| </button> | |
| ))} | |
| </div> | |
| </div> | |
| <div className="p-4 border-t border-gray-100 bg-gray-50"> | |
| <button | |
| onClick={() => setSelectedSlot(null)} | |
| className="w-full btn-secondary" | |
| > | |
| Cancel | |
| </button> | |
| </div> | |
| </div> | |
| </div> | |
| )} | |
| </div> | |
| ); | |
| } |