54 lines
1.2 KiB
TypeScript
54 lines
1.2 KiB
TypeScript
'use client';
|
|
|
|
import { useState, useEffect } from 'react';
|
|
import {
|
|
UserMetrics,
|
|
WorkoutSession,
|
|
saveWorkoutSession,
|
|
getWorkoutSessions,
|
|
updateWorkoutSession,
|
|
deleteWorkoutSession,
|
|
getWorkoutsByType,
|
|
getWorkoutsByDateRange,
|
|
saveUserMetrics,
|
|
getUserMetrics,
|
|
updateUserMetrics,
|
|
calculateMetricsFromSessions,
|
|
} from '@/lib/storage/workoutStorage';
|
|
|
|
export function useWorkoutData() {
|
|
const [workouts, setWorkouts] = useState<WorkoutSession[]>([]);
|
|
const [metrics, setMetrics] = useState<UserMetrics | null>(null);
|
|
const [loading, setLoading] = useState(true);
|
|
|
|
useEffect(() => {
|
|
const loadData = async () => {
|
|
try {
|
|
const [workoutList, userMetrics] = await Promise.all([
|
|
getWorkoutSessions(),
|
|
getUserMetrics(),
|
|
]);
|
|
setWorkouts(workoutList);
|
|
setMetrics(userMetrics);
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
};
|
|
loadData();
|
|
}, []);
|
|
|
|
return {
|
|
workouts,
|
|
metrics,
|
|
loading,
|
|
saveWorkoutSession,
|
|
updateWorkoutSession,
|
|
deleteWorkoutSession,
|
|
getWorkoutsByType,
|
|
getWorkoutsByDateRange,
|
|
saveUserMetrics,
|
|
updateUserMetrics,
|
|
calculateMetricsFromSessions,
|
|
};
|
|
}
|