History added to Quick Log. Some minor fixes.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import React from 'react';
|
||||
import { Dumbbell, Scale, Activity, Timer as TimerIcon, ArrowRight, ArrowUp, Plus, CheckCircle } from 'lucide-react';
|
||||
import { ExerciseType, Language } from '../../types';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Dumbbell, Scale, Activity, Timer as TimerIcon, ArrowRight, ArrowUp, Plus, CheckCircle, Edit, Trash2 } from 'lucide-react';
|
||||
import { ExerciseType, Language, SporadicSet } from '../../types';
|
||||
import { t } from '../../services/i18n';
|
||||
import FilledInput from '../FilledInput';
|
||||
import ExerciseModal from '../ExerciseModal';
|
||||
@@ -9,9 +9,10 @@ import { useTracker } from './useTracker';
|
||||
interface SporadicViewProps {
|
||||
tracker: ReturnType<typeof useTracker>;
|
||||
lang: Language;
|
||||
sporadicSets?: SporadicSet[];
|
||||
}
|
||||
|
||||
const SporadicView: React.FC<SporadicViewProps> = ({ tracker, lang }) => {
|
||||
const SporadicView: React.FC<SporadicViewProps> = ({ tracker, lang, sporadicSets }) => {
|
||||
const {
|
||||
searchQuery,
|
||||
setSearchQuery,
|
||||
@@ -40,6 +41,27 @@ const SporadicView: React.FC<SporadicViewProps> = ({ tracker, lang }) => {
|
||||
resetForm
|
||||
} = tracker;
|
||||
|
||||
const [todaysSets, setTodaysSets] = useState<SporadicSet[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
if (sporadicSets) {
|
||||
const startOfDay = new Date();
|
||||
startOfDay.setHours(0, 0, 0, 0);
|
||||
const todayS = sporadicSets.filter(s => s.timestamp >= startOfDay.getTime());
|
||||
setTodaysSets(todayS.sort((a, b) => b.timestamp - a.timestamp));
|
||||
}
|
||||
}, [sporadicSets]);
|
||||
|
||||
const renderSetMetrics = (set: SporadicSet) => {
|
||||
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 (
|
||||
<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">
|
||||
@@ -50,7 +72,7 @@ const SporadicView: React.FC<SporadicViewProps> = ({ tracker, lang }) => {
|
||||
}}
|
||||
className="text-error font-medium text-sm hover:opacity-80 transition-opacity"
|
||||
>
|
||||
{t('cancel', lang)}
|
||||
{t('quit', lang)}
|
||||
</button>
|
||||
<div className="flex flex-col items-center">
|
||||
<h2 className="text-title-medium text-on-surface flex items-center gap-2 font-medium">
|
||||
@@ -102,7 +124,7 @@ const SporadicView: React.FC<SporadicViewProps> = ({ tracker, lang }) => {
|
||||
<button
|
||||
key={ex.id}
|
||||
onMouseDown={(e) => {
|
||||
e.preventDefault(); // Prevent input blur
|
||||
e.preventDefault();
|
||||
setSelectedExercise(ex);
|
||||
setSearchQuery(ex.name);
|
||||
setShowSuggestions(false);
|
||||
@@ -178,6 +200,26 @@ const SporadicView: React.FC<SporadicViewProps> = ({ tracker, lang }) => {
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* History Section */}
|
||||
{todaysSets.length > 0 && (
|
||||
<div className="mt-6">
|
||||
<h3 className="text-title-medium font-medium mb-3">{t('history_section', lang)}</h3>
|
||||
<div className="space-y-2">
|
||||
{todaysSets.map(set => (
|
||||
<div key={set.id} className="bg-surface-container rounded-lg p-3 flex items-center justify-between shadow-elevation-1 animate-in fade-in">
|
||||
<div>
|
||||
<p className="font-medium text-on-surface">{set.exerciseName}</p>
|
||||
<p className="text-sm text-on-surface-variant">{renderSetMetrics(set)}</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
{/* Edit and Delete buttons can be added here in the future */}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{isCreating && (
|
||||
|
||||
Reference in New Issue
Block a user