Workout Management tests done
This commit is contained in:
@@ -2,6 +2,7 @@ import React, { useState } from 'react';
|
||||
import { Calendar, Clock, TrendingUp, Gauge, Pencil, Trash2, X, Save, ArrowRight, ArrowUp, Timer, Activity, Dumbbell, Percent } from 'lucide-react';
|
||||
import { WorkoutSession, ExerciseType, WorkoutSet, Language } from '../types';
|
||||
import { t } from '../services/i18n';
|
||||
import { formatSetMetrics } from '../utils/setFormatting';
|
||||
import { useSession } from '../context/SessionContext';
|
||||
import { Button } from './ui/Button';
|
||||
import { Card } from './ui/Card';
|
||||
@@ -243,13 +244,7 @@ const History: React.FC<HistoryProps> = ({ lang }) => {
|
||||
{set.side && <span className="ml-2 text-xs font-medium text-on-surface-variant">{t(set.side.toLowerCase() as any, lang)}</span>}
|
||||
</div>
|
||||
<div className="text-sm text-on-surface-variant mt-1">
|
||||
{set.type === ExerciseType.STRENGTH && `${set.weight || 0}kg x ${set.reps || 0}`}
|
||||
{set.type === ExerciseType.BODYWEIGHT && `${set.weight ? `+${set.weight}kg` : 'BW'} x ${set.reps || 0}`}
|
||||
{set.type === ExerciseType.CARDIO && `${set.durationSeconds || 0}s ${set.distanceMeters ? `/ ${set.distanceMeters}m` : ''}`}
|
||||
{set.type === ExerciseType.STATIC && `${set.durationSeconds || 0}s`}
|
||||
{set.type === ExerciseType.HIGH_JUMP && `${set.height || 0}cm`}
|
||||
{set.type === ExerciseType.LONG_JUMP && `${set.distanceMeters || 0}m`}
|
||||
{set.type === ExerciseType.PLYOMETRIC && `x ${set.reps || 0}`}
|
||||
{formatSetMetrics(set, lang)}
|
||||
</div>
|
||||
<div className="text-xs text-on-surface-variant mt-1">
|
||||
{new Date(set.timestamp).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}
|
||||
|
||||
@@ -20,7 +20,7 @@ interface PlansProps {
|
||||
const Plans: React.FC<PlansProps> = ({ lang }) => {
|
||||
const { currentUser } = useAuth();
|
||||
const userId = currentUser?.id || '';
|
||||
const { plans, savePlan, deletePlan } = useSession();
|
||||
const { plans, savePlan, deletePlan, refreshData } = useSession();
|
||||
const { startSession } = useActiveWorkout();
|
||||
|
||||
const [isEditing, setIsEditing] = useState(false);
|
||||
@@ -45,6 +45,7 @@ const Plans: React.FC<PlansProps> = ({ lang }) => {
|
||||
|
||||
useEffect(() => {
|
||||
const loadData = async () => {
|
||||
refreshData();
|
||||
const fetchedExercises = await getExercises(userId);
|
||||
// Filter out archived exercises
|
||||
if (Array.isArray(fetchedExercises)) {
|
||||
@@ -54,7 +55,7 @@ const Plans: React.FC<PlansProps> = ({ lang }) => {
|
||||
}
|
||||
};
|
||||
if (userId) loadData();
|
||||
}, [userId]);
|
||||
}, [userId, refreshData]);
|
||||
|
||||
const handleCreateNew = () => {
|
||||
setEditId(generateId());
|
||||
|
||||
@@ -6,6 +6,7 @@ import FilledInput from '../FilledInput';
|
||||
import ExerciseModal from '../ExerciseModal';
|
||||
import { useTracker } from './useTracker';
|
||||
import SetLogger from './SetLogger';
|
||||
import { formatSetMetrics } from '../../utils/setFormatting';
|
||||
|
||||
interface ActiveSessionViewProps {
|
||||
tracker: ReturnType<typeof useTracker>;
|
||||
@@ -95,6 +96,7 @@ const ActiveSessionView: React.FC<ActiveSessionViewProps> = ({ tracker, activeSe
|
||||
<button
|
||||
onClick={() => setShowMenu(!showMenu)}
|
||||
className="p-2 rounded-full bg-surface-container-high text-on-surface hover:bg-surface-container-highest transition-colors"
|
||||
aria-label="Options"
|
||||
>
|
||||
<MoreVertical size={20} />
|
||||
</button>
|
||||
@@ -247,27 +249,7 @@ const ActiveSessionView: React.FC<ActiveSessionViewProps> = ({ tracker, activeSe
|
||||
<div>
|
||||
<div className="text-base font-medium text-on-surface">{set.exerciseName}{set.side && <span className="ml-2 text-xs font-medium text-on-surface-variant">{t(set.side.toLowerCase() as any, lang)}</span>}</div>
|
||||
<div className="text-sm text-on-surface-variant">
|
||||
{set.type === ExerciseType.STRENGTH &&
|
||||
`${set.weight ? `${set.weight}kg` : ''} ${set.reps ? `x ${set.reps}` : ''}`.trim()
|
||||
}
|
||||
{set.type === ExerciseType.BODYWEIGHT &&
|
||||
`${set.weight ? `${set.weight}kg` : ''} ${set.reps ? `x ${set.reps}` : ''}`.trim()
|
||||
}
|
||||
{set.type === ExerciseType.CARDIO &&
|
||||
`${set.durationSeconds ? `${set.durationSeconds}s` : ''} ${set.distanceMeters ? `/ ${set.distanceMeters}m` : ''}`.trim()
|
||||
}
|
||||
{set.type === ExerciseType.STATIC &&
|
||||
`${set.durationSeconds ? `${set.durationSeconds}s` : ''}`.trim()
|
||||
}
|
||||
{set.type === ExerciseType.HIGH_JUMP &&
|
||||
`${set.height ? `${set.height}cm` : ''}`.trim()
|
||||
}
|
||||
{set.type === ExerciseType.LONG_JUMP &&
|
||||
`${set.distanceMeters ? `${set.distanceMeters}m` : ''}`.trim()
|
||||
}
|
||||
{set.type === ExerciseType.PLYOMETRIC &&
|
||||
`${set.reps ? `x ${set.reps}` : ''}`.trim()
|
||||
}
|
||||
{formatSetMetrics(set, lang)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
@@ -278,12 +260,14 @@ const ActiveSessionView: React.FC<ActiveSessionViewProps> = ({ tracker, activeSe
|
||||
<button
|
||||
onClick={handleCancelEdit}
|
||||
className="p-2 text-on-surface-variant hover:text-on-surface hover:bg-surface-container-high rounded-full transition-colors"
|
||||
aria-label={t('cancel', lang)}
|
||||
>
|
||||
<X size={20} />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => handleSaveEdit(set)}
|
||||
className="p-2 text-primary hover:bg-primary-container/20 rounded-full transition-colors"
|
||||
aria-label={t('save', lang)}
|
||||
>
|
||||
<CheckCircle size={20} />
|
||||
</button>
|
||||
@@ -293,12 +277,14 @@ const ActiveSessionView: React.FC<ActiveSessionViewProps> = ({ tracker, activeSe
|
||||
<button
|
||||
onClick={() => handleEditSet(set)}
|
||||
className="p-2 text-on-surface-variant hover:text-primary hover:bg-primary-container/20 rounded-full transition-colors"
|
||||
aria-label={t('edit', lang)}
|
||||
>
|
||||
<Edit size={20} />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => onRemoveSet(set.id)}
|
||||
className="p-2 text-on-surface-variant hover:text-error hover:bg-error-container/10 rounded-full transition-colors"
|
||||
aria-label={t('delete', lang)}
|
||||
>
|
||||
<Trash2 size={20} />
|
||||
</button>
|
||||
|
||||
@@ -64,6 +64,7 @@ const SetLogger: React.FC<SetLoggerProps> = ({ tracker, lang, onLogSet, isSporad
|
||||
<button
|
||||
onClick={() => setIsCreating(true)}
|
||||
className="p-2 text-primary hover:bg-primary-container/20 rounded-full"
|
||||
aria-label="Add Exercise"
|
||||
>
|
||||
<Plus size={24} />
|
||||
</button>
|
||||
|
||||
@@ -5,6 +5,7 @@ import { t } from '../../services/i18n';
|
||||
import ExerciseModal from '../ExerciseModal';
|
||||
import { useTracker } from './useTracker';
|
||||
import SetLogger from './SetLogger';
|
||||
import { formatSetMetrics } from '../../utils/setFormatting';
|
||||
|
||||
interface SporadicViewProps {
|
||||
tracker: ReturnType<typeof useTracker>;
|
||||
@@ -40,13 +41,7 @@ const SporadicView: React.FC<SporadicViewProps> = ({ tracker, lang }) => {
|
||||
}, [quickLogSession]);
|
||||
|
||||
const renderSetMetrics = (set: WorkoutSet) => {
|
||||
const metrics: string[] = [];
|
||||
if (set.weight) metrics.push(`${set.weight} ${t('weight_kg', lang)}`);
|
||||
if (set.reps) metrics.push(`${set.reps} ${t('reps', lang)}`);
|
||||
if (set.durationSeconds) metrics.push(`${set.durationSeconds} ${t('time_sec', lang)}`);
|
||||
if (set.distanceMeters) metrics.push(`${set.distanceMeters} ${t('dist_m', lang)}`);
|
||||
if (set.height) metrics.push(`${set.height} ${t('height_cm', lang)}`);
|
||||
return metrics.join(' / ');
|
||||
return formatSetMetrics(set, lang);
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -80,7 +80,7 @@ export const useTracker = (props: any) => { // Props ignored/removed
|
||||
loadQuickLogSession();
|
||||
};
|
||||
loadData();
|
||||
}, [activeSession, userId, userWeight, activePlan]);
|
||||
}, [activeSession?.id, userId, userWeight, activePlan?.id, isSporadicMode]);
|
||||
|
||||
// Function to reload Quick Log session
|
||||
const loadQuickLogSession = async () => {
|
||||
@@ -99,7 +99,7 @@ export const useTracker = (props: any) => { // Props ignored/removed
|
||||
const step = planExec.getCurrentStep();
|
||||
if (step) {
|
||||
const exDef = exercises.find(e => e.id === step.exerciseId);
|
||||
if (exDef) {
|
||||
if (exDef && selectedExercise?.id !== exDef.id) {
|
||||
setSelectedExercise(exDef);
|
||||
}
|
||||
}
|
||||
@@ -113,6 +113,7 @@ export const useTracker = (props: any) => { // Props ignored/removed
|
||||
await form.updateFormFromLastSet(selectedExercise.id, selectedExercise.type, selectedExercise.bodyWeightPercentage);
|
||||
} else {
|
||||
setSearchQuery('');
|
||||
form.resetForm();
|
||||
}
|
||||
};
|
||||
updateSelection();
|
||||
@@ -155,7 +156,7 @@ export const useTracker = (props: any) => { // Props ignored/removed
|
||||
setSporadicSuccess(true);
|
||||
setTimeout(() => setSporadicSuccess(false), 2000);
|
||||
loadQuickLogSession();
|
||||
form.resetForm();
|
||||
// form.resetForm(); // Persist values
|
||||
refreshHistory();
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user