Skip to content

Commit a93097a

Browse files
CopilotBruno-366
andcommitted
Fix TypeScript type errors: add type annotations and assertions
Co-authored-by: Bruno-366 <81762173+Bruno-366@users.noreply.github.com>
1 parent 848018a commit a93097a

File tree

1 file changed

+56
-56
lines changed

1 file changed

+56
-56
lines changed

src/App.tsx

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react';
1+
import { useState } from 'react';
22
import { Activity, Clock, CheckCircle } from 'lucide-react';
33

44
const App = () => {
@@ -364,10 +364,10 @@ const App = () => {
364364
const HISTORY_CONFIGS = {
365365
rest: { color: 'bg-slate-400', label: 'Rest', summary: 'Recovery day' },
366366
deload: { color: 'bg-slate-400', label: 'Deload', summary: 'Light activity' },
367-
liss: { color: 'bg-green-500', label: 'LISS', getSummary: (w) => `${w.activity} - ${w.duration}${typeof w.duration === 'number' ? ' min' : ''}` },
368-
hiit: { color: 'bg-yellow-500', label: 'HIIT', getSummary: (w) => `${w.activity} - ${w.duration}${typeof w.duration === 'number' ? ' min' : ''}` },
369-
strength: { color: 'bg-red-500', label: 'Strength', getSummary: (w) => w.exercises?.join(', ') || 'Strength training' },
370-
hypertrophy: { color: 'bg-blue-500', label: 'Hypertrophy', getSummary: (w) => w.exercises?.slice(0, 3).join(', ') + (w.exercises?.length > 3 ? '...' : '') || 'Accessory work' }
367+
liss: { color: 'bg-green-500', label: 'LISS', getSummary: (w: any) => `${w.activity} - ${w.duration}${typeof w.duration === 'number' ? ' min' : ''}` },
368+
hiit: { color: 'bg-yellow-500', label: 'HIIT', getSummary: (w: any) => `${w.activity} - ${w.duration}${typeof w.duration === 'number' ? ' min' : ''}` },
369+
strength: { color: 'bg-red-500', label: 'Strength', getSummary: (w: any) => w.exercises?.join(', ') || 'Strength training' },
370+
hypertrophy: { color: 'bg-blue-500', label: 'Hypertrophy', getSummary: (w: any) => w.exercises?.slice(0, 3).join(', ') + (w.exercises?.length > 3 ? '...' : '') || 'Accessory work' }
371371
};
372372

373373
const AVAILABLE_BLOCKS = {
@@ -381,7 +381,7 @@ const App = () => {
381381
};
382382

383383
// Helper function to generate exercise key from name
384-
const getExerciseKey = (exerciseName) => {
384+
const getExerciseKey = (exerciseName: string) => {
385385
return exerciseName.toLowerCase().replace(/\s+/g, '').replace(/[^a-z0-9]/g, '');
386386
};
387387

@@ -390,16 +390,16 @@ const App = () => {
390390
const currentBlock = state.customPlan[0];
391391
if (!currentBlock) return { strengthExercises: [], hypertrophyExercises: [] };
392392

393-
const blockTemplate = blockTemplates[currentBlock.type];
393+
const blockTemplate = blockTemplates[currentBlock.type as keyof typeof blockTemplates];
394394
if (!blockTemplate) return { strengthExercises: [], hypertrophyExercises: [] };
395395

396396
const strengthExercises = new Set();
397397
const hypertrophyExercises = new Set();
398398

399-
blockTemplate.weeks.forEach(week => {
400-
week.days.forEach(day => {
399+
blockTemplate.weeks.forEach((week: any) => {
400+
week.days.forEach((day: any) => {
401401
if (day.exercises) {
402-
day.exercises.forEach(exercise => {
402+
day.exercises.forEach((exercise: string) => {
403403
if (day.type === 'strength') {
404404
strengthExercises.add(exercise);
405405
} else if (day.type === 'hypertrophy') {
@@ -444,14 +444,14 @@ const App = () => {
444444
});
445445

446446
// Unified state update function
447-
const updateState = (updates) => setState(prev => ({ ...prev, ...updates }));
447+
const updateState = (updates: any) => setState((prev: any) => ({ ...prev, ...updates }));
448448

449449
// Consolidated utility functions
450-
const calculateWeight = (exercise, percentage) => {
450+
const calculateWeight = (exercise: string, percentage: number) => {
451451
const exerciseKey = getExerciseKey(exercise);
452-
if (!exerciseKey || !state.maxes[exerciseKey]) return 0;
452+
if (!exerciseKey || !(state.maxes as any)[exerciseKey]) return 0;
453453

454-
const calculatedWeight = state.maxes[exerciseKey] * (percentage / 100);
454+
const calculatedWeight = (state.maxes as any)[exerciseKey] * (percentage / 100);
455455
const barbellExercises = ['Bench Press', 'Squat', 'Deadlift', 'Overhead Press', 'Front Squat', 'Trap Bar Deadlift', 'Power Clean', 'Romanian Deadlift'];
456456

457457
if (barbellExercises.includes(exercise)) {
@@ -461,17 +461,17 @@ const App = () => {
461461
return Math.round(calculatedWeight);
462462
};
463463

464-
const calculateHypertrophyWeight = (exercise, percentage) => {
464+
const calculateHypertrophyWeight = (exercise: string, percentage: number) => {
465465
const exerciseKey = getExerciseKey(exercise);
466466

467467
// Convert 10RM input to estimated 1RM, then apply percentage
468468
let estimatedOneRM;
469-
if (state.tenRMs[exerciseKey]) {
469+
if ((state.tenRMs as any)[exerciseKey]) {
470470
// Convert 10RM to 1RM: 10RM / 0.75 = 1RM
471-
estimatedOneRM = state.tenRMs[exerciseKey] / 0.75;
472-
} else if (state.maxes[exerciseKey]) {
471+
estimatedOneRM = (state.tenRMs as any)[exerciseKey] / 0.75;
472+
} else if ((state.maxes as any)[exerciseKey]) {
473473
// Fallback to actual 1RM if available
474-
estimatedOneRM = state.maxes[exerciseKey];
474+
estimatedOneRM = (state.maxes as any)[exerciseKey];
475475
} else {
476476
return 0;
477477
}
@@ -481,12 +481,12 @@ const App = () => {
481481
return Math.round(calculatedWeight);
482482
};
483483

484-
const calculateWarmupSets = (exercise, workingWeight) => {
484+
const calculateWarmupSets = (_exercise: string, workingWeight: number) => {
485485
if (!workingWeight || workingWeight <= 0) return [];
486486

487487
const barbellWeight = state.weightUnit === 'kg' ? 20 : 45;
488488
const plateIncrement = state.weightUnit === 'kg' ? 2.5 : 5;
489-
const roundToPlate = (weight) => Math.max(Math.round(weight / plateIncrement) * plateIncrement, barbellWeight);
489+
const roundToPlate = (weight: number) => Math.max(Math.round(weight / plateIncrement) * plateIncrement, barbellWeight);
490490

491491
const warmupSets = [
492492
{ weight: roundToPlate(workingWeight * 0.5), reps: 5, type: 'warmup' },
@@ -500,7 +500,7 @@ const App = () => {
500500

501501
const getCurrentWorkout = () => {
502502
const block = state.customPlan[0];
503-
const blockTemplate = blockTemplates[block.type];
503+
const blockTemplate = blockTemplates[block.type as keyof typeof blockTemplates];
504504
if (!blockTemplate) return null;
505505

506506
const weekIndex = Math.min(state.currentWeek - 1, blockTemplate.weeks.length - 1);
@@ -509,7 +509,7 @@ const App = () => {
509509
};
510510

511511
// Consolidated event handlers
512-
const handleDrag = (action, data) => {
512+
const handleDrag = (action: string, data: any) => {
513513
switch(action) {
514514
case 'start':
515515
if (data.index === 0) { data.e.preventDefault(); return; }
@@ -592,17 +592,17 @@ const App = () => {
592592
});
593593
};
594594

595-
const toggleSet = (exerciseIndex, setIndex) => {
595+
const toggleSet = (exerciseIndex: number | string, setIndex: number) => {
596596
const key = `${exerciseIndex}-${setIndex}`;
597597
updateState({
598-
completedSets: { ...state.completedSets, [key]: !state.completedSets[key] }
598+
completedSets: { ...state.completedSets, [key]: !(state.completedSets as any)[key] }
599599
});
600600
};
601601

602-
const manageBlocks = (action, data) => {
602+
const manageBlocks = (action: string, data: any) => {
603603
switch(action) {
604604
case 'add': {
605-
const blockConfig = AVAILABLE_BLOCKS[data.blockType];
605+
const blockConfig = AVAILABLE_BLOCKS[data.blockType as keyof typeof AVAILABLE_BLOCKS];
606606
updateState({
607607
customPlan: [...state.customPlan, {
608608
name: blockConfig.name,
@@ -649,13 +649,13 @@ const App = () => {
649649
};
650650

651651
// Render functions using lookup tables
652-
const renderSimpleWorkout = (type, workout) => {
653-
const config = WORKOUT_CONFIGS[type];
652+
const renderSimpleWorkout = (type: string, workout: any) => {
653+
const config = WORKOUT_CONFIGS[type as keyof typeof WORKOUT_CONFIGS];
654654
return (
655655
<div>
656656
<div className={`bg-gradient-to-r ${config.bg} text-white p-6 rounded-lg text-center`}>
657-
<h3 className="text-2xl font-bold mb-2">{config.title || workout.activity}</h3>
658-
{config.desc && <p className="opacity-90">{config.desc}</p>}
657+
<h3 className="text-2xl font-bold mb-2">{(config as any).title || workout.activity}</h3>
658+
{(config as any).desc && <p className="opacity-90">{(config as any).desc}</p>}
659659
{workout.duration && (
660660
<>
661661
<div className="text-4xl font-bold">{workout.duration}</div>
@@ -670,7 +670,7 @@ const App = () => {
670670
);
671671
};
672672

673-
const renderExerciseSet = (exercise, exerciseIndex, setScheme, schemeIndex, intensity, weight, workout) => {
673+
const renderExerciseSet = (exercise: string, exerciseIndex: number, setScheme: string, schemeIndex: number, intensity: number, weight: number, workout: any) => {
674674
const [sets, reps] = setScheme.split('x');
675675
const warmupSets = workout.type === 'strength' && weight > 0 ? calculateWarmupSets(exercise, weight) : [];
676676

@@ -695,11 +695,11 @@ const App = () => {
695695
<button
696696
onClick={() => toggleSet(`warmup-${exerciseIndex}-${schemeIndex}-${warmupIndex}`, 0)}
697697
className={`w-6 h-6 rounded-full border-2 flex items-center justify-center transition-all ${
698-
state.completedSets[`warmup-${exerciseIndex}-${schemeIndex}-${warmupIndex}-0`]
698+
(state.completedSets as any)[`warmup-${exerciseIndex}-${schemeIndex}-${warmupIndex}-0`]
699699
? 'bg-blue-500 border-blue-500 text-white' : 'border-blue-300 hover:border-blue-400 bg-white'
700700
}`}
701701
>
702-
{state.completedSets[`warmup-${exerciseIndex}-${schemeIndex}-${warmupIndex}-0`] && <CheckCircle className="w-4 h-4" />}
702+
{(state.completedSets as any)[`warmup-${exerciseIndex}-${schemeIndex}-${warmupIndex}-0`] && <CheckCircle className="w-4 h-4" />}
703703
</button>
704704
</div>
705705
))}
@@ -731,11 +731,11 @@ const App = () => {
731731
<button
732732
onClick={() => toggleSet(`${exerciseIndex}-${schemeIndex}`, setIndex)}
733733
className={`w-8 h-8 rounded-full border-2 flex items-center justify-center transition-all ${
734-
state.completedSets[`${exerciseIndex}-${schemeIndex}-${setIndex}`]
734+
(state.completedSets as any)[`${exerciseIndex}-${schemeIndex}-${setIndex}`]
735735
? 'bg-green-500 border-green-500 text-white' : 'border-gray-300 hover:border-green-400 bg-white'
736736
}`}
737737
>
738-
{state.completedSets[`${exerciseIndex}-${schemeIndex}-${setIndex}`] && <CheckCircle className="w-5 h-5" />}
738+
{(state.completedSets as any)[`${exerciseIndex}-${schemeIndex}-${setIndex}`] && <CheckCircle className="w-5 h-5" />}
739739
</button>
740740
</div>
741741
</div>
@@ -756,10 +756,10 @@ const App = () => {
756756
if (workout.type === 'strength' || workout.type === 'hypertrophy') {
757757
return (
758758
<div className="space-y-4">
759-
{workout.exercises.map((exercise, exerciseIndex) => {
760-
const setSchemes = workout.sets.split(',');
759+
{(workout.exercises || []).map((exercise: string, exerciseIndex: number) => {
760+
const setSchemes = (workout.sets || '').split(',');
761761
const intensities = String(workout.intensity).split(',');
762-
const shouldMapByIndex = setSchemes.length === workout.exercises.length;
762+
const shouldMapByIndex = setSchemes.length === (workout.exercises || []).length;
763763
const exerciseSetSchemes = shouldMapByIndex ? [setSchemes[exerciseIndex]] : setSchemes;
764764

765765
return exerciseSetSchemes.map((setScheme, schemeIndex) => {
@@ -858,11 +858,11 @@ const App = () => {
858858
</div>
859859
) : (
860860
<div className="space-y-4">
861-
{state.completedWorkouts.slice(-10).reverse().map((workout, index) => {
862-
const date = new Date(workout.date);
863-
const workoutType = workout.details?.type || 'unknown';
864-
const config = HISTORY_CONFIGS[workoutType] || HISTORY_CONFIGS.rest;
865-
const workoutSummary = config.getSummary ? config.getSummary(workout.details) : config.summary;
861+
{state.completedWorkouts.slice(-10).reverse().map((workout: any, index: number) => {
862+
const date = new Date((workout as any).date);
863+
const workoutType = (workout as any).details?.type || 'unknown';
864+
const config = HISTORY_CONFIGS[workoutType as keyof typeof HISTORY_CONFIGS] || HISTORY_CONFIGS.rest;
865+
const workoutSummary = (config as any).getSummary ? (config as any).getSummary((workout as any).details) : (config as any).summary;
866866

867867
return (
868868
<div key={index} className="border-l-4 border-blue-500 pl-4 pb-3">
@@ -874,12 +874,12 @@ const App = () => {
874874
{config.label}
875875
</span>
876876
</div>
877-
<div className="font-semibold text-gray-900">{workout.blockName || 'Unknown Block'}</div>
878-
<div className="text-sm text-gray-600">Week {workout.week}, Day {workout.day}</div>
877+
<div className="font-semibold text-gray-900">{(workout as any).blockName || 'Unknown Block'}</div>
878+
<div className="text-sm text-gray-600">Week {(workout as any).week}, Day {(workout as any).day}</div>
879879
{workoutSummary && <div className="text-sm text-gray-700 mt-1 font-medium">{workoutSummary}</div>}
880-
{workout.details?.sets && (
880+
{(workout as any).details?.sets && (
881881
<div className="text-xs text-gray-500 mt-1">
882-
Sets: {workout.details.sets}{workout.details.intensity && ` @ ${workout.details.intensity}%`}
882+
Sets: {(workout as any).details.sets}{(workout as any).details.intensity && ` @ ${(workout as any).details.intensity}%`}
883883
</div>
884884
)}
885885
</div>
@@ -983,15 +983,15 @@ const App = () => {
983983
Strength Exercises (1RM - {state.weightUnit})
984984
</h4>
985985
<div className="space-y-3">
986-
{strengthExercises.map((exercise) => {
987-
const exerciseKey = getExerciseKey(exercise);
986+
{(strengthExercises as string[]).map((exercise: string) => {
987+
const exerciseKey = getExerciseKey(exercise as string);
988988

989989
return (
990990
<div key={exerciseKey} className="flex items-center gap-3">
991-
<label className="flex-1 text-sm text-gray-700 font-medium">{exercise}</label>
991+
<label className="flex-1 text-sm text-gray-700 font-medium">{exercise as string}</label>
992992
<input
993993
type="number"
994-
value={state.maxes[exerciseKey] || ''}
994+
value={(state.maxes as any)[exerciseKey] || ''}
995995
onChange={(e) => updateState({
996996
maxes: { ...state.maxes, [exerciseKey]: parseFloat(e.target.value) || 0 }
997997
})}
@@ -1013,15 +1013,15 @@ const App = () => {
10131013
Hypertrophy Exercises (10RM - {state.weightUnit})
10141014
</h4>
10151015
<div className="space-y-3">
1016-
{hypertrophyExercises.map((exercise) => {
1017-
const exerciseKey = getExerciseKey(exercise);
1016+
{(hypertrophyExercises as string[]).map((exercise: string) => {
1017+
const exerciseKey = getExerciseKey(exercise as string);
10181018

10191019
return (
10201020
<div key={exerciseKey} className="flex items-center gap-3">
1021-
<label className="flex-1 text-sm text-gray-700 font-medium">{exercise}</label>
1021+
<label className="flex-1 text-sm text-gray-700 font-medium">{exercise as string}</label>
10221022
<input
10231023
type="number"
1024-
value={state.tenRMs[exerciseKey] || ''}
1024+
value={(state.tenRMs as any)[exerciseKey] || ''}
10251025
onChange={(e) => updateState({
10261026
tenRMs: { ...state.tenRMs, [exerciseKey]: parseFloat(e.target.value) || 0 }
10271027
})}

0 commit comments

Comments
 (0)