@@ -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' ;
1415import { uuid } from '@/utils/uuid' ;
1516import { 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+ }
0 commit comments