Critical Stability & Performance fixes. Excessive Log Set button gone on QIuck Log screen

This commit is contained in:
AG
2025-12-06 08:58:44 +02:00
parent 27afacee3f
commit 1c3e15516c
35 changed files with 48 additions and 26 deletions

View File

@@ -93,10 +93,10 @@
} }
} }
</script> </script>
<link rel="stylesheet" href="/index.css"> <link rel="stylesheet" href="/src/index.css">
</head> </head>
<body class="bg-surface text-on-surface h-screen overflow-hidden selection:bg-primary-container selection:text-on-primary-container"> <body class="bg-surface text-on-surface h-screen overflow-hidden selection:bg-primary-container selection:text-on-primary-container">
<div id="root"></div> <div id="root"></div>
<script type="module" src="/index.tsx"></script> <script type="module" src="/src/index.tsx"></script>
</body> </body>
</html> </html>

View File

@@ -13,12 +13,12 @@
"@prisma/adapter-better-sqlite3": "^7.1.0", "@prisma/adapter-better-sqlite3": "^7.1.0",
"@prisma/client": "^6.19.0", "@prisma/client": "^6.19.0",
"@types/better-sqlite3": "^7.6.13", "@types/better-sqlite3": "^7.6.13",
"bcryptjs": "*", "bcryptjs": "3.0.3",
"better-sqlite3": "^12.5.0", "better-sqlite3": "^12.5.0",
"cors": "*", "cors": "2.8.5",
"dotenv": "*", "dotenv": "17.2.3",
"express": "*", "express": "5.1.0",
"jsonwebtoken": "*", "jsonwebtoken": "9.0.2",
"ts-node-dev": "^2.0.0" "ts-node-dev": "^2.0.0"
}, },
"devDependencies": { "devDependencies": {

Binary file not shown.

View File

@@ -41,6 +41,32 @@ router.get('/', async (req: any, res) => {
} }
}); });
// Get last set for specific exercise
router.get('/:id/last-set', async (req: any, res) => {
try {
const userId = req.user.userId;
const exerciseId = req.params.id;
const lastSet = await prisma.workoutSet.findFirst({
where: {
exerciseId,
session: { userId } // Ensure optimization by filtering sessions of the user
},
include: {
session: true
},
orderBy: {
timestamp: 'desc'
}
});
res.json({ success: true, set: lastSet });
} catch (error) {
console.error(error);
res.status(500).json({ error: 'Server error' });
}
});
// Create/Update exercise // Create/Update exercise
router.post('/', async (req: any, res) => { router.post('/', async (req: any, res) => {
try { try {

View File

@@ -52,12 +52,12 @@ export const updateActiveSession = async (userId: string, session: WorkoutSessio
}; };
export const deleteSetFromActiveSession = async (userId: string, setId: string): Promise<void> => { export const deleteSetFromActiveSession = async (userId: string, setId: string): Promise<void> => {
await api.delete(`/sessions/active/set/${setId}`); await api.delete(`/sessions/active/set/${setId}`);
}; };
export const updateSetInActiveSession = async (userId: string, setId: string, setData: Partial<WorkoutSet>): Promise<WorkoutSet> => { export const updateSetInActiveSession = async (userId: string, setId: string, setData: Partial<WorkoutSet>): Promise<WorkoutSet> => {
const response = await api.put(`/sessions/active/set/${setId}`, setData); const response = await api.put(`/sessions/active/set/${setId}`, setData);
return response.updatedSet; return response.updatedSet;
}; };
export const deleteActiveSession = async (userId: string): Promise<void> => { export const deleteActiveSession = async (userId: string): Promise<void> => {
@@ -85,21 +85,17 @@ export const saveExercise = async (userId: string, exercise: ExerciseDef): Promi
}; };
export const getLastSetForExercise = async (userId: string, exerciseId: string): Promise<WorkoutSet | undefined> => { export const getLastSetForExercise = async (userId: string, exerciseId: string): Promise<WorkoutSet | undefined> => {
// This requires fetching sessions or a specific endpoint. try {
// For performance, we should probably have an endpoint for this. const response = await api.get(`/exercises/${exerciseId}/last-set`);
// For now, let's fetch sessions and find it client side, or implement endpoint later. if (response.success && response.set) {
// Given the async nature, we need to change the signature to Promise. return response.set;
// The caller needs to await this.
const sessions = await getSessions(userId);
for (const session of sessions) {
for (let i = session.sets.length - 1; i >= 0; i--) {
if (session.sets[i].exerciseId === exerciseId) {
return session.sets[i];
}
} }
return undefined;
} catch (error) {
console.error("Failed to fetch last set:", error);
return undefined;
} }
return undefined; };
}
export const getPlans = async (userId: string): Promise<WorkoutPlan[]> => { export const getPlans = async (userId: string): Promise<WorkoutPlan[]> => {
try { try {

View File

@@ -20,7 +20,7 @@
"jsx": "react-jsx", "jsx": "react-jsx",
"paths": { "paths": {
"@/*": [ "@/*": [
"./*" "./src/*"
] ]
}, },
"allowImportingTsExtensions": true, "allowImportingTsExtensions": true,

View File

@@ -23,7 +23,7 @@ export default defineConfig(({ mode }) => {
}, },
resolve: { resolve: {
alias: { alias: {
'@': path.resolve(__dirname, '.'), '@': path.resolve(__dirname, './src'),
} }
} }
}; };