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 fabb2ae..011faf3 100644 Binary files a/server/prisma/dev.db and b/server/prisma/dev.db differ diff --git a/server/src/routes/exercises.ts b/server/src/routes/exercises.ts index b64cd42..c697122 100644 --- a/server/src/routes/exercises.ts +++ b/server/src/routes/exercises.ts @@ -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 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'), } } };