Compare commits
2 Commits
f3a89d2590
...
1e0dd27fa3
| Author | SHA1 | Date | |
|---|---|---|---|
|
1e0dd27fa3
|
|||
|
9caa0fbc24
|
@@ -72,8 +72,9 @@ const translations: Translations = {
|
||||
workouts_plural: { en: 'Workouts', de: 'Trainings' },
|
||||
lifted: { en: 'Lifted', de: 'Gehoben' },
|
||||
est_kcal: { en: 'Est. kcal', de: 'Gesch. kcal' },
|
||||
burned: { en: 'Burned', de: 'Verbrannt' },
|
||||
kcal_set_profile: { en: 'Set sex & height in', de: 'Geschlecht & Grösse unter' },
|
||||
distance_covered: { en: 'Distance Covered', de: 'Zurückgelegt' },
|
||||
covered: { en: 'Covered', de: 'Zurückgelegt' },
|
||||
workouts_per_week: { en: 'Workouts per week', de: 'Trainings pro Woche' },
|
||||
sex: { en: 'Sex', de: 'Geschlecht' },
|
||||
male: { en: 'Male', de: 'Männlich' },
|
||||
|
||||
@@ -40,7 +40,9 @@ export const POST: RequestHandler = async ({ params, locals }) => {
|
||||
// Recompute totalVolume and totalDistance
|
||||
let totalVolume = 0;
|
||||
let totalDistance = 0;
|
||||
for (const ex of workoutSession.exercises) {
|
||||
const gpsPreviewUpdates: Record<string, number[][]> = {};
|
||||
for (let i = 0; i < workoutSession.exercises.length; i++) {
|
||||
const ex = workoutSession.exercises[i];
|
||||
const exercise = getExerciseById(ex.exerciseId);
|
||||
const metrics = getExerciseMetrics(exercise);
|
||||
const isCardio = metrics.includes('distance');
|
||||
@@ -56,7 +58,7 @@ export const POST: RequestHandler = async ({ params, locals }) => {
|
||||
|
||||
// Regenerate gpsPreview from gpsTrack if present
|
||||
if (ex.gpsTrack && ex.gpsTrack.length >= 2) {
|
||||
ex.gpsPreview = simplifyTrack(ex.gpsTrack);
|
||||
gpsPreviewUpdates[`exercises.${i}.gpsPreview`] = simplifyTrack(ex.gpsTrack);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,15 +122,20 @@ export const POST: RequestHandler = async ({ params, locals }) => {
|
||||
}
|
||||
}
|
||||
|
||||
workoutSession.totalVolume = totalVolume > 0 ? totalVolume : undefined;
|
||||
workoutSession.totalDistance = totalDistance > 0 ? totalDistance : undefined;
|
||||
workoutSession.prs = prs.length > 0 ? prs : undefined;
|
||||
await workoutSession.save();
|
||||
// Use $set to only update computed fields, preserving gpsTrack data
|
||||
await WorkoutSession.updateOne({ _id: workoutSession._id }, {
|
||||
$set: {
|
||||
totalVolume: totalVolume > 0 ? totalVolume : undefined,
|
||||
totalDistance: totalDistance > 0 ? totalDistance : undefined,
|
||||
prs: prs.length > 0 ? prs : undefined,
|
||||
...gpsPreviewUpdates
|
||||
}
|
||||
});
|
||||
|
||||
return json({
|
||||
totalVolume: workoutSession.totalVolume,
|
||||
totalDistance: workoutSession.totalDistance,
|
||||
prs: workoutSession.prs?.length ?? 0
|
||||
totalVolume: totalVolume > 0 ? totalVolume : undefined,
|
||||
totalDistance: totalDistance > 0 ? totalDistance : undefined,
|
||||
prs: prs.length
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error recalculating session:', error);
|
||||
|
||||
@@ -145,7 +145,7 @@
|
||||
<div class="lifetime-card kcal">
|
||||
<div class="card-icon"><Flame size={24} /></div>
|
||||
<div class="card-value">~{stats.kcalEstimate.kcal.toLocaleString()}<span class="card-unit">kcal</span></div>
|
||||
<div class="card-label">{t('est_kcal', lang)}</div>
|
||||
<div class="card-label">{t('burned', lang)}</div>
|
||||
{#if !hasDemographics}
|
||||
<div class="card-hint">{t('kcal_set_profile', lang)} <a href="/fitness/{fitnessSlugs(lang).measure}">{t('measure_title', lang)}</a></div>
|
||||
{/if}
|
||||
@@ -154,7 +154,7 @@
|
||||
<div class="lifetime-card cardio">
|
||||
<div class="card-icon"><Route size={24} /></div>
|
||||
<div class="card-value">{stats.totalCardioKm ?? 0}<span class="card-unit">km</span></div>
|
||||
<div class="card-label">{t('distance_covered', lang)}</div>
|
||||
<div class="card-label">{t('covered', lang)}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user