Redesign Dashboard + add WorkoutSelectPage
Dashboard (cleaner): - Week calendar at TOP - Coach greeting (workout today or rest tips) - If workout: gradient card with arrow → WorkoutPage - If rest: tips + '+ Lägg till pass' → WorkoutSelectPage - Quick stats at bottom WorkoutSelectPage: - Visual workout cards with icons and colors - Preview of exercises - Select + Start flow - Fixed bottom action button
This commit is contained in:
@@ -3,30 +3,44 @@ import { useAuth } from '../context/AuthContext'
|
||||
|
||||
const API_URL = '/api'
|
||||
|
||||
// Coach greetings based on time and context
|
||||
// Coach greetings based on context
|
||||
const getCoachGreeting = (user, todayWorkout) => {
|
||||
const hour = new Date().getHours()
|
||||
const name = user?.name?.split(' ')[0] || 'du'
|
||||
|
||||
if (hour < 10) {
|
||||
return todayWorkout
|
||||
? `Godmorgon ${name}! 💪 Redo för ${todayWorkout.name.toLowerCase()}?`
|
||||
: `Godmorgon ${name}! Vilodag idag – återhämtning är också träning.`
|
||||
} else if (hour < 14) {
|
||||
return todayWorkout
|
||||
? `Dags att köra ${name}! ${todayWorkout.name} väntar.`
|
||||
: `Lugn dag idag ${name}. Ladda batterierna! 🔋`
|
||||
} else if (hour < 18) {
|
||||
return todayWorkout
|
||||
? `Eftermiddagspass? ${todayWorkout.name} står på schemat 🏋️`
|
||||
: `Vila upp dig ${name}. Imorgon kör vi igen!`
|
||||
if (todayWorkout) {
|
||||
// There's a workout today
|
||||
if (hour < 10) {
|
||||
return `Godmorgon ${name}! Idag kör vi ${todayWorkout.name.toLowerCase()}. Redo? 💪`
|
||||
} else if (hour < 14) {
|
||||
return `${todayWorkout.name} står på schemat idag. Dags att köra! 🏋️`
|
||||
} else if (hour < 18) {
|
||||
return `Eftermiddagspass? ${todayWorkout.name} väntar på dig.`
|
||||
} else {
|
||||
return `Kvällspass ${name}? ${todayWorkout.name} – perfekt för att avsluta dagen.`
|
||||
}
|
||||
} else {
|
||||
return todayWorkout
|
||||
? `Kvällspass ${name}? Perfekt för att släppa dagen.`
|
||||
: `Bra jobbat denna veckan! Vila gott. 😴`
|
||||
// Rest day
|
||||
if (hour < 10) {
|
||||
return `Godmorgon ${name}! Vilodag idag – perfekt för återhämtning. 🧘`
|
||||
} else if (hour < 14) {
|
||||
return `Ingen träning schemalagd. Ta en promenad eller stretcha lite? 🚶`
|
||||
} else if (hour < 18) {
|
||||
return `Vila är också träning! Lätt rörelse eller mobilitet idag? 🧘`
|
||||
} else {
|
||||
return `Lugn kväll ${name}. Ladda batterierna till nästa pass! 😴`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Rest day tips
|
||||
const restDayTips = [
|
||||
{ icon: '🚶', text: '30 min promenad' },
|
||||
{ icon: '🧘', text: 'Yoga/stretching' },
|
||||
{ icon: '🏊', text: 'Simning' },
|
||||
{ icon: '🚴', text: 'Lätt cykling' },
|
||||
]
|
||||
|
||||
// Get weekday names
|
||||
const weekdays = ['Mån', 'Tis', 'Ons', 'Tor', 'Fre', 'Lör', 'Sön']
|
||||
|
||||
@@ -43,16 +57,13 @@ function Dashboard({ onStartWorkout, onNavigate }) {
|
||||
|
||||
const fetchData = async () => {
|
||||
try {
|
||||
// Fetch user's program
|
||||
const res = await fetch(`${API_URL}/programs/1`)
|
||||
const data = await res.json()
|
||||
setProgram(data)
|
||||
|
||||
// Determine today's workout based on day of week
|
||||
const dayOfWeek = new Date().getDay() // 0 = Sunday
|
||||
const adjustedDay = dayOfWeek === 0 ? 7 : dayOfWeek // Convert to 1-7 (Mon-Sun)
|
||||
|
||||
// Find if there's a workout scheduled for today
|
||||
const dayOfWeek = new Date().getDay()
|
||||
const adjustedDay = dayOfWeek === 0 ? 7 : dayOfWeek
|
||||
const todayDay = data.days?.find(d => d.day_number === adjustedDay)
|
||||
setTodayWorkout(todayDay || null)
|
||||
|
||||
@@ -89,15 +100,7 @@ function Dashboard({ onStartWorkout, onNavigate }) {
|
||||
</header>
|
||||
|
||||
<main className="dashboard-main">
|
||||
{/* Coach Greeting */}
|
||||
<section className="coach-greeting">
|
||||
<div className="coach-avatar">🧔♂️</div>
|
||||
<div className="coach-message">
|
||||
<p>{getCoachGreeting(user, todayWorkout)}</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* Week Calendar */}
|
||||
{/* Week Calendar - TOP */}
|
||||
<section className="week-calendar">
|
||||
<div className="calendar-header">
|
||||
<button
|
||||
@@ -139,51 +142,48 @@ function Dashboard({ onStartWorkout, onNavigate }) {
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* Today's Workout */}
|
||||
<section className="todays-workout">
|
||||
<h2>{todayWorkout ? 'Dagens pass' : 'Välj pass'}</h2>
|
||||
{todayWorkout ? (
|
||||
<div className="workout-card" onClick={() => onStartWorkout(todayWorkout)}>
|
||||
<div className="workout-card-header">
|
||||
<h3>{todayWorkout.name}</h3>
|
||||
<span className="workout-duration">~45 min</span>
|
||||
</div>
|
||||
<div className="workout-exercises">
|
||||
{todayWorkout.exercises?.filter(e => e.name).map((ex, i) => (
|
||||
<div key={i} className="exercise-preview">
|
||||
<span className="exercise-name">{ex.name}</span>
|
||||
<span className="exercise-sets">{ex.sets}×{ex.reps_min}-{ex.reps_max}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<button className="start-workout-btn">
|
||||
Starta pass →
|
||||
</button>
|
||||
{/* Coach Section with Today's Action */}
|
||||
<section className="coach-section">
|
||||
<div className="coach-greeting">
|
||||
<div className="coach-avatar">🧔♂️</div>
|
||||
<div className="coach-message">
|
||||
<p>{getCoachGreeting(user, todayWorkout)}</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="workout-list">
|
||||
{program?.days?.map((workout) => (
|
||||
<div
|
||||
key={workout.id}
|
||||
className="workout-card compact"
|
||||
onClick={() => onStartWorkout(workout)}
|
||||
>
|
||||
<div className="workout-card-header">
|
||||
<h3>{workout.name}</h3>
|
||||
<span className="workout-day">Dag {workout.day_number}</span>
|
||||
</div>
|
||||
<div className="workout-exercises compact">
|
||||
{workout.exercises?.filter(e => e.name).slice(0, 3).map((ex, i) => (
|
||||
<span key={i} className="exercise-tag">{ex.name}</span>
|
||||
))}
|
||||
{workout.exercises?.filter(e => e.name).length > 3 && (
|
||||
<span className="exercise-tag more">+{workout.exercises.filter(e => e.name).length - 3}</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Today's Action */}
|
||||
<div className="today-action">
|
||||
{todayWorkout ? (
|
||||
// Workout today - show workout card
|
||||
<div className="today-workout-card" onClick={() => onStartWorkout(todayWorkout)}>
|
||||
<div className="workout-info">
|
||||
<h3>{todayWorkout.name}</h3>
|
||||
<span className="workout-meta">
|
||||
{todayWorkout.exercises?.filter(e => e.name).length} övningar • ~45 min
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
<div className="workout-action">
|
||||
<span className="action-arrow">→</span>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
// Rest day - show tips + add button
|
||||
<div className="rest-day-section">
|
||||
<div className="rest-tips">
|
||||
{restDayTips.map((tip, i) => (
|
||||
<span key={i} className="tip-badge">{tip.icon} {tip.text}</span>
|
||||
))}
|
||||
</div>
|
||||
<button
|
||||
className="add-workout-btn"
|
||||
onClick={() => onNavigate('select-workout')}
|
||||
>
|
||||
<span className="add-icon">+</span>
|
||||
<span>Lägg till pass</span>
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* Quick Stats */}
|
||||
@@ -201,24 +201,6 @@ function Dashboard({ onStartWorkout, onNavigate }) {
|
||||
<span className="stat-label">Streak: 5</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* Upcoming Workouts */}
|
||||
<section className="upcoming-workouts">
|
||||
<h2>Kommande pass</h2>
|
||||
<div className="upcoming-list">
|
||||
{program?.days?.slice(0, 3).map((day, idx) => (
|
||||
<div
|
||||
key={day.id}
|
||||
className="upcoming-item"
|
||||
onClick={() => onStartWorkout(day)}
|
||||
>
|
||||
<span className="upcoming-day">{weekdays[day.day_number - 1]}</span>
|
||||
<span className="upcoming-name">{day.name}</span>
|
||||
<span className="upcoming-arrow">→</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
|
||||
const API_URL = '/api'
|
||||
|
||||
// Workout icons based on type/name
|
||||
const getWorkoutIcon = (name) => {
|
||||
const lower = name.toLowerCase()
|
||||
if (lower.includes('push') || lower.includes('bröst') || lower.includes('chest')) return '💪'
|
||||
if (lower.includes('pull') || lower.includes('rygg') || lower.includes('back')) return '🏋️'
|
||||
if (lower.includes('ben') || lower.includes('leg') || lower.includes('lower')) return '🦵'
|
||||
if (lower.includes('axlar') || lower.includes('shoulder')) return '🎯'
|
||||
if (lower.includes('arm')) return '💪'
|
||||
if (lower.includes('core') || lower.includes('mage')) return '🔥'
|
||||
if (lower.includes('helkropp') || lower.includes('full')) return '⚡'
|
||||
if (lower.includes('överkropp') || lower.includes('upper')) return '💪'
|
||||
if (lower.includes('underkropp') || lower.includes('lower')) return '🦵'
|
||||
return '🏋️'
|
||||
}
|
||||
|
||||
// Workout color based on type
|
||||
const getWorkoutColor = (name) => {
|
||||
const lower = name.toLowerCase()
|
||||
if (lower.includes('push') || lower.includes('bröst')) return '#ef4444' // Red
|
||||
if (lower.includes('pull') || lower.includes('rygg')) return '#3b82f6' // Blue
|
||||
if (lower.includes('ben') || lower.includes('leg')) return '#8b5cf6' // Purple
|
||||
if (lower.includes('axlar')) return '#f59e0b' // Orange
|
||||
if (lower.includes('överkropp') || lower.includes('upper')) return '#10b981' // Green
|
||||
if (lower.includes('underkropp') || lower.includes('lower')) return '#6366f1' // Indigo
|
||||
return '#6366f1' // Default indigo
|
||||
}
|
||||
|
||||
function WorkoutSelectPage({ onBack, onSelectWorkout }) {
|
||||
const [program, setProgram] = useState(null)
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [selectedWorkout, setSelectedWorkout] = useState(null)
|
||||
|
||||
useEffect(() => {
|
||||
fetchProgram()
|
||||
}, [])
|
||||
|
||||
const fetchProgram = async () => {
|
||||
try {
|
||||
const res = await fetch(`${API_URL}/programs/1`)
|
||||
const data = await res.json()
|
||||
setProgram(data)
|
||||
setLoading(false)
|
||||
} catch (err) {
|
||||
console.error('Failed to fetch program:', err)
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
const handleSelect = (workout) => {
|
||||
setSelectedWorkout(workout)
|
||||
}
|
||||
|
||||
const handleStart = () => {
|
||||
if (selectedWorkout) {
|
||||
onSelectWorkout(selectedWorkout)
|
||||
}
|
||||
}
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="select-page loading">
|
||||
<div className="spinner"></div>
|
||||
<p>Laddar pass...</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="select-page">
|
||||
<header className="page-header">
|
||||
<button className="back-btn" onClick={onBack}>← Tillbaka</button>
|
||||
<h1>Välj pass</h1>
|
||||
<div style={{ width: 40 }}></div>
|
||||
</header>
|
||||
|
||||
<main className="select-main">
|
||||
<p className="select-intro">
|
||||
Vilken träning vill du köra idag?
|
||||
</p>
|
||||
|
||||
<div className="workout-grid">
|
||||
{program?.days?.map((workout) => {
|
||||
const icon = getWorkoutIcon(workout.name)
|
||||
const color = getWorkoutColor(workout.name)
|
||||
const isSelected = selectedWorkout?.id === workout.id
|
||||
const exerciseCount = workout.exercises?.filter(e => e.name).length || 0
|
||||
|
||||
return (
|
||||
<div
|
||||
key={workout.id}
|
||||
className={`workout-select-card ${isSelected ? 'selected' : ''}`}
|
||||
style={{ '--workout-color': color }}
|
||||
onClick={() => handleSelect(workout)}
|
||||
>
|
||||
<div className="workout-icon" style={{ background: color }}>
|
||||
{icon}
|
||||
</div>
|
||||
<div className="workout-details">
|
||||
<h3>{workout.name}</h3>
|
||||
<p className="workout-exercises-count">
|
||||
{exerciseCount} övningar
|
||||
</p>
|
||||
<div className="workout-preview">
|
||||
{workout.exercises?.filter(e => e.name).slice(0, 2).map((ex, i) => (
|
||||
<span key={i} className="preview-exercise">{ex.name}</span>
|
||||
))}
|
||||
{exerciseCount > 2 && (
|
||||
<span className="preview-more">+{exerciseCount - 2} till</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
{isSelected && (
|
||||
<div className="selected-indicator">✓</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
|
||||
{/* Selected workout action */}
|
||||
{selectedWorkout && (
|
||||
<div className="select-action">
|
||||
<button className="start-btn" onClick={handleStart}>
|
||||
Starta {selectedWorkout.name} →
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</main>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default WorkoutSelectPage
|
||||
Reference in New Issue
Block a user