This commit is contained in:
Dominik Klarkowski
2026-06-16 09:43:48 +02:00
parent f0e87d8d11
commit 36407f534b
52 changed files with 3211 additions and 100 deletions

View File

@@ -0,0 +1,37 @@
"use server";
import { redirect } from "next/navigation";
import { revalidatePath } from "next/cache";
import { parseStrongShareText } from "@/lib/strong/parser";
import { upsertStrengthWorkout } from "@/lib/models/strength";
export type ImportStrongWorkoutState = { error: string } | null;
export async function importStrongWorkout(
_prevState: ImportStrongWorkoutState,
formData: FormData
): Promise<ImportStrongWorkoutState> {
const text = formData.get("text");
if (typeof text !== "string" || text.trim().length === 0) {
return { error: "Wklej tekst wygenerowany przez funkcję 'Share workout' w Strong." };
}
let workouts;
try {
workouts = parseStrongShareText(text);
} catch (error) {
return { error: error instanceof Error ? error.message : "Nie udało się przetworzyć tekstu." };
}
if (workouts.length === 0) {
return { error: "Nie znaleziono żadnego treningu w podanym tekście." };
}
for (const workout of workouts) {
await upsertStrengthWorkout(workout);
}
revalidatePath("/strength");
revalidatePath("/");
redirect("/strength");
}