Select Newly created exercise automatically
This commit is contained in:
@@ -69,6 +69,7 @@ const Tracker: React.FC<TrackerProps> = ({ userId, userWeight, activeSession, ac
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadData = async () => {
|
const loadData = async () => {
|
||||||
const exList = await getExercises(userId);
|
const exList = await getExercises(userId);
|
||||||
|
exList.sort((a, b) => a.name.localeCompare(b.name));
|
||||||
setExercises(exList);
|
setExercises(exList);
|
||||||
const planList = await getPlans(userId);
|
const planList = await getPlans(userId);
|
||||||
setPlans(planList);
|
setPlans(planList);
|
||||||
@@ -253,8 +254,7 @@ const Tracker: React.FC<TrackerProps> = ({ userId, userWeight, activeSession, ac
|
|||||||
|
|
||||||
const handleCreateExercise = async (newEx: ExerciseDef) => {
|
const handleCreateExercise = async (newEx: ExerciseDef) => {
|
||||||
await saveExercise(userId, newEx);
|
await saveExercise(userId, newEx);
|
||||||
const exList = await getExercises(userId);
|
setExercises(prev => [...prev, newEx].sort((a, b) => a.name.localeCompare(b.name)));
|
||||||
setExercises(exList.filter(e => !e.isArchived));
|
|
||||||
setSelectedExercise(newEx);
|
setSelectedExercise(newEx);
|
||||||
setIsCreating(false);
|
setIsCreating(false);
|
||||||
};
|
};
|
||||||
@@ -493,8 +493,6 @@ const Tracker: React.FC<TrackerProps> = ({ userId, userWeight, activeSession, ac
|
|||||||
>
|
>
|
||||||
<option value="" disabled>{t('select_exercise', lang)}</option>
|
<option value="" disabled>{t('select_exercise', lang)}</option>
|
||||||
{exercises
|
{exercises
|
||||||
.slice()
|
|
||||||
.sort((a, b) => a.name.localeCompare(b.name))
|
|
||||||
.map(ex => (
|
.map(ex => (
|
||||||
<option key={ex.id} value={ex.id} className="bg-surface-container text-on-surface">{ex.name}</option>
|
<option key={ex.id} value={ex.id} className="bg-surface-container text-on-surface">{ex.name}</option>
|
||||||
))}
|
))}
|
||||||
@@ -710,6 +708,7 @@ const Tracker: React.FC<TrackerProps> = ({ userId, userWeight, activeSession, ac
|
|||||||
onClose={() => setIsCreating(false)}
|
onClose={() => setIsCreating(false)}
|
||||||
onSave={handleCreateExercise}
|
onSave={handleCreateExercise}
|
||||||
lang={lang}
|
lang={lang}
|
||||||
|
existingExercises={exercises}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user