import { useRef, useState } from "react"; import { useTranslation } from "react-i18next"; import { useNavigate } from "react-router"; import type { Route } from "./+types/home"; import { parseGpxAsync, extractWaypoints } from "@trails-cool/gpx"; export function meta(_args: Route.MetaArgs) { return [ { title: "trails.cool Planner β€” Collaborative Route Planning" }, { name: "description", content: "Plan hiking and cycling routes together in real-time. No account needed." }, ]; } const features = [ { key: "featureCollaborative", icon: "πŸ‘₯" }, { key: "featureRouting", icon: "πŸ—ΊοΈ" }, { key: "featureElevation", icon: "⛰️" }, { key: "featureExport", icon: "πŸ“₯" }, { key: "featureNoAccount", icon: "πŸ”“" }, ] as const; export default function Home() { const { t } = useTranslation("planner"); const navigate = useNavigate(); const fileInputRef = useRef(null); const [importError, setImportError] = useState(null); const handleFileSelect = async (e: React.ChangeEvent) => { const file = e.target.files?.[0]; if (!file) return; // Reset input so the same file can be re-selected e.target.value = ""; try { const text = await file.text(); const gpxData = await parseGpxAsync(text); const waypoints = extractWaypoints(gpxData); const noGoAreas = gpxData.noGoAreas; // Create session via API const resp = await fetch("/api/sessions", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({}), }); if (!resp.ok) return; const session = await resp.json() as { url: string }; // Build session URL with imported data const params = new URLSearchParams(); if (waypoints.length > 0) params.set("waypoints", JSON.stringify(waypoints)); if (noGoAreas.length > 0) params.set("noGoAreas", JSON.stringify(noGoAreas)); navigate(`${session.url}?${params}`); } catch { setImportError(t("importGpxError")); setTimeout(() => setImportError(null), 4000); } }; return (
{/* Hero */}

{t("title")}

{t("landing.heroDescription")}

{t("landing.startPlanning")}
{importError && (

{importError}

)}
{/* Features */}
{features.map(({ key, icon }) => (
{icon}

{t(`landing.${key}`)}

{t(`landing.${key}Desc`)}

))}
{/* Secondary CTA */}

{t("landing.saveRoutes")}

{t("landing.saveRoutesDesc")}

{t("landing.goToJournal")}
{/* Footer */}
); }