StreakFit web: exercices planifiés en séance + filtre matériel + config matos profil
Build & Deploy / build (push) Successful in 23s
Build & Deploy / build (push) Successful in 23s
- session/[id]: affiche les exercices planifies de la routine (objectif series x reps) + pre-remplit la 1re serie - exercises/index: select Materiel + bouton 'Mon matos' (filtre sur le materiel du profil) - profile: multi-select du materiel possede + PATCH /api/me - i18n fr/en/pt-BR Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -8,7 +8,10 @@ const sessionId = Number(route.params.id)
|
||||
|
||||
interface SetLog { id: number, exercise_id: number, set_number: number, reps: number | null, weight: number | null }
|
||||
interface Exercise { id: number, name: string, image_url: string | null, target?: string | null }
|
||||
interface Session { id: number, title: string | null, status: string, set_logs: (SetLog & { exercise?: Exercise })[] }
|
||||
interface Plan { sets: number, target_reps: string | null, target_weight: number | null }
|
||||
interface PlannedExercise { exercise_id: number, position: number, sets: number, target_reps: string | null, target_weight: number | null, rest_seconds: number | null, exercise: Exercise | null }
|
||||
interface Session { id: number, title: string | null, status: string, routine_id: number | null, set_logs: (SetLog & { exercise?: Exercise })[], planned_exercises?: PlannedExercise[] }
|
||||
type ActiveExercise = Exercise & { plan?: Plan }
|
||||
|
||||
// L'API peut envelopper la resource dans { data: {...} } → déballage tolérant.
|
||||
const { data: session, refresh } = await useAsyncData(
|
||||
@@ -16,14 +19,17 @@ const { data: session, refresh } = await useAsyncData(
|
||||
() => api<Session | { data: Session }>(`/api/sessions/${sessionId}`).then((r: unknown) => (r as { data?: Session })?.data ?? r as Session)
|
||||
)
|
||||
|
||||
// Exercices actifs = ceux ayant des sets + ceux ajoutés manuellement
|
||||
// Exercices actifs = exercices planifiés par la routine (dans l'ordre) + ceux ayant des sets + ajoutés manuellement.
|
||||
const added = ref<Exercise[]>([])
|
||||
const exercises = computed<Exercise[]>(() => {
|
||||
const map = new Map<number, Exercise>()
|
||||
for (const sl of session.value?.set_logs ?? []) {
|
||||
if (sl.exercise) map.set(sl.exercise.id, sl.exercise)
|
||||
const exercises = computed<ActiveExercise[]>(() => {
|
||||
const map = new Map<number, ActiveExercise>()
|
||||
for (const p of session.value?.planned_exercises ?? []) {
|
||||
if (p.exercise) map.set(p.exercise.id, { ...p.exercise, plan: { sets: p.sets, target_reps: p.target_reps, target_weight: p.target_weight } })
|
||||
}
|
||||
for (const e of added.value) map.set(e.id, e)
|
||||
for (const sl of session.value?.set_logs ?? []) {
|
||||
if (sl.exercise && !map.has(sl.exercise.id)) map.set(sl.exercise.id, sl.exercise)
|
||||
}
|
||||
for (const e of added.value) if (!map.has(e.id)) map.set(e.id, e)
|
||||
return [...map.values()]
|
||||
})
|
||||
|
||||
@@ -47,6 +53,15 @@ function addExercise(e: Exercise) {
|
||||
|
||||
// Log d'une série
|
||||
const draft = reactive<Record<number, { reps?: number, weight?: number }>>({})
|
||||
|
||||
// Pré-remplit la 1re série de chaque exercice planifié avec les cibles de la routine (reps/poids).
|
||||
watch(() => session.value?.planned_exercises, (planned) => {
|
||||
for (const p of planned ?? []) {
|
||||
if (draft[p.exercise_id]) continue
|
||||
const reps = p.target_reps ? Number.parseInt(String(p.target_reps), 10) : Number.NaN
|
||||
draft[p.exercise_id] = { reps: Number.isFinite(reps) ? reps : undefined, weight: p.target_weight ?? undefined }
|
||||
}
|
||||
}, { immediate: true })
|
||||
async function logSet(exId: number) {
|
||||
const d = draft[exId] || {}
|
||||
const setNumber = setsFor(exId).length + 1
|
||||
@@ -91,7 +106,12 @@ async function finish() {
|
||||
<div v-for="ex in exercises" :key="ex.id" class="rounded-xl border border-zinc-200 dark:border-zinc-800 p-3 space-y-2">
|
||||
<div class="flex items-center gap-3">
|
||||
<img v-if="ex.image_url" :src="ex.image_url" :alt="ex.name" class="size-10 rounded-lg object-cover">
|
||||
<p class="font-semibold capitalize flex-1">{{ ex.name }}</p>
|
||||
<div class="flex-1">
|
||||
<p class="font-semibold capitalize">{{ ex.name }}</p>
|
||||
<p v-if="ex.plan" class="text-xs text-zinc-500">
|
||||
{{ t('session.target') }} : {{ ex.plan.sets }} × {{ ex.plan.target_reps }}<span v-if="ex.plan.target_weight"> · {{ ex.plan.target_weight }} {{ t('session.weight') }}</span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-for="s in setsFor(ex.id)" :key="s.id" class="flex items-center gap-3 text-sm pl-1">
|
||||
|
||||
Reference in New Issue
Block a user