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

@@ -1,65 +1,90 @@
import Image from "next/image";
import Link from "next/link";
import { startOfWeek } from "date-fns";
import { Activity, Dumbbell } from "lucide-react";
import { DashboardAnalysisCard } from "@/components/dashboard-analysis-card";
import { EmptyState } from "@/components/empty-state";
import { StatCard } from "@/components/stat-card";
import { formatDateShort, formatDistance, formatDuration, formatPace } from "@/lib/format";
import { getDashboardAnalysis } from "@/lib/models/analysis";
import { listRunningActivities } from "@/lib/models/running";
import { listStrengthWorkouts } from "@/lib/models/strength";
export const dynamic = "force-dynamic";
export default async function Home() {
const [runs, strengthWorkouts, dashboardAnalysis] = await Promise.all([
listRunningActivities(),
listStrengthWorkouts(),
getDashboardAnalysis(),
]);
const weekStart = startOfWeek(new Date(), { weekStartsOn: 1 });
const weeklyKm = runs
.filter((run) => run.startTime >= weekStart)
.reduce((sum, run) => sum + run.distanceM, 0) / 1000;
const weeklyStrengthSessions = strengthWorkouts.filter((workout) => workout.date >= weekStart).length;
const latestRun = runs[0];
const latestStrength = strengthWorkouts[0];
export default function Home() {
return (
<div className="flex flex-col flex-1 items-center justify-center bg-zinc-50 font-sans dark:bg-black">
<main className="flex flex-1 w-full max-w-3xl flex-col items-center justify-between py-32 px-16 bg-white dark:bg-black sm:items-start">
<Image
className="dark:invert"
src="/next.svg"
alt="Next.js logo"
width={100}
height={20}
priority
/>
<div className="flex flex-col items-center gap-6 text-center sm:items-start sm:text-left">
<h1 className="max-w-xs text-3xl font-semibold leading-10 tracking-tight text-black dark:text-zinc-50">
To get started, edit the page.tsx file.
</h1>
<p className="max-w-md text-lg leading-8 text-zinc-600 dark:text-zinc-400">
Looking for a starting point or more instructions? Head over to{" "}
<a
href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
className="font-medium text-zinc-950 dark:text-zinc-50"
<div className="flex flex-col gap-8">
<section className="grid grid-cols-1 gap-4 sm:grid-cols-2">
<StatCard label="Kilometry w tym tygodniu" value={`${weeklyKm.toFixed(1)} km`} hint="Bieganie" />
<StatCard label="Treningi siłowe w tym tygodniu" value={weeklyStrengthSessions} hint="Siłownia" />
</section>
<section className="grid grid-cols-1 gap-4 sm:grid-cols-2">
<div className="flex flex-col gap-3">
<h2 className="text-lg font-semibold text-fg">Ostatni bieg</h2>
{latestRun ? (
<Link
href={`/running/${latestRun._id.toString()}`}
className="flex flex-col gap-2 rounded-lg border border-muted/40 bg-surface p-4 transition-colors hover:border-accent/60"
>
Templates
</a>{" "}
or the{" "}
<a
href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
className="font-medium text-zinc-950 dark:text-zinc-50"
>
Learning
</a>{" "}
center.
</p>
</div>
<div className="flex flex-col gap-4 text-base font-medium sm:flex-row">
<a
className="flex h-12 w-full items-center justify-center gap-2 rounded-full bg-foreground px-5 text-background transition-colors hover:bg-[#383838] dark:hover:bg-[#ccc] md:w-[158px]"
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
<Image
className="dark:invert"
src="/vercel.svg"
alt="Vercel logomark"
width={16}
height={16}
<div className="font-semibold text-fg">{latestRun.name}</div>
<div className="text-sm text-fg/60">{formatDateShort(latestRun.startTime)}</div>
<div className="text-sm text-fg/70">
{formatDistance(latestRun.distanceM)} · {formatDuration(latestRun.durationSec)} ·{" "}
{formatPace(latestRun.avgPaceSecPerKm)}
</div>
</Link>
) : (
<EmptyState
icon={<Activity size={32} />}
title="Brak danych o bieganiu"
description="Zsynchronizuj aktywności z Garmin Connect, aby zobaczyć tutaj swoje biegi."
action={{ href: "/running", label: "Przejdź do biegania" }}
/>
Deploy Now
</a>
<a
className="flex h-12 w-full items-center justify-center rounded-full border border-solid border-black/[.08] px-5 transition-colors hover:border-transparent hover:bg-black/[.04] dark:border-white/[.145] dark:hover:bg-[#1a1a1a] md:w-[158px]"
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
Documentation
</a>
)}
</div>
</main>
<div className="flex flex-col gap-3">
<h2 className="text-lg font-semibold text-fg">Ostatni trening siłowy</h2>
{latestStrength ? (
<Link
href={`/strength/${latestStrength._id.toString()}`}
className="flex flex-col gap-2 rounded-lg border border-muted/40 bg-surface p-4 transition-colors hover:border-accent/60"
>
<div className="font-semibold text-fg">{latestStrength.name}</div>
<div className="text-sm text-fg/60">{formatDateShort(latestStrength.date)}</div>
<div className="text-sm text-fg/70">
{latestStrength.exercises.length}{" "}
{latestStrength.exercises.length === 1 ? "ćwiczenie" : "ćwiczeń"}
</div>
</Link>
) : (
<EmptyState
icon={<Dumbbell size={32} />}
title="Brak treningów siłowych"
description="Zaimportuj trening wklejając tekst wygenerowany przez aplikację Strong."
action={{ href: "/strength/import", label: "Zaimportuj trening" }}
/>
)}
</div>
</section>
<DashboardAnalysisCard analysis={dashboardAnalysis} />
</div>
);
}