New exercise creation added to Quick Log. History fixed.

This commit is contained in:
AG
2025-11-29 19:29:35 +02:00
parent b5c8e8ac43
commit 4f363730d5
5 changed files with 116 additions and 66 deletions

View File

@@ -112,7 +112,7 @@ const History: React.FC<HistoryProps> = ({ sessions, sporadicSets, onUpdateSessi
} }
}; };
if (sessions.length === 0) { if (sessions.length === 0 && (!sporadicSets || sporadicSets.length === 0)) {
return ( return (
<div className="flex flex-col items-center justify-center h-full text-on-surface-variant p-8 text-center"> <div className="flex flex-col items-center justify-center h-full text-on-surface-variant p-8 text-center">
<Clock size={48} className="mb-4 opacity-50" /> <Clock size={48} className="mb-4 opacity-50" />
@@ -197,7 +197,6 @@ const History: React.FC<HistoryProps> = ({ sessions, sporadicSets, onUpdateSessi
</div> </div>
) )
})} })}
</div>
{/* Sporadic Sets Section */} {/* Sporadic Sets Section */}
{sporadicSets && sporadicSets.length > 0 && ( {sporadicSets && sporadicSets.length > 0 && (
@@ -216,7 +215,7 @@ const History: React.FC<HistoryProps> = ({ sessions, sporadicSets, onUpdateSessi
<div key={date} className="mb-4"> <div key={date} className="mb-4">
<div className="text-sm text-on-surface-variant px-2 mb-2 font-medium">{date}</div> <div className="text-sm text-on-surface-variant px-2 mb-2 font-medium">{date}</div>
<div className="space-y-2"> <div className="space-y-2">
{sets.map(set => ( {(sets as SporadicSet[]).map(set => (
<div <div
key={set.id} key={set.id}
className="bg-surface-container-low rounded-xl p-4 border border-outline-variant/10 flex justify-between items-center" className="bg-surface-container-low rounded-xl p-4 border border-outline-variant/10 flex justify-between items-center"
@@ -257,6 +256,7 @@ const History: React.FC<HistoryProps> = ({ sessions, sporadicSets, onUpdateSessi
))} ))}
</div> </div>
)} )}
</div>
{/* DELETE CONFIRMATION DIALOG (MD3) */} {/* DELETE CONFIRMATION DIALOG (MD3) */}
{deletingId && ( {deletingId && (

View File

@@ -204,7 +204,8 @@ const ActiveSessionView: React.FC<ActiveSessionViewProps> = ({ tracker, activeSe
filteredExercises.map(ex => ( filteredExercises.map(ex => (
<button <button
key={ex.id} key={ex.id}
onClick={() => { onMouseDown={(e) => {
e.preventDefault(); // Prevent input blur
setSelectedExercise(ex); setSelectedExercise(ex);
setSearchQuery(ex.name); setSearchQuery(ex.name);
setShowSuggestions(false); setShowSuggestions(false);

View File

@@ -3,6 +3,7 @@ import { Dumbbell, Scale, Activity, Timer as TimerIcon, ArrowRight, ArrowUp, Plu
import { ExerciseType, Language } from '../../types'; import { ExerciseType, Language } from '../../types';
import { t } from '../../services/i18n'; import { t } from '../../services/i18n';
import FilledInput from '../FilledInput'; import FilledInput from '../FilledInput';
import ExerciseModal from '../ExerciseModal';
import { useTracker } from './useTracker'; import { useTracker } from './useTracker';
interface SporadicViewProps { interface SporadicViewProps {
@@ -31,23 +32,41 @@ const SporadicView: React.FC<SporadicViewProps> = ({ tracker, lang }) => {
setHeight, setHeight,
handleLogSporadicSet, handleLogSporadicSet,
sporadicSuccess, sporadicSuccess,
setIsSporadicMode setIsSporadicMode,
isCreating,
setIsCreating,
handleCreateExercise,
exercises,
resetForm
} = tracker; } = tracker;
return ( return (
<div className="flex flex-col h-full max-h-full overflow-hidden relative bg-surface"> <div className="flex flex-col h-full max-h-full overflow-hidden relative bg-surface">
<div className="px-4 py-3 bg-surface-container shadow-elevation-1 z-20 flex justify-between items-center"> <div className="px-4 py-3 bg-surface-container shadow-elevation-1 z-20 flex justify-between items-center">
<div className="flex flex-col"> <button
onClick={() => {
resetForm();
setIsSporadicMode(false);
}}
className="text-error font-medium text-sm hover:opacity-80 transition-opacity"
>
{t('cancel', lang)}
</button>
<div className="flex flex-col items-center">
<h2 className="text-title-medium text-on-surface flex items-center gap-2 font-medium"> <h2 className="text-title-medium text-on-surface flex items-center gap-2 font-medium">
<span className="w-2 h-2 rounded-full bg-primary animate-pulse" /> <span className="w-2 h-2 rounded-full bg-primary animate-pulse" />
{t('quick_log', lang)} {t('quick_log', lang)}
</h2> </h2>
</div> </div>
<button <button
onClick={() => setIsSporadicMode(false)} onClick={handleLogSporadicSet}
className="px-5 py-2 rounded-full bg-primary-container text-on-primary-container text-sm font-medium hover:opacity-90 transition-opacity" className={`px-5 py-2 rounded-full text-sm font-medium transition-all ${selectedExercise
? 'bg-primary-container text-on-primary-container hover:opacity-90 shadow-elevation-1'
: 'bg-surface-container-high text-on-surface-variant opacity-50 cursor-not-allowed'
}`}
disabled={!selectedExercise}
> >
{t('done', lang)} {t('log_set', lang)}
</button> </button>
</div> </div>
@@ -67,13 +86,20 @@ const SporadicView: React.FC<SporadicViewProps> = ({ tracker, lang }) => {
autoComplete="off" autoComplete="off"
type="text" type="text"
/> />
<button
onClick={() => setIsCreating(true)}
className="absolute right-2 top-1/2 -translate-y-1/2 p-2 text-primary hover:bg-primary-container/20 rounded-full z-10"
>
<Plus size={24} />
</button>
{showSuggestions && ( {showSuggestions && (
<div className="absolute top-full left-0 w-full bg-surface-container rounded-xl shadow-elevation-3 overflow-hidden z-20 mt-1 max-h-60 overflow-y-auto animate-in fade-in slide-in-from-top-2"> <div className="absolute top-full left-0 w-full bg-surface-container rounded-xl shadow-elevation-3 overflow-hidden z-20 mt-1 max-h-60 overflow-y-auto animate-in fade-in slide-in-from-top-2">
{filteredExercises.length > 0 ? ( {filteredExercises.length > 0 ? (
filteredExercises.map(ex => ( filteredExercises.map(ex => (
<button <button
key={ex.id} key={ex.id}
onClick={() => { onMouseDown={(e) => {
e.preventDefault(); // Prevent input blur
setSelectedExercise(ex); setSelectedExercise(ex);
setSearchQuery(ex.name); setSearchQuery(ex.name);
setShowSuggestions(false); setShowSuggestions(false);
@@ -150,6 +176,16 @@ const SporadicView: React.FC<SporadicViewProps> = ({ tracker, lang }) => {
</div> </div>
)} )}
</div> </div>
{isCreating && (
<ExerciseModal
isOpen={isCreating}
onClose={() => setIsCreating(false)}
onSave={handleCreateExercise}
lang={lang}
existingExercises={exercises}
/>
)}
</div> </div>
); );
}; };

View File

@@ -308,7 +308,7 @@ export const useTracker = ({
} }
try { try {
const result = await logSporadicSet(userId, set); const result = await logSporadicSet(set);
if (result) { if (result) {
setSporadicSuccess(true); setSporadicSuccess(true);
setTimeout(() => setSporadicSuccess(false), 2000); setTimeout(() => setSporadicSuccess(false), 2000);
@@ -329,6 +329,7 @@ export const useTracker = ({
await saveExercise(userId, newEx); await saveExercise(userId, newEx);
setExercises(prev => [...prev, newEx].sort((a, b) => a.name.localeCompare(b.name))); setExercises(prev => [...prev, newEx].sort((a, b) => a.name.localeCompare(b.name)));
setSelectedExercise(newEx); setSelectedExercise(newEx);
setSearchQuery(newEx.name);
setIsCreating(false); setIsCreating(false);
}; };
@@ -364,6 +365,17 @@ export const useTracker = ({
setShowPlanList(false); setShowPlanList(false);
}; };
const resetForm = () => {
setWeight('');
setReps('');
setDuration('');
setDistance('');
setHeight('');
setSelectedExercise(null);
setSearchQuery('');
setSporadicSuccess(false);
};
return { return {
exercises, exercises,
plans, plans,
@@ -426,5 +438,6 @@ export const useTracker = ({
handleSaveEdit, handleSaveEdit,
handleCancelEdit, handleCancelEdit,
jumpToStep, jumpToStep,
resetForm,
}; };
}; };

Binary file not shown.