From dc06735645369fa3ab94ca441e521821538a5f52 Mon Sep 17 00:00:00 2001 From: Ethan Swan Date: Thu, 23 Nov 2023 13:01:53 -0600 Subject: [PATCH] Start exercise detail card. --- .../live/workouts/[workoutId]/LiveWorkout.tsx | 3 +- .../exerciseGroupCard/ExerciseCard.tsx | 72 +++++++++++++++---- .../exerciseGroupCard/ExerciseGroupCard.tsx | 29 +++++--- lib/resources/exercises/read.ts | 12 ++++ 4 files changed, 92 insertions(+), 24 deletions(-) diff --git a/app/(protected)/live/workouts/[workoutId]/LiveWorkout.tsx b/app/(protected)/live/workouts/[workoutId]/LiveWorkout.tsx index d179c2b..7511005 100644 --- a/app/(protected)/live/workouts/[workoutId]/LiveWorkout.tsx +++ b/app/(protected)/live/workouts/[workoutId]/LiveWorkout.tsx @@ -132,9 +132,10 @@ export default function LiveWorkout({ reps: number; weight: number; }) => { - const newExercise = { + const newExercise: Exercise = { reps, weight, + start_time: new Date(), exercise_type_id: exerciseType.id as string, workout_id: workout.id, }; diff --git a/app/(protected)/live/workouts/[workoutId]/exerciseGroupCard/ExerciseCard.tsx b/app/(protected)/live/workouts/[workoutId]/exerciseGroupCard/ExerciseCard.tsx index d83cc52..43a4c6c 100644 --- a/app/(protected)/live/workouts/[workoutId]/exerciseGroupCard/ExerciseCard.tsx +++ b/app/(protected)/live/workouts/[workoutId]/exerciseGroupCard/ExerciseCard.tsx @@ -2,28 +2,74 @@ import { SaveStatus } from "@/components/indicators/SaveStatusIndicator"; import SaveStatusOverlayContainer from "./SaveStatusOverlayContainer"; import { Card, CardContent } from "@/components/ui/card"; import { X } from "lucide-react"; +import { + Dialog, + DialogTrigger, + DialogHeader, + DialogTitle, + DialogContent, + DialogFooter, + DialogClose, +} from "@/components/ui/dialog"; +import { Button } from "@/components/ui/button"; +import { ExerciseWithType } from "@/lib/resources/apiTypes"; +import { formatDateYMD } from "@/lib/time"; interface ExerciseWidgetProps { - weight: number; - reps: number; + exercise: ExerciseWithType; saveStatus: SaveStatus; } export default function ExerciseCard({ - weight, - reps, + exercise, saveStatus, }: ExerciseWidgetProps) { return ( - - - -
{weight}
-
- - {reps} + + + {/* This button has to be inline in this function (not a separate component) for the alert trigger to work */} + + + + + +
+
+ + {exercise.exercise_type_name} + + + {exercise.start_time + ? formatDateYMD(exercise.start_time, true) + : "unknown"} + +
+
+
{exercise.weight}
+
pounds
+
{exercise.reps}
+
reps
+
+ + + + +
- - +
+
+ ); +} + +function ExerciseCardContent({ exercise, saveStatus }: ExerciseWidgetProps) { + return ( + + +
{exercise.weight}
+
+ + {exercise.reps} +
+
); } diff --git a/app/(protected)/live/workouts/[workoutId]/exerciseGroupCard/ExerciseGroupCard.tsx b/app/(protected)/live/workouts/[workoutId]/exerciseGroupCard/ExerciseGroupCard.tsx index cda2d24..224195e 100644 --- a/app/(protected)/live/workouts/[workoutId]/exerciseGroupCard/ExerciseGroupCard.tsx +++ b/app/(protected)/live/workouts/[workoutId]/exerciseGroupCard/ExerciseGroupCard.tsx @@ -1,6 +1,10 @@ "use client"; -import { Exercise, ExerciseType } from "@/lib/resources/apiTypes"; +import { + Exercise, + ExerciseType, + ExerciseWithType, +} from "@/lib/resources/apiTypes"; import CreateNewExerciseButton from "./CreateNewExerciseButton"; import ExerciseCard from "./ExerciseCard"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; @@ -26,6 +30,18 @@ export default function ExerciseGroupCard({ onAddExercise, supportsAddingExercise = false, }: ExerciseGroupWidgetProps) { + const exercisesWithTypes: ExerciseWithType[] = exercises + .filter((ex): ex is Exercise => !("isLoading" in ex)) + .map((ex) => { + return { + ...ex, + id: ex.id as string, + user_id: ex.user_id as string, + exercise_type_name: exerciseType.name, + exercise_type_id: exerciseType.id as string, + exercise_type_owner_user_id: exerciseType.owner_user_id, + }; + }); return ( @@ -34,18 +50,11 @@ export default function ExerciseGroupCard({ - {exercises.map((ex) => { + {exercisesWithTypes.map((ex) => { if ("isLoading" in ex) { return; } - return ( - - ); + return ; })} {supportsAddingExercise && ( ; + if (result.success) { + result.data = result.data.map(fixTypes); + } return result; } + +function fixTypes(exercise: Exercise): Exercise { + exercise = { ...exercise }; + // if "start_time" is a string, convert it to a Date + if (typeof exercise.start_time === "string") { + exercise.start_time = new Date(exercise.start_time); + } + return exercise; +}