Sporadic set logging added
This commit is contained in:
34
App.tsx
34
App.tsx
@@ -1,15 +1,16 @@
|
||||
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import Navbar from './components/Navbar';
|
||||
import Tracker from './components/Tracker';
|
||||
import Tracker from './components/Tracker/index';
|
||||
import History from './components/History';
|
||||
import Stats from './components/Stats';
|
||||
import AICoach from './components/AICoach';
|
||||
import Plans from './components/Plans';
|
||||
import Login from './components/Login';
|
||||
import Profile from './components/Profile';
|
||||
import { TabView, WorkoutSession, WorkoutSet, WorkoutPlan, User, Language } from './types';
|
||||
import { TabView, WorkoutSession, WorkoutSet, WorkoutPlan, User, Language, SporadicSet } from './types';
|
||||
import { getSessions, saveSession, deleteSession, getPlans, getActiveSession, updateActiveSession, deleteActiveSession, updateSetInActiveSession, deleteSetFromActiveSession } from './services/storage';
|
||||
import { getSporadicSets, updateSporadicSet, deleteSporadicSet } from './services/sporadicSets';
|
||||
import { getCurrentUserProfile, getMe } from './services/auth';
|
||||
import { getSystemLanguage } from './services/i18n';
|
||||
import { logWeight } from './services/weight';
|
||||
@@ -24,6 +25,7 @@ function App() {
|
||||
const [plans, setPlans] = useState<WorkoutPlan[]>([]);
|
||||
const [activeSession, setActiveSession] = useState<WorkoutSession | null>(null);
|
||||
const [activePlan, setActivePlan] = useState<WorkoutPlan | null>(null);
|
||||
const [sporadicSets, setSporadicSets] = useState<SporadicSet[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
// Set initial language
|
||||
@@ -66,9 +68,13 @@ function App() {
|
||||
// Load plans
|
||||
const p = await getPlans(currentUser.id);
|
||||
setPlans(p);
|
||||
// Load sporadic sets
|
||||
const sporadicSets = await getSporadicSets();
|
||||
setSporadicSets(sporadicSets);
|
||||
} else {
|
||||
setSessions([]);
|
||||
setPlans([]);
|
||||
setSporadicSets([]);
|
||||
}
|
||||
};
|
||||
loadSessions();
|
||||
@@ -80,6 +86,7 @@ function App() {
|
||||
};
|
||||
|
||||
const handleLogout = () => {
|
||||
localStorage.removeItem('token');
|
||||
setCurrentUser(null);
|
||||
setActiveSession(null);
|
||||
setActivePlan(null);
|
||||
@@ -190,6 +197,25 @@ function App() {
|
||||
setSessions(prev => prev.filter(s => s.id !== sessionId));
|
||||
};
|
||||
|
||||
const handleSporadicSetAdded = async () => {
|
||||
const sets = await getSporadicSets();
|
||||
setSporadicSets(sets);
|
||||
};
|
||||
|
||||
const handleUpdateSporadicSet = async (set: SporadicSet) => {
|
||||
const updated = await updateSporadicSet(set.id, set);
|
||||
if (updated) {
|
||||
setSporadicSets(prev => prev.map(s => s.id === set.id ? updated : s));
|
||||
}
|
||||
};
|
||||
|
||||
const handleDeleteSporadicSet = async (id: string) => {
|
||||
const success = await deleteSporadicSet(id);
|
||||
if (success) {
|
||||
setSporadicSets(prev => prev.filter(s => s.id !== id));
|
||||
}
|
||||
};
|
||||
|
||||
if (!currentUser) {
|
||||
return <Login onLogin={handleLogin} language={language} onLanguageChange={handleLanguageChange} />;
|
||||
}
|
||||
@@ -215,6 +241,7 @@ function App() {
|
||||
onSetAdded={handleAddSet}
|
||||
onRemoveSet={handleRemoveSetFromActive}
|
||||
onUpdateSet={handleUpdateSetInActive}
|
||||
onSporadicSetAdded={handleSporadicSetAdded}
|
||||
lang={language}
|
||||
/>
|
||||
)}
|
||||
@@ -224,8 +251,11 @@ function App() {
|
||||
{currentTab === 'HISTORY' && (
|
||||
<History
|
||||
sessions={sessions}
|
||||
sporadicSets={sporadicSets}
|
||||
onUpdateSession={handleUpdateSession}
|
||||
onDeleteSession={handleDeleteSession}
|
||||
onUpdateSporadicSet={handleUpdateSporadicSet}
|
||||
onDeleteSporadicSet={handleDeleteSporadicSet}
|
||||
lang={language}
|
||||
/>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user