trails/apps/journal/app/routes/routes._index.tsx
Ullrich Schäfer df562742e1
fix(journal): extract loaders/actions for the remaining 21 mixed routes
Completes the .server.ts split started in #418. Every route that mixes
a default-export component with a server-only loader/action now has a
sibling <route>.server.ts holding the data-fetching helpers; the route
.tsx is a thin delegator.

Routes converted (21):
  activities._index, activities.$id, activities.new, auth.accept-terms,
  auth.verify, explore, feed, notifications, routes._index, routes.$id,
  routes.$id.edit, routes.new, settings, settings.account,
  settings.connections.komoot, settings.profile, settings.security,
  sync.import.$provider, sync.import.komoot, users.$username.followers,
  users.$username.following

Pattern (same as home.tsx / users.$username.tsx / settings.connections.tsx):
- loader → `return data(await loadX(request, params?))`
- action → `return await xAction(request, params?)`
- All `getDb` / Drizzle schema / `~/lib/*.server` imports move to the
  .server.ts sibling.
- `throw redirect(...)` and `throw data(...)` propagate through the
  delegator unchanged.

No behavior changes — pure module-graph cleanup. Component modules no
longer transitively import the DB client; Vite's tree-shake of
server-only code is now backed by an explicit, file-local contract.

Verified:
- pnpm typecheck — green
- pnpm lint — green
- pnpm test — 181 passed, 31 integration-gated skipped
- pnpm --filter @trails-cool/journal build — succeeds

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-24 11:05:40 +02:00

78 lines
2.8 KiB
TypeScript

import { data } from "react-router";
import { useTranslation } from "react-i18next";
import type { Route } from "./+types/routes._index";
import { ClientDate } from "~/components/ClientDate";
import { ClientMap } from "~/components/ClientMap";
import { loadRoutesIndex } from "./routes._index.server";
export async function loader({ request }: Route.LoaderArgs) {
return data(await loadRoutesIndex(request));
}
export function meta(_args: Route.MetaArgs) {
return [{ title: "My Routes — trails.cool" }];
}
export default function RoutesListPage({ loaderData }: Route.ComponentProps) {
const { routes } = loaderData;
const { t } = useTranslation("journal");
return (
<div className="mx-auto max-w-4xl px-4 py-8">
<div className="flex items-center justify-between">
<h1 className="text-2xl font-bold text-gray-900">{t("routes.myRoutes")}</h1>
<a
href="/routes/new"
className="rounded-md bg-blue-600 px-4 py-2 text-sm text-white hover:bg-blue-700"
>
{t("routes.new")}
</a>
</div>
{routes.length === 0 ? (
<p className="mt-8 text-center text-gray-500">
{t("routes.noRoutesYet")}
</p>
) : (
<ul className="mt-6 space-y-4">
{routes.map((route) => (
<li key={route.id}>
<a
href={`/routes/${route.id}`}
className="block rounded-lg border border-gray-200 p-4 hover:bg-gray-50"
>
<div className="flex gap-4">
<div className="w-48 shrink-0">
{route.geojson ? (
<ClientMap geojson={route.geojson} />
) : (
<div className="flex h-36 w-full items-center justify-center rounded bg-gray-100 text-xs text-gray-400">
{t("routes.noMapPreview")}
</div>
)}
</div>
<div className="flex flex-1 flex-col justify-between">
<div>
<h2 className="text-lg font-medium text-gray-900">{route.name}</h2>
<div className="mt-1 flex gap-4 text-sm text-gray-500">
{route.distance != null && (
<span>{(route.distance / 1000).toFixed(1)} km</span>
)}
{route.elevationGain != null && (
<span> {route.elevationGain} m</span>
)}
</div>
</div>
<span className="text-sm text-gray-400">
<ClientDate iso={route.updatedAt} />
</span>
</div>
</div>
</a>
</li>
))}
</ul>
)}
</div>
);
}