Exercise archivation fixed
This commit is contained in:
@@ -72,7 +72,9 @@ const Profile: React.FC<ProfileProps> = ({ user, onLogout, lang, onLanguageChang
|
|||||||
};
|
};
|
||||||
|
|
||||||
const refreshExercises = async () => {
|
const refreshExercises = async () => {
|
||||||
setExercises(await getExercises(user.id));
|
const exercises = await getExercises(user.id);
|
||||||
|
console.log('Refreshed exercises:', exercises);
|
||||||
|
setExercises(exercises);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Snackbar State
|
// Snackbar State
|
||||||
@@ -160,10 +162,12 @@ const Profile: React.FC<ProfileProps> = ({ user, onLogout, lang, onLanguageChang
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Exercise Management Handlers
|
// Exercise Management Handlers
|
||||||
const handleArchiveExercise = (ex: ExerciseDef, archive: boolean) => {
|
const handleArchiveExercise = async (ex: ExerciseDef, archive: boolean) => {
|
||||||
const updated = { ...ex, isArchived: archive };
|
const updated = { ...ex, isArchived: archive };
|
||||||
saveExercise(user.id, updated);
|
console.log('Archiving exercise:', updated);
|
||||||
refreshExercises();
|
await saveExercise(user.id, updated);
|
||||||
|
console.log('Archive complete, refreshing...');
|
||||||
|
await refreshExercises();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSaveExerciseEdit = () => {
|
const handleSaveExerciseEdit = () => {
|
||||||
|
|||||||
@@ -108,14 +108,12 @@ const Tracker: React.FC<TrackerProps> = ({ userId, userWeight, activeSession, ac
|
|||||||
if (step) {
|
if (step) {
|
||||||
const exDef = exercises.find(e => e.id === step.exerciseId);
|
const exDef = exercises.find(e => e.id === step.exerciseId);
|
||||||
if (exDef) {
|
if (exDef) {
|
||||||
if (!selectedExercise || selectedExercise.id !== exDef.id) {
|
|
||||||
setSelectedExercise(exDef);
|
setSelectedExercise(exDef);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}, [currentStepIndex, activePlan, exercises]);
|
||||||
}, [activeSession, activePlan, currentStepIndex, exercises, selectedExercise]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const updateSelection = async () => {
|
const updateSelection = async () => {
|
||||||
|
|||||||
Binary file not shown.
@@ -6,6 +6,7 @@ const router = express.Router();
|
|||||||
const prisma = new PrismaClient();
|
const prisma = new PrismaClient();
|
||||||
const JWT_SECRET = process.env.JWT_SECRET || 'secret';
|
const JWT_SECRET = process.env.JWT_SECRET || 'secret';
|
||||||
|
|
||||||
|
// Middleware to check auth
|
||||||
// Middleware to check auth
|
// Middleware to check auth
|
||||||
const authenticate = (req: any, res: any, next: any) => {
|
const authenticate = (req: any, res: any, next: any) => {
|
||||||
const token = req.headers.authorization?.split(' ')[1];
|
const token = req.headers.authorization?.split(' ')[1];
|
||||||
@@ -31,10 +32,10 @@ router.get('/', async (req: any, res) => {
|
|||||||
OR: [
|
OR: [
|
||||||
{ userId: null }, // System default
|
{ userId: null }, // System default
|
||||||
{ userId } // User custom
|
{ userId } // User custom
|
||||||
],
|
]
|
||||||
isArchived: false
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
console.log('GET /exercises - Returning:', exercises.map(e => ({ id: e.id, name: e.name, isArchived: e.isArchived })));
|
||||||
res.json(exercises);
|
res.json(exercises);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
res.status(500).json({ error: 'Server error' });
|
res.status(500).json({ error: 'Server error' });
|
||||||
@@ -45,7 +46,9 @@ router.get('/', async (req: any, res) => {
|
|||||||
router.post('/', async (req: any, res) => {
|
router.post('/', async (req: any, res) => {
|
||||||
try {
|
try {
|
||||||
const userId = req.user.userId;
|
const userId = req.user.userId;
|
||||||
const { id, name, type, bodyWeightPercentage } = req.body;
|
const { id, name, type, bodyWeightPercentage, isArchived } = req.body;
|
||||||
|
|
||||||
|
console.log('POST /exercises - Received:', { id, name, type, bodyWeightPercentage, isArchived });
|
||||||
|
|
||||||
// If id exists and belongs to user, update. Else create.
|
// If id exists and belongs to user, update. Else create.
|
||||||
// Note: We can't update system exercises directly. If user edits a system exercise,
|
// Note: We can't update system exercises directly. If user edits a system exercise,
|
||||||
@@ -56,10 +59,12 @@ router.post('/', async (req: any, res) => {
|
|||||||
// Check if it exists and belongs to user
|
// Check if it exists and belongs to user
|
||||||
const existing = await prisma.exercise.findUnique({ where: { id } });
|
const existing = await prisma.exercise.findUnique({ where: { id } });
|
||||||
if (existing && existing.userId === userId) {
|
if (existing && existing.userId === userId) {
|
||||||
|
console.log('Updating existing exercise with:', { name, type, bodyWeightPercentage, isArchived });
|
||||||
const updated = await prisma.exercise.update({
|
const updated = await prisma.exercise.update({
|
||||||
where: { id },
|
where: { id },
|
||||||
data: { name, type, bodyWeightPercentage }
|
data: { name, type, bodyWeightPercentage, isArchived }
|
||||||
});
|
});
|
||||||
|
console.log('Updated exercise:', updated);
|
||||||
return res.json(updated);
|
return res.json(updated);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -70,7 +75,8 @@ router.post('/', async (req: any, res) => {
|
|||||||
userId,
|
userId,
|
||||||
name,
|
name,
|
||||||
type,
|
type,
|
||||||
bodyWeightPercentage
|
bodyWeightPercentage,
|
||||||
|
isArchived: isArchived || false
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
res.json(newExercise);
|
res.json(newExercise);
|
||||||
|
|||||||
Reference in New Issue
Block a user