diff --git a/package.json b/package.json index 948927d..34e858b 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "@types/node": "^12.0.0", "@types/react": "^16.9.0", "@types/react-dom": "^16.9.0", - "make-workout": "^0.0.0", + "luxon": "^1.25.0", "react": "^16.13.1", "react-dom": "^16.13.1", "react-scripts": "3.4.3", @@ -39,6 +39,7 @@ ] }, "devDependencies": { + "@types/luxon": "^1.25.0", "@types/styled-components": "^5.1.3" } } diff --git a/src/components/WorkoutStats.tsx b/src/components/WorkoutStats.tsx index f8b5bfa..8c9912c 100644 --- a/src/components/WorkoutStats.tsx +++ b/src/components/WorkoutStats.tsx @@ -1,6 +1,45 @@ import React from 'react'; -import { stats, Workout } from 'make-workout'; +import { stats, Workout, Duration, Intensity } from 'make-workout'; +import { Duration as LuxonDuration } from 'luxon'; -export const WorkoutStats: React.FC<{workout: Workout}> = ({ workout }) => ( -
{stats(workout)}
+const formatDuration = (duration: Duration): string => {
+ const {hours, minutes, seconds} = LuxonDuration.fromObject({seconds: duration.seconds}).shiftTo('hours', 'minutes', 'seconds');
+ if (hours > 0) {
+ return `${hours}h ${minutes}min`;
+ }
+ else if (minutes > 0) {
+ return `${minutes}min`;
+ }
+ else if (seconds > 0) {
+ return `${seconds}sec`;
+ }
+ else {
+ return `-`;
+ }
+};
+
+const formatIntensity = (intensity: Intensity): string => `${Math.round(intensity.value * 100)}%`;
+
+const StatsLine: React.FC<{ label: string, value: string | number }> = ({ label, value }) => (
+