You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.1 KiB

2 years ago
2 years ago
2 years ago
2 years ago
  1. import "./Misc.sass";
  2. import {WithChildren} from "../Shared";
  3. import {Values} from "../../models/Shared";
  4. export function TitleLine({children}: WithChildren) {
  5. return (
  6. <div className="TitleLine">{children}</div>
  7. );
  8. }
  9. interface ValueProps {
  10. raw: Values | number
  11. valueKey: keyof Values
  12. }
  13. export function Value({raw, valueKey}: ValueProps): JSX.Element | null {
  14. const actual = typeof raw === "number" ? raw : (raw[valueKey]);
  15. if (actual !== null && actual !== undefined) {
  16. if (valueKey === "time") {
  17. const minutes = Math.floor(actual / 60).toString(10).padStart(2, "0");
  18. const seconds = (actual % 60).toString(10).padStart(2, "0");
  19. return <><strong>{minutes}</strong>'<strong>{seconds}</strong>"</>;
  20. }
  21. if (valueKey === "calories") {
  22. return <><strong>{actual}</strong> kcal</>;
  23. }
  24. if (valueKey === "distance") {
  25. const km = actual / 1000;
  26. const kmStr = km > 9.95 ? km.toFixed(1) : km.toFixed(2);
  27. return <><strong>{kmStr}</strong> km</>;
  28. }
  29. if (valueKey === "level") {
  30. return <><strong>{actual}</strong> lvl</>;
  31. }
  32. }
  33. return null;
  34. }