Skip to content

Commit 7ac3354

Browse files
committed
fix: Add diff string for progressive overload
1 parent f587560 commit 7ac3354

5 files changed

Lines changed: 166 additions & 91 deletions

File tree

app/src/components/presentation/summary/session-diff-view.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ function DiffChangeRow({
181181
const { t } = useTranslate();
182182
const theme = useAppTheme();
183183

184-
const description = getChangeDescription(change);
184+
const description = getChangeDescription(t, change);
185185
const label = getChangeLabelKey(change);
186186

187187
const variantColor = match(variant)
@@ -195,7 +195,7 @@ function DiffChangeRow({
195195
onPress={onToggle}
196196
title={t(label.key, label.params)}
197197
titleStyle={variantColor ? { color: variantColor } : undefined}
198-
description={t(description.key, description.params)}
198+
description={description}
199199
left={() => (
200200
<Checkbox
201201
disabled={disabled}

app/src/i18n/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@
287287
"plan.diff.cardio_set_removed.body": "Remove set {setNumber}",
288288
"plan.diff.cardio_set_modified.label": "Set {setNumber}",
289289
"plan.diff.cardio_set_modified.body": "Set {setNumber} modified",
290+
"plan.diff.progressive_overload_increase_all_evenly.label": "Evenly (amount: {amount})",
291+
"plan.diff.progressive_overload_increase_lowest_set.label": "Lowest (strategy: {strategy}) (amount: {amount})",
290292
"plan.manage.subtitle": "Setup your workout plans",
291293
"plan.manage.title": "Manage plans",
292294
"plan.name.label": "Plan Name",

app/src/models/blueprint-diff.spec.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
diffSessionBlueprints,
1515
getChangeDescription,
1616
} from './blueprint-diff';
17+
import { UseTranslateResult } from '@tolgee/react';
1718

1819
describe('diffSessionBlueprints', () => {
1920
const createWeightedExercise = (
@@ -773,7 +774,15 @@ describe('getChangeDescription', () => {
773774
const modified = new SessionBlueprint('Workout B', [], '');
774775

775776
const diff = diffSessionBlueprints(original, modified);
776-
const translatable = getChangeDescription(diff.sessionChanges[0]!);
777+
const t: UseTranslateResult['t'] = (key, params?) =>
778+
({ key, params }) as unknown as string;
779+
const translatable = getChangeDescription(
780+
t,
781+
diff.sessionChanges[0]!,
782+
) as unknown as {
783+
key: string;
784+
params: unknown;
785+
};
777786

778787
expect(translatable.key).toBe('plan.diff.generic_two_value_change.body');
779788
expect(translatable.params).toEqual({
@@ -791,7 +800,15 @@ describe('getChangeDescription', () => {
791800
);
792801

793802
const diff = diffSessionBlueprints(original, modified);
794-
const translatable = getChangeDescription(diff.addedExercises[0]!);
803+
const t: UseTranslateResult['t'] = (key, params?) =>
804+
({ key, params }) as unknown as string;
805+
const translatable = getChangeDescription(
806+
t,
807+
diff.addedExercises[0]!,
808+
) as unknown as {
809+
key: string;
810+
params: unknown;
811+
};
795812

796813
expect(translatable.key).toBe('plan.diff.exercise_added.body');
797814
expect(translatable.params).toEqual({ name: 'Squat' });
@@ -824,7 +841,13 @@ describe('getChangeDescription', () => {
824841
const setsChange = diff.modifiedExercises[0]!.changes.find(
825842
(c) => c.kind === 'exerciseSets',
826843
);
827-
const translatable = getChangeDescription(setsChange!);
844+
845+
const t: UseTranslateResult['t'] = (key, params?) =>
846+
({ key, params }) as unknown as string;
847+
const translatable = getChangeDescription(t, setsChange!) as unknown as {
848+
key: string;
849+
params: unknown;
850+
};
828851

829852
expect(translatable.key).toBe('plan.diff.generic_two_value_change.body');
830853
expect(translatable.params).toEqual({

app/src/models/blueprint-diff.ts

Lines changed: 131 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ import {
55
CardioTarget,
66
cardioTargetEquals,
77
ExerciseBlueprint,
8+
IncreaseStrategy,
89
ProgressiveOverload,
910
Rest,
1011
SessionBlueprint,
1112
WeightedExerciseBlueprint,
1213
} from './blueprint-models';
13-
import { TranslationKey } from '@tolgee/react';
14+
import { TranslationKey, UseTranslateResult } from '@tolgee/react';
1415
import { uuid } from '@/utils/uuid';
1516
import { EmptySession } from '@/models/session-models';
17+
import { localeFormatBigNumber } from '@/utils/locale-bignumber';
1618

1719
// ============================================================================
1820
// Change Types
@@ -1095,80 +1097,76 @@ export interface TranslatableString {
10951097
params?: Record<string, string | number>;
10961098
}
10971099

1098-
/**
1099-
* Get the translation key and parameters for describing a change.
1100-
* Use with t(result.key, result.params) in your component.
1101-
*/
1102-
export function getChangeDescription(change: DiffChange): TranslatableString {
1100+
export function getChangeDescription(
1101+
t: UseTranslateResult['t'],
1102+
change: DiffChange,
1103+
): string {
11031104
return match(change)
1104-
.returnType<TranslatableString>()
1105-
.with({ kind: 'sessionName' }, (c) => ({
1106-
key: 'plan.diff.generic_two_value_change.body',
1107-
params: { oldValue: c.oldValue, newValue: c.newValue },
1108-
}))
1109-
.with({ kind: 'sessionNotes' }, () => ({
1110-
key: 'plan.diff.generic_updated.body',
1111-
}))
1112-
.with({ kind: 'exercise', type: 'added' }, (c) => ({
1113-
key: 'plan.diff.exercise_added.body',
1114-
params: { name: c.exercise.name },
1115-
}))
1116-
.with({ kind: 'exercise', type: 'removed' }, (c) => ({
1117-
key: 'plan.diff.exercise_removed.body',
1118-
params: { name: c.exercise.name },
1119-
}))
1120-
.with({ kind: 'exercise', type: 'reordered' }, (c) => ({
1121-
key: 'plan.diff.exercise_reordered.body',
1122-
params: {
1105+
.returnType<string>()
1106+
.with({ kind: 'sessionName' }, (c) =>
1107+
t('plan.diff.generic_two_value_change.body', {
1108+
oldValue: c.oldValue,
1109+
newValue: c.newValue,
1110+
}),
1111+
)
1112+
.with({ kind: 'sessionNotes' }, () => t('plan.diff.generic_updated.body'))
1113+
.with({ kind: 'exercise', type: 'added' }, (c) =>
1114+
t('plan.diff.exercise_added.body', { name: c.exercise.name }),
1115+
)
1116+
.with({ kind: 'exercise', type: 'removed' }, (c) =>
1117+
t('plan.diff.exercise_removed.body', { name: c.exercise.name }),
1118+
)
1119+
.with({ kind: 'exercise', type: 'reordered' }, (c) =>
1120+
t('plan.diff.exercise_reordered.body', {
11231121
name: c.exerciseName,
11241122
oldPosition: c.oldIndex + 1,
11251123
newPosition: c.newIndex + 1,
1126-
},
1127-
}))
1128-
.with({ kind: 'exerciseName' }, (c) => ({
1129-
key: 'plan.diff.generic_two_value_change.body',
1130-
params: { oldValue: c.oldValue, newValue: c.newValue },
1131-
}))
1132-
.with({ kind: 'exerciseSets' }, (c) => ({
1133-
key: 'plan.diff.generic_two_value_change.body',
1134-
params: { oldValue: c.oldValue, newValue: c.newValue },
1135-
}))
1136-
.with({ kind: 'exerciseReps' }, (c) => ({
1137-
key: 'plan.diff.generic_two_value_change.body',
1138-
params: { oldValue: c.oldValue, newValue: c.newValue },
1139-
}))
1140-
.with({ kind: 'progressiveOverload' }, (c) => ({
1141-
key: 'plan.diff.generic_two_value_change.body',
1142-
params: {
1143-
oldValue: c.oldValue.weightIncrement.toString(),
1144-
newValue: c.newValue.weightIncrement.toString(),
1145-
},
1146-
}))
1147-
.with({ kind: 'exerciseRest' }, () => ({
1148-
key: 'plan.diff.generic_updated.body',
1149-
}))
1150-
.with({ kind: 'exerciseSuperset' }, (c) => ({
1151-
key: c.newValue
1152-
? 'plan.diff.generic_enabled.body'
1153-
: 'plan.diff.generic_disabled.body',
1154-
}))
1155-
.with({ kind: 'exerciseNotes' }, () => ({
1156-
key: 'plan.diff.generic_updated.body',
1157-
}))
1158-
.with({ kind: 'exerciseLink' }, () => ({
1159-
key: 'plan.diff.generic_updated.body',
1160-
}))
1161-
.with({ kind: 'exerciseTarget' }, () => ({
1162-
key: 'plan.diff.generic_updated.body',
1163-
}))
1164-
.with({ kind: 'exerciseTracking' }, (c) => ({
1165-
key: c.newValue
1166-
? 'plan.diff.generic_enabled.body'
1167-
: 'plan.diff.generic_disabled.body',
1168-
}))
1169-
.with({ kind: 'exerciseType' }, (c) => ({
1170-
key: 'plan.diff.generic_two_value_change.body',
1171-
params: {
1124+
}),
1125+
)
1126+
.with({ kind: 'exerciseName' }, (c) =>
1127+
t('plan.diff.generic_two_value_change.body', {
1128+
oldValue: c.oldValue,
1129+
newValue: c.newValue,
1130+
}),
1131+
)
1132+
.with({ kind: 'exerciseSets' }, (c) =>
1133+
t('plan.diff.generic_two_value_change.body', {
1134+
oldValue: c.oldValue,
1135+
newValue: c.newValue,
1136+
}),
1137+
)
1138+
.with({ kind: 'exerciseReps' }, (c) =>
1139+
t('plan.diff.generic_two_value_change.body', {
1140+
oldValue: c.oldValue,
1141+
newValue: c.newValue,
1142+
}),
1143+
)
1144+
.with({ kind: 'progressiveOverload' }, (c) =>
1145+
t('plan.diff.generic_two_value_change.body', {
1146+
oldValue: stringifyProgressiveOverload(t, c.oldValue),
1147+
newValue: stringifyProgressiveOverload(t, c.newValue),
1148+
}),
1149+
)
1150+
.with({ kind: 'exerciseRest' }, () => t('plan.diff.generic_updated.body'))
1151+
.with({ kind: 'exerciseSuperset' }, (c) =>
1152+
t(
1153+
c.newValue
1154+
? 'plan.diff.generic_enabled.body'
1155+
: 'plan.diff.generic_disabled.body',
1156+
),
1157+
)
1158+
.with({ kind: 'exerciseNotes' }, () => t('plan.diff.generic_updated.body'))
1159+
.with({ kind: 'exerciseLink' }, () => t('plan.diff.generic_updated.body'))
1160+
.with({ kind: 'exerciseTarget' }, () => t('plan.diff.generic_updated.body'))
1161+
.with({ kind: 'exerciseTracking' }, (c) =>
1162+
t(
1163+
c.newValue
1164+
? 'plan.diff.generic_enabled.body'
1165+
: 'plan.diff.generic_disabled.body',
1166+
),
1167+
)
1168+
.with({ kind: 'exerciseType' }, (c) =>
1169+
t('plan.diff.generic_two_value_change.body', {
11721170
oldValue:
11731171
c.oldExercise instanceof WeightedExerciseBlueprint
11741172
? 'weighted'
@@ -1177,20 +1175,17 @@ export function getChangeDescription(change: DiffChange): TranslatableString {
11771175
c.newExercise instanceof WeightedExerciseBlueprint
11781176
? 'weighted'
11791177
: 'cardio',
1180-
},
1181-
}))
1182-
.with({ kind: 'cardioSet', type: 'added' }, (c) => ({
1183-
key: 'plan.diff.cardio_set_added.body',
1184-
params: { setNumber: c.setIndex + 1 },
1185-
}))
1186-
.with({ kind: 'cardioSet', type: 'removed' }, (c) => ({
1187-
key: 'plan.diff.cardio_set_removed.body',
1188-
params: { setNumber: c.setIndex + 1 },
1189-
}))
1190-
.with({ kind: 'cardioSetModified' }, (c) => ({
1191-
key: 'plan.diff.cardio_set_modified.body',
1192-
params: { setNumber: c.setIndex + 1 },
1193-
}))
1178+
}),
1179+
)
1180+
.with({ kind: 'cardioSet', type: 'added' }, (c) =>
1181+
t('plan.diff.cardio_set_added.body', { setNumber: c.setIndex + 1 }),
1182+
)
1183+
.with({ kind: 'cardioSet', type: 'removed' }, (c) =>
1184+
t('plan.diff.cardio_set_removed.body', { setNumber: c.setIndex + 1 }),
1185+
)
1186+
.with({ kind: 'cardioSetModified' }, (c) =>
1187+
t('plan.diff.cardio_set_modified.body', { setNumber: c.setIndex + 1 }),
1188+
)
11941189
.exhaustive();
11951190
}
11961191

@@ -1266,3 +1261,54 @@ export function getChangeLabelKey(change: DiffChange): TranslatableString {
12661261
}))
12671262
.exhaustive();
12681263
}
1264+
1265+
function stringifyProgressiveOverload(
1266+
t: UseTranslateResult['t'],
1267+
progressiveOverload: ProgressiveOverload,
1268+
): string {
1269+
return match(progressiveOverload)
1270+
.returnType<string>()
1271+
.with({ type: 'NoProgressiveOverload' }, () =>
1272+
t('exercise.progressive_overload.no.label'),
1273+
)
1274+
.with({ type: 'IncreaseAllEvenlyProgressiveOverload' }, (x) =>
1275+
t('plan.diff.progressive_overload_increase_all_evenly.label', {
1276+
amount: localeFormatBigNumber(x.amount),
1277+
}),
1278+
)
1279+
.with({ type: 'IncreaseLowestSetProgressiveOverload' }, (x) =>
1280+
t('plan.diff.progressive_overload_increase_lowest_set.label', {
1281+
amount: localeFormatBigNumber(x.amount),
1282+
strategy: stringifyIncreaseStrategy(t, x.increaseStrategy),
1283+
}),
1284+
)
1285+
.exhaustive();
1286+
}
1287+
1288+
function stringifyIncreaseStrategy(
1289+
t: UseTranslateResult['t'],
1290+
strategy: IncreaseStrategy,
1291+
) {
1292+
return match(strategy)
1293+
.with('all', () =>
1294+
t(
1295+
'exercise.progressive_overload.increase_lowest_set.increase_strategy.all.label',
1296+
),
1297+
)
1298+
.with('first', () =>
1299+
t(
1300+
'exercise.progressive_overload.increase_lowest_set.increase_strategy.first.label',
1301+
),
1302+
)
1303+
.with('middle', () =>
1304+
t(
1305+
'exercise.progressive_overload.increase_lowest_set.increase_strategy.middle.label',
1306+
),
1307+
)
1308+
.with('last', () =>
1309+
t(
1310+
'exercise.progressive_overload.increase_lowest_set.increase_strategy.last.label',
1311+
),
1312+
)
1313+
.exhaustive();
1314+
}

app/src/models/blueprint-models/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,11 @@ export class IncreaseLowestSetProgressiveOverload {
474474
}
475475

476476
equals(other: ProgressiveOverload): boolean {
477-
return this.type === other.type && this.amount.isEqualTo(other.amount);
477+
return (
478+
this.type === other.type &&
479+
this.amount.isEqualTo(other.amount) &&
480+
this.increaseStrategy === other.increaseStrategy
481+
);
478482
}
479483

480484
applyProgressiveOverload(

0 commit comments

Comments
 (0)