Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ ROUTECRAFT_ROUTING_ENGINE=java docker compose up -d routecraft-api

For native Java development, start only PostGIS with `docker compose up -d postgres`, then run `ROUTECRAFT_ROUTING_ENGINE=java ./mvnw spring-boot:run` from `services/routecraft-api`. For native Rust, run `cargo run --release --bin routecraft-engine` from `services/routecraft-engine`, then start Spring with `ROUTECRAFT_ENGINE_URL=http://localhost:8090 ./mvnw spring-boot:run` from the API directory.

Strava is optional. Export `STRAVA_CLIENT_ID`, `STRAVA_CLIENT_SECRET`, `STRAVA_ACCESS_TOKEN` and `STRAVA_REFRESH_TOKEN` to enable live segment loading; without them, that flow uses local mock data. Backend configuration is documented in [services/routecraft-api/.env.example](services/routecraft-api/.env.example). The frontend only needs its public API URL configuration.
Strava is optional. Export `STRAVA_CLIENT_ID` and `STRAVA_CLIENT_SECRET` to enable per-user Strava OAuth; users connect from `/strava` after signing in. Without client credentials, that flow uses local mock data. Backend configuration is documented in [services/routecraft-api/.env.example](services/routecraft-api/.env.example).

This is a local-first demo. The backend has no authentication or per-user authorization; add those controls before exposing it publicly.
Register or sign in at `/register` and `/login`. Session cookies plus CSRF protect saved-route and account endpoints. Route generation, geocoding, and OSM cache stay public so the wizard works without an account. Public share pages live at `/share/{token}` and expire by default after seven days.

## Repository layout

Expand Down
16 changes: 16 additions & 0 deletions apps/web/src/app/login/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Suspense } from "react";
import { LoginForm } from "@/components/LoginForm";

export default function LoginPage() {
return (
<Suspense
fallback={
<div className="mx-auto max-w-md px-4 py-16 text-center">
<p className="font-semibold text-emerald-800">Loading…</p>
</div>
}
>
<LoginForm />
</Suspense>
);
}
16 changes: 16 additions & 0 deletions apps/web/src/app/register/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Suspense } from "react";
import { RegisterForm } from "@/components/RegisterForm";

export default function RegisterPage() {
return (
<Suspense
fallback={
<div className="mx-auto max-w-md px-4 py-16 text-center">
<p className="font-semibold text-emerald-800">Loading…</p>
</div>
}
>
<RegisterForm />
</Suspense>
);
}
41 changes: 41 additions & 0 deletions apps/web/src/app/share/[token]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import type { Metadata } from "next";
import { ShareRouteClient } from "@/components/ShareRouteClient";
import { loadShare } from "@/lib/api-client/shares";

type SharePageProps = {
params: Promise<{ token: string }>;
};

export async function generateMetadata({ params }: SharePageProps): Promise<Metadata> {
const { token } = await params;
try {
const share = await loadShare(token);
const route = share.route;
const description = `${route.distanceKm} km · ${route.elevationGainM} m gain`;
return {
title: `${route.name} · RouteCraft`,
description,
openGraph: {
title: route.name,
description,
type: "website",
},
};
} catch {
return {
title: "Shared route · RouteCraft",
description: "A RouteCraft shared route.",
};
}
}

export default async function SharePage({ params }: SharePageProps) {
const { token } = await params;
let initialShare = null;
try {
initialShare = await loadShare(token);
} catch {
initialShare = null;
}
return <ShareRouteClient token={token} initialShare={initialShare} />;
}
6 changes: 4 additions & 2 deletions apps/web/src/app/strava/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Link from "next/link";
import { ArrowLeft } from "lucide-react";
import { StravaConnectBanner } from "@/components/StravaConnectBanner";
import { StravaRoutePicker } from "@/components/StravaRoutePicker";

export default function StravaPage() {
Expand All @@ -13,10 +14,11 @@ export default function StravaPage() {
<p className="font-semibold text-orange-600">Strava route map</p>
<h1 className="mt-2 text-4xl font-semibold text-stone-950">Explore existing routes near you</h1>
<p className="mt-4 text-lg leading-8 text-stone-600">
Nearby Strava segments load when backend credentials are configured; otherwise RouteCraft
shows local mock routes centered on your browser location when available.
Connect your Strava account after signing in to load live nearby segments; otherwise
RouteCraft shows local mock routes.
</p>
</div>
<StravaConnectBanner />
<StravaRoutePicker />
</main>
);
Expand Down
41 changes: 40 additions & 1 deletion apps/web/src/components/AppHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
"use client";

import { useEffect } from "react";
import Link from "next/link";
import { Bookmark, Compass, Map } from "lucide-react";
import { Bookmark, Compass, LogOut, Map } from "lucide-react";
import { useAuthStore } from "@/store/authStore";

export function AppHeader() {
const user = useAuthStore((state) => state.user);
const status = useAuthStore((state) => state.status);
const loadMe = useAuthStore((state) => state.loadMe);
const logout = useAuthStore((state) => state.logout);

useEffect(() => {
if (status === "idle") {
void loadMe();
}
}, [loadMe, status]);

return (
<header className="sticky top-0 z-40 border-b border-stone-200/80 bg-[#f7f5ee]/90 backdrop-blur">
<div className="mx-auto flex h-16 max-w-7xl items-center justify-between px-4 sm:px-6 lg:px-8">
Expand All @@ -26,6 +41,30 @@ export function AppHeader() {
<Bookmark size={17} />
Saved
</Link>
{status === "authenticated" && user ? (
<>
<span className="hidden max-w-[10rem] truncate px-2 text-stone-500 sm:inline">
{user.email}
</span>
<button
type="button"
onClick={() => {
void logout();
}}
className="inline-flex items-center gap-2 rounded-lg px-3 py-2 hover:bg-emerald-100 hover:text-emerald-950"
>
<LogOut size={17} />
Logout
</button>
</>
) : (
<Link
href="/login"
className="inline-flex items-center gap-2 rounded-lg bg-emerald-800 px-3 py-2 text-white hover:bg-stone-950"
>
Login
</Link>
)}
</nav>
</div>
</header>
Expand Down
53 changes: 53 additions & 0 deletions apps/web/src/components/AuthGate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"use client";

import { useEffect, type ReactNode } from "react";
import Link from "next/link";
import { usePathname, useRouter } from "next/navigation";
import { useAuthStore } from "@/store/authStore";

function sanitizeNext(pathname: string | null): string {
if (!pathname || !pathname.startsWith("/") || pathname.startsWith("//") || pathname.includes("..")) {
return "/saved";
}
return pathname;
}

export function AuthGate({ children }: { children: ReactNode }) {
const router = useRouter();
const pathname = usePathname();
const status = useAuthStore((state) => state.status);
const loadMe = useAuthStore((state) => state.loadMe);

useEffect(() => {
if (status === "idle") {
void loadMe();
}
}, [loadMe, status]);

useEffect(() => {
if (status === "anonymous") {
router.replace(`/login?next=${encodeURIComponent(sanitizeNext(pathname))}`);
}
}, [pathname, router, status]);

if (status === "idle" || status === "loading") {
return (
<div className="mx-auto max-w-3xl px-4 py-16 text-center">
<p className="font-semibold text-emerald-800">Checking session…</p>
</div>
);
}

if (status === "anonymous") {
return (
<div className="mx-auto max-w-3xl px-4 py-16 text-center">
<p className="font-semibold text-emerald-800">Redirecting to login…</p>
<Link href="/login" className="mt-4 inline-block font-semibold text-stone-700 underline">
Continue to login
</Link>
</div>
);
}

return <>{children}</>;
}
28 changes: 25 additions & 3 deletions apps/web/src/components/ElevationChart.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"use client";

import type { ElevationPoint } from "@/types/route";
import { formatMiles, mToFt } from "@/lib/units";

const W = 600;
const H = 130;
const PAD = { top: 16, right: 16, bottom: 28, left: 52 };
const H = 144;
const PAD = { top: 16, right: 56, bottom: 42, left: 52 };
const INNER_W = W - PAD.left - PAD.right;
const INNER_H = H - PAD.top - PAD.bottom;

Expand Down Expand Up @@ -45,6 +46,7 @@ export function ElevationChart({ profile }: { profile: ElevationPoint[] }) {
}

const yTicks = ticks(minElev, maxElev, 4);
const yTicksFt = ticks(mToFt(minElev), mToFt(maxElev), 4);

const xLabelCount = Math.min(Math.ceil(maxDist) + 1, 8);
const xStep = maxDist / (xLabelCount - 1);
Expand Down Expand Up @@ -77,7 +79,7 @@ export function ElevationChart({ profile }: { profile: ElevationPoint[] }) {
<svg
viewBox={`0 0 ${W} ${H}`}
className="w-full"
style={{ height: 160 }}
style={{ height: 176 }}
aria-label="Elevation profile chart"
>
{yTicks.map((tick) => {
Expand Down Expand Up @@ -107,6 +109,23 @@ export function ElevationChart({ profile }: { profile: ElevationPoint[] }) {
);
})}

{yTicksFt.map((tickFt) => {
const yPos = y(tickFt / mToFt(1));
if (yPos < PAD.top - 4 || yPos > PAD.top + INNER_H + 4) return null;
return (
<text
key={`ft-${tickFt}`}
x={PAD.left + INNER_W + 6}
y={yPos + 4}
textAnchor="start"
fontSize={11}
fill="#78716c"
>
{tickFt} ft
</text>
);
})}

<path d={areaPath} fill="#9ca3af" opacity={0.68} />
<path
d={linePath}
Expand All @@ -127,6 +146,9 @@ export function ElevationChart({ profile }: { profile: ElevationPoint[] }) {
fill="#78716c"
>
{d} km
<tspan x={x(d)} dy={13} fontSize={10} fill="#a8a29e">
{formatMiles(d)}
</tspan>
</text>
))}
</svg>
Expand Down
Loading
Loading