feat: last-session recall when starting an exercise
When you start an exercise, the Mini App now fetches the most
recent time you logged it and shows a hint line in the sets card
("Last time: 8×60, 6×60, 5×60 · 3 days ago"), plus pre-fills the
weight input with the last set's weight.
- db.get_last_exercise(user_id, name): most recent non-deleted
entry, case-insensitive name match, sets_detail parsed.
- GET /api/exercises/last?name=<name>.
- webapp: loadLastSession() on startExercise + draft restore;
hint cleared on editExercise (the set rows are the reference
there). Pre-fill only when the weight field is empty and no
sets logged yet, so it never clobbers user input.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
5e3636201f
commit
9f146d60fa
6 changed files with 168 additions and 1 deletions
13
server.py
13
server.py
|
|
@ -17,7 +17,7 @@ from urllib.parse import parse_qs
|
|||
|
||||
from aiohttp import web
|
||||
|
||||
from db import init_db, save_workout, get_workouts, get_workout_count, get_stats_sql, delete_workout, update_workout, export_workouts, get_user_workout_number, get_all_exercise_names, log_event, get_settings, update_settings
|
||||
from db import init_db, save_workout, get_workouts, get_workout_count, get_stats_sql, delete_workout, update_workout, export_workouts, get_user_workout_number, get_all_exercise_names, log_event, get_settings, update_settings, get_last_exercise
|
||||
from parser import parse_workout, format_workout
|
||||
|
||||
logging.basicConfig(
|
||||
|
|
@ -283,6 +283,16 @@ async def api_get_exercise_names(request: web.Request):
|
|||
return web.json_response({"exercises": get_all_exercise_names()})
|
||||
|
||||
|
||||
@require_auth
|
||||
async def api_get_last_exercise(request: web.Request):
|
||||
"""Return the user's most recent logged entry for a given exercise name."""
|
||||
name = request.query.get("name", "").strip()
|
||||
if not name:
|
||||
return web.json_response({"error": "Missing name"}, status=400)
|
||||
last = get_last_exercise(request["user_id"], name)
|
||||
return web.json_response({"last": last})
|
||||
|
||||
|
||||
@require_auth
|
||||
async def api_get_stats(request: web.Request):
|
||||
"""Return summary stats for the user."""
|
||||
|
|
@ -366,6 +376,7 @@ def create_app() -> web.Application:
|
|||
app.router.add_put("/api/workouts/{workout_id}", api_update_workout)
|
||||
app.router.add_delete("/api/workouts/{workout_id}", api_delete_workout)
|
||||
app.router.add_get("/api/exercises", api_get_exercise_names)
|
||||
app.router.add_get("/api/exercises/last", api_get_last_exercise)
|
||||
app.router.add_get("/api/stats", api_get_stats)
|
||||
app.router.add_get("/api/export/json", api_export_json)
|
||||
app.router.add_get("/api/export/csv", api_export_csv)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue