|
@@ -1,9 +1,10 @@
|
|
|
"use client";
|
|
|
|
|
|
-import { useState } from "react";
|
|
|
+import { useState, useEffect } from "react";
|
|
|
import { Clock, Play, Pause, RotateCcw, X, Target, Weight } from "lucide-react";
|
|
|
|
|
|
import { useCurrentLocale, useI18n } from "locales/client";
|
|
|
+import { type WeightUnit } from "@/shared/lib/weight-conversion";
|
|
|
import { cn } from "@/shared/lib/utils";
|
|
|
import { useWorkoutSession } from "@/features/workout-session/model/use-workout-session";
|
|
|
import { Timer } from "@/components/ui/timer";
|
|
@@ -31,11 +32,26 @@ export function WorkoutSessionHeader({
|
|
|
const t = useI18n();
|
|
|
const [showQuitDialog, setShowQuitDialog] = useState(false);
|
|
|
const [resetCount, setResetCount] = useState(0);
|
|
|
+ const [volumeUnit, setVolumeUnit] = useState<WeightUnit>("kg");
|
|
|
const locale = useCurrentLocale();
|
|
|
- const { getExercisesCompleted, getTotalExercises, session, getTotalVolume } = useWorkoutSession();
|
|
|
+ const { getExercisesCompleted, getTotalExercises, session, getTotalVolume, getTotalVolumeInUnit } = useWorkoutSession();
|
|
|
const exercisesCompleted = getExercisesCompleted();
|
|
|
const totalExercises = getTotalExercises();
|
|
|
- const totalVolume = getTotalVolume();
|
|
|
+ const totalVolume = getTotalVolumeInUnit(volumeUnit);
|
|
|
+
|
|
|
+ // Load volume unit preference from localStorage
|
|
|
+ useEffect(() => {
|
|
|
+ const savedUnit = localStorage.getItem("volumeUnit") as WeightUnit;
|
|
|
+ if (savedUnit === "kg" || savedUnit === "lbs") {
|
|
|
+ setVolumeUnit(savedUnit);
|
|
|
+ }
|
|
|
+ }, []);
|
|
|
+
|
|
|
+ // Save volume unit preference to localStorage
|
|
|
+ const handleVolumeUnitChange = (unit: WeightUnit) => {
|
|
|
+ setVolumeUnit(unit);
|
|
|
+ localStorage.setItem("volumeUnit", unit);
|
|
|
+ };
|
|
|
|
|
|
const handleQuitClick = () => {
|
|
|
setShowQuitDialog(true);
|
|
@@ -158,8 +174,34 @@ export function WorkoutSessionHeader({
|
|
|
</div>
|
|
|
|
|
|
<div className="text-center">
|
|
|
- <div className="text-2xl font-bold text-slate-900 dark:text-white mb-1">{totalVolume}</div>
|
|
|
- <span className="text-sm text-slate-400">kg</span>
|
|
|
+ <div className="text-2xl font-bold text-slate-900 dark:text-white mb-1">
|
|
|
+ {totalVolume.toFixed(volumeUnit === "lbs" ? 1 : 0)}
|
|
|
+ </div>
|
|
|
+ <div className="flex items-center justify-center gap-1">
|
|
|
+ <button
|
|
|
+ className={cn(
|
|
|
+ "text-xs px-2 py-1 rounded transition-colors",
|
|
|
+ volumeUnit === "kg"
|
|
|
+ ? "bg-orange-100 text-orange-700 dark:bg-orange-900 dark:text-orange-100"
|
|
|
+ : "text-slate-400 hover:text-slate-600 dark:hover:text-slate-300",
|
|
|
+ )}
|
|
|
+ onClick={() => handleVolumeUnitChange("kg")}
|
|
|
+ >
|
|
|
+ kg
|
|
|
+ </button>
|
|
|
+ <span className="text-slate-300 dark:text-slate-600">|</span>
|
|
|
+ <button
|
|
|
+ className={cn(
|
|
|
+ "text-xs px-2 py-1 rounded transition-colors",
|
|
|
+ volumeUnit === "lbs"
|
|
|
+ ? "bg-orange-100 text-orange-700 dark:bg-orange-900 dark:text-orange-100"
|
|
|
+ : "text-slate-400 hover:text-slate-600 dark:hover:text-slate-300",
|
|
|
+ )}
|
|
|
+ onClick={() => handleVolumeUnitChange("lbs")}
|
|
|
+ >
|
|
|
+ lbs
|
|
|
+ </button>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|