65 lines
1.5 KiB
TypeScript
65 lines
1.5 KiB
TypeScript
'use client';
|
|
|
|
export interface ExerciseLog {
|
|
id: string;
|
|
name: string;
|
|
sets: number;
|
|
reps: number;
|
|
weight?: number;
|
|
}
|
|
|
|
export interface WorkoutSession {
|
|
id: string;
|
|
date: string;
|
|
type: 'cardio' | 'training' | 'nutrition';
|
|
distance?: number;
|
|
duration: number;
|
|
pace?: string;
|
|
calories?: number;
|
|
steps?: number;
|
|
exercises?: ExerciseLog[];
|
|
meals?: Array<{
|
|
id: string;
|
|
name: string;
|
|
calories: number;
|
|
protein: number;
|
|
carbs: number;
|
|
fats: number;
|
|
timestamp: string;
|
|
}>;
|
|
notes?: string;
|
|
}
|
|
|
|
const STORAGE_KEY = 'workout_sessions';
|
|
|
|
export const workoutStorage = {
|
|
getSessions: (): WorkoutSession[] => {
|
|
if (typeof window === 'undefined') return [];
|
|
const stored = localStorage.getItem(STORAGE_KEY);
|
|
return stored ? JSON.parse(stored) : [];
|
|
},
|
|
|
|
addSession: (session: Omit<WorkoutSession, 'id'>): WorkoutSession => {
|
|
const sessions = workoutStorage.getSessions();
|
|
const newSession: WorkoutSession = {
|
|
...session,
|
|
id: `session-${Date.now()}`,
|
|
};
|
|
sessions.push(newSession);
|
|
if (typeof window !== 'undefined') {
|
|
localStorage.setItem(STORAGE_KEY, JSON.stringify(sessions));
|
|
}
|
|
return newSession;
|
|
},
|
|
|
|
getSessionsByDate: (date: string): WorkoutSession[] => {
|
|
const sessions = workoutStorage.getSessions();
|
|
return sessions.filter((s) => s.date.startsWith(date));
|
|
},
|
|
|
|
getTodaysSessions: (): WorkoutSession[] => {
|
|
const currentDate = new Date().toISOString().split('T')[0];
|
|
return workoutStorage.getSessionsByDate(currentDate);
|
|
},
|
|
};
|