From 1c3e15516c6b5b3461e1df1c5fcef8ea422841cd Mon Sep 17 00:00:00 2001 From: AG Date: Sat, 6 Dec 2025 08:58:44 +0200 Subject: [PATCH] Critical Stability & Performance fixes. Excessive Log Set button gone on QIuck Log screen --- index.html | 4 +-- server/package.json | 12 ++++---- server/prisma/dev.db | Bin 102400 -> 102400 bytes server/src/routes/exercises.ts | 26 ++++++++++++++++ App.tsx => src/App.tsx | 0 {components => src/components}/AICoach.tsx | 0 .../components}/ExerciseModal.tsx | 0 .../components}/FilledInput.tsx | 0 {components => src/components}/History.tsx | 0 {components => src/components}/Login.tsx | 0 {components => src/components}/Navbar.tsx | 0 {components => src/components}/Plans.tsx | 0 {components => src/components}/Profile.tsx | 0 {components => src/components}/Snackbar.tsx | 0 {components => src/components}/Stats.tsx | 0 .../components}/Tracker/ActiveSessionView.tsx | 0 .../components}/Tracker/IdleView.tsx | 0 .../components}/Tracker/SetLogger.tsx | 0 .../components}/Tracker/SporadicView.tsx | 0 .../components}/Tracker/index.tsx | 0 .../components}/Tracker/useTracker.ts | 0 index.css => src/index.css | 0 index.tsx => src/index.tsx | 0 {services => src/services}/api.ts | 0 {services => src/services}/auth.ts | 0 {services => src/services}/geminiService.ts | 0 {services => src/services}/i18n.ts | 0 {services => src/services}/sporadicSets.ts | 0 {services => src/services}/storage.ts | 28 ++++++++---------- {services => src/services}/weight.ts | 0 types.ts => src/types.ts | 0 {utils => src/utils}/text.ts | 0 {utils => src/utils}/uuid.ts | 0 tsconfig.json | 2 +- vite.config.ts | 2 +- 35 files changed, 48 insertions(+), 26 deletions(-) rename App.tsx => src/App.tsx (100%) rename {components => src/components}/AICoach.tsx (100%) rename {components => src/components}/ExerciseModal.tsx (100%) rename {components => src/components}/FilledInput.tsx (100%) rename {components => src/components}/History.tsx (100%) rename {components => src/components}/Login.tsx (100%) rename {components => src/components}/Navbar.tsx (100%) rename {components => src/components}/Plans.tsx (100%) rename {components => src/components}/Profile.tsx (100%) rename {components => src/components}/Snackbar.tsx (100%) rename {components => src/components}/Stats.tsx (100%) rename {components => src/components}/Tracker/ActiveSessionView.tsx (100%) rename {components => src/components}/Tracker/IdleView.tsx (100%) rename {components => src/components}/Tracker/SetLogger.tsx (100%) rename {components => src/components}/Tracker/SporadicView.tsx (100%) rename {components => src/components}/Tracker/index.tsx (100%) rename {components => src/components}/Tracker/useTracker.ts (100%) rename index.css => src/index.css (100%) rename index.tsx => src/index.tsx (100%) rename {services => src/services}/api.ts (100%) rename {services => src/services}/auth.ts (100%) rename {services => src/services}/geminiService.ts (100%) rename {services => src/services}/i18n.ts (100%) rename {services => src/services}/sporadicSets.ts (100%) rename {services => src/services}/storage.ts (80%) rename {services => src/services}/weight.ts (100%) rename types.ts => src/types.ts (100%) rename {utils => src/utils}/text.ts (100%) rename {utils => src/utils}/uuid.ts (100%) diff --git a/index.html b/index.html index c86ea0f..77635af 100644 --- a/index.html +++ b/index.html @@ -93,10 +93,10 @@ } } - +
- + \ No newline at end of file diff --git a/server/package.json b/server/package.json index 2d7f69c..2d6649a 100644 --- a/server/package.json +++ b/server/package.json @@ -13,12 +13,12 @@ "@prisma/adapter-better-sqlite3": "^7.1.0", "@prisma/client": "^6.19.0", "@types/better-sqlite3": "^7.6.13", - "bcryptjs": "*", + "bcryptjs": "3.0.3", "better-sqlite3": "^12.5.0", - "cors": "*", - "dotenv": "*", - "express": "*", - "jsonwebtoken": "*", + "cors": "2.8.5", + "dotenv": "17.2.3", + "express": "5.1.0", + "jsonwebtoken": "9.0.2", "ts-node-dev": "^2.0.0" }, "devDependencies": { @@ -32,4 +32,4 @@ "ts-node": "*", "typescript": "*" } -} +} \ No newline at end of file diff --git a/server/prisma/dev.db b/server/prisma/dev.db index fabb2ae0dfff7dfe62cc0253719b134a8beb7d8d..011faf3874cea9226f0596b300ef8b0ccccb5baa 100644 GIT binary patch delta 974 zcmd6lKZp}S6vk)Rm`$>~Gl>W)i6#dJ-f@|`+1dX=)J6g}qPWPx#kjlKMX(5hXrV$< zT#y67utmHsg^i6D-6GftmWLoBdUfg)RuW0$CTC}}rNz8r-pu>n`+cu7Om~Lqmqkeg z0G$1MV1Lbk;=8-Auje?l2k>*8MSD>p{}ff9acSG;>nkP=4CZMbaTM1hYRgoK#Z-%E zfufnd#&pFD!osW7aJyN6dU(HCiet7p&v3X0@B!{cbofw=D)}_GzQ)-wNj)w)Xy3Sk zPQ+b8JdY#5cpjqB7HstU5e1K=W+1$9qhE;ThqbZWGS>bfp570V^6PpLt5 z)Ab$8l4ZrxDJ62?YDCpNgE$V8iEC+=9C-0}hlR8G>Uoh-rV*JDs^6k|P19-$+f+1l zgVGwM(QL%w3$ZLJ=Hgfqb{9i7q)*~6aUFd?6X}68mC7POmxSH0^6^woc#Ds)AU=sn z6!KSvn+phr)1tB}2gC{DURB4}iR-o)@hLM*zh(Jy;FJ~*lT22OejJh%R|JiaAL;)E zq72SSF&&5lfP<(|*}>c0)1_n6;`^m(Nf;zG?cBefnVY7?jy-$-GeuAG!W7_p=nJ|d zeUq+i}#3P)?#ZfLoA2ZSaP`>iBULzTiY2O%_{lgnMW*MihQU z%T-TOjUNk_;qOY0!#=>D@jmurT(|LHzYQ6$b4toyflI~lVH;k|Lom*C;0*r(TJ!N> delta 389 zcmZozz}B#UZGto}8v_G_Bos4G)G%jc+nBJ#pM!~?lYzg3pL4UI!e740obkWenE2N- z@UP!&u%Luzvx0yj^XB#Wfew7UK&?^?KN$G)`0ns|P3GI6KXKCT%|9-1@Y`^Kq`0pG zHSx#t9_IPRqsh0E?-6ey?;Bou9tJ);eiQENd=q%i@+{#?=LzBy<@Mm5#eajJo2Qz; zZL^@jZ0^n1PwTSqu<(g6@VD}F@%8hG0EK_^iq)}jhlYl7GBQ@e7z_-Y43iVjt4w~o z*NeB386?fY$OsmV-j~N)$pqB^7I_O2VMJC_zdug^n>t^m3~!Iyt>?D^%3 zSw0vDu { } }); +// 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 router.post('/', async (req: any, res) => { try { diff --git a/App.tsx b/src/App.tsx similarity index 100% rename from App.tsx rename to src/App.tsx diff --git a/components/AICoach.tsx b/src/components/AICoach.tsx similarity index 100% rename from components/AICoach.tsx rename to src/components/AICoach.tsx diff --git a/components/ExerciseModal.tsx b/src/components/ExerciseModal.tsx similarity index 100% rename from components/ExerciseModal.tsx rename to src/components/ExerciseModal.tsx diff --git a/components/FilledInput.tsx b/src/components/FilledInput.tsx similarity index 100% rename from components/FilledInput.tsx rename to src/components/FilledInput.tsx diff --git a/components/History.tsx b/src/components/History.tsx similarity index 100% rename from components/History.tsx rename to src/components/History.tsx diff --git a/components/Login.tsx b/src/components/Login.tsx similarity index 100% rename from components/Login.tsx rename to src/components/Login.tsx diff --git a/components/Navbar.tsx b/src/components/Navbar.tsx similarity index 100% rename from components/Navbar.tsx rename to src/components/Navbar.tsx diff --git a/components/Plans.tsx b/src/components/Plans.tsx similarity index 100% rename from components/Plans.tsx rename to src/components/Plans.tsx diff --git a/components/Profile.tsx b/src/components/Profile.tsx similarity index 100% rename from components/Profile.tsx rename to src/components/Profile.tsx diff --git a/components/Snackbar.tsx b/src/components/Snackbar.tsx similarity index 100% rename from components/Snackbar.tsx rename to src/components/Snackbar.tsx diff --git a/components/Stats.tsx b/src/components/Stats.tsx similarity index 100% rename from components/Stats.tsx rename to src/components/Stats.tsx diff --git a/components/Tracker/ActiveSessionView.tsx b/src/components/Tracker/ActiveSessionView.tsx similarity index 100% rename from components/Tracker/ActiveSessionView.tsx rename to src/components/Tracker/ActiveSessionView.tsx diff --git a/components/Tracker/IdleView.tsx b/src/components/Tracker/IdleView.tsx similarity index 100% rename from components/Tracker/IdleView.tsx rename to src/components/Tracker/IdleView.tsx diff --git a/components/Tracker/SetLogger.tsx b/src/components/Tracker/SetLogger.tsx similarity index 100% rename from components/Tracker/SetLogger.tsx rename to src/components/Tracker/SetLogger.tsx diff --git a/components/Tracker/SporadicView.tsx b/src/components/Tracker/SporadicView.tsx similarity index 100% rename from components/Tracker/SporadicView.tsx rename to src/components/Tracker/SporadicView.tsx diff --git a/components/Tracker/index.tsx b/src/components/Tracker/index.tsx similarity index 100% rename from components/Tracker/index.tsx rename to src/components/Tracker/index.tsx diff --git a/components/Tracker/useTracker.ts b/src/components/Tracker/useTracker.ts similarity index 100% rename from components/Tracker/useTracker.ts rename to src/components/Tracker/useTracker.ts diff --git a/index.css b/src/index.css similarity index 100% rename from index.css rename to src/index.css diff --git a/index.tsx b/src/index.tsx similarity index 100% rename from index.tsx rename to src/index.tsx diff --git a/services/api.ts b/src/services/api.ts similarity index 100% rename from services/api.ts rename to src/services/api.ts diff --git a/services/auth.ts b/src/services/auth.ts similarity index 100% rename from services/auth.ts rename to src/services/auth.ts diff --git a/services/geminiService.ts b/src/services/geminiService.ts similarity index 100% rename from services/geminiService.ts rename to src/services/geminiService.ts diff --git a/services/i18n.ts b/src/services/i18n.ts similarity index 100% rename from services/i18n.ts rename to src/services/i18n.ts diff --git a/services/sporadicSets.ts b/src/services/sporadicSets.ts similarity index 100% rename from services/sporadicSets.ts rename to src/services/sporadicSets.ts diff --git a/services/storage.ts b/src/services/storage.ts similarity index 80% rename from services/storage.ts rename to src/services/storage.ts index 2b00de6..3d51e4b 100644 --- a/services/storage.ts +++ b/src/services/storage.ts @@ -52,12 +52,12 @@ export const updateActiveSession = async (userId: string, session: WorkoutSessio }; export const deleteSetFromActiveSession = async (userId: string, setId: string): Promise => { - await api.delete(`/sessions/active/set/${setId}`); + await api.delete(`/sessions/active/set/${setId}`); }; export const updateSetInActiveSession = async (userId: string, setId: string, setData: Partial): Promise => { - const response = await api.put(`/sessions/active/set/${setId}`, setData); - return response.updatedSet; + const response = await api.put(`/sessions/active/set/${setId}`, setData); + return response.updatedSet; }; export const deleteActiveSession = async (userId: string): Promise => { @@ -85,21 +85,17 @@ export const saveExercise = async (userId: string, exercise: ExerciseDef): Promi }; export const getLastSetForExercise = async (userId: string, exerciseId: string): Promise => { - // This requires fetching sessions or a specific endpoint. - // For performance, we should probably have an endpoint for this. - // For now, let's fetch sessions and find it client side, or implement endpoint later. - // Given the async nature, we need to change the signature to Promise. - // 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]; - } + try { + const response = await api.get(`/exercises/${exerciseId}/last-set`); + if (response.success && response.set) { + return response.set; } + return undefined; + } catch (error) { + console.error("Failed to fetch last set:", error); + return undefined; } - return undefined; -} +}; export const getPlans = async (userId: string): Promise => { try { diff --git a/services/weight.ts b/src/services/weight.ts similarity index 100% rename from services/weight.ts rename to src/services/weight.ts diff --git a/types.ts b/src/types.ts similarity index 100% rename from types.ts rename to src/types.ts diff --git a/utils/text.ts b/src/utils/text.ts similarity index 100% rename from utils/text.ts rename to src/utils/text.ts diff --git a/utils/uuid.ts b/src/utils/uuid.ts similarity index 100% rename from utils/uuid.ts rename to src/utils/uuid.ts diff --git a/tsconfig.json b/tsconfig.json index 2c6eed5..d8a27ae 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -20,7 +20,7 @@ "jsx": "react-jsx", "paths": { "@/*": [ - "./*" + "./src/*" ] }, "allowImportingTsExtensions": true, diff --git a/vite.config.ts b/vite.config.ts index 1d59b1e..dd8eba8 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -23,7 +23,7 @@ export default defineConfig(({ mode }) => { }, resolve: { alias: { - '@': path.resolve(__dirname, '.'), + '@': path.resolve(__dirname, './src'), } } };