first commit
This commit is contained in:
commit
b7b0f253ce
85 files changed
+7560
No files matched your search
@@ -0,0 +1,95 @@
|
||||
import { notFound } from "next/navigation";
|
||||
import { deleteMap, renameMap } from "@/actions/maps";
|
||||
import { ConfirmSubmit } from "@/components/confirm-submit";
|
||||
import { MapLoader } from "@/components/map-loader";
|
||||
import { PageBody, PageHeader } from "@/components/page";
|
||||
import { getT } from "@/i18n/server";
|
||||
import { prisma } from "@/lib/db";
|
||||
import { fileUrl } from "@/lib/files";
|
||||
import { requireBook } from "@/lib/session";
|
||||
|
||||
// Standard är OpenStreetMaps publika tjänster. Byt via miljövariabler vid tyngre användning.
|
||||
const TILE_URL = process.env.MAP_TILE_URL ?? "https://tile.openstreetmap.org/{z}/{x}/{y}.png";
|
||||
const TILE_ATTRIBUTION = process.env.MAP_TILE_ATTRIBUTION ?? "© OpenStreetMap-bidragsgivare";
|
||||
const GEOCODER_URL = process.env.MAP_GEOCODER_URL ?? "https://nominatim.openstreetmap.org/search";
|
||||
|
||||
export default async function MapPage({
|
||||
params,
|
||||
searchParams,
|
||||
}: {
|
||||
params: Promise<{ bookId: string; mapId: string }>;
|
||||
searchParams: Promise<{ place?: string; marker?: string }>;
|
||||
}) {
|
||||
const { bookId, mapId } = await params;
|
||||
const { place, marker } = await searchParams;
|
||||
await requireBook(bookId);
|
||||
const { t } = await getT();
|
||||
|
||||
const [map, entities] = await Promise.all([
|
||||
prisma.bookMap.findFirst({ where: { id: mapId, bookId }, include: { markers: { orderBy: { createdAt: "asc" } } } }),
|
||||
prisma.entity.findMany({ where: { bookId }, select: { id: true, name: true, kind: true }, orderBy: { name: "asc" } }),
|
||||
]);
|
||||
if (!map) notFound();
|
||||
|
||||
const center: [number, number] | null =
|
||||
map.centerLat !== null && map.centerLng !== null ? [map.centerLat, map.centerLng] : null;
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHeader title={map.name} pretitle={t("map.title")} />
|
||||
<PageBody>
|
||||
<MapLoader
|
||||
bookId={bookId}
|
||||
mapId={map.id}
|
||||
kind={map.kind}
|
||||
imageUrl={fileUrl(map.imageFile)}
|
||||
center={center}
|
||||
zoom={map.zoom}
|
||||
markers={map.markers.map((m) => ({
|
||||
id: m.id,
|
||||
label: m.label,
|
||||
note: m.note,
|
||||
color: m.color,
|
||||
lat: m.lat,
|
||||
lng: m.lng,
|
||||
entityId: m.entityId,
|
||||
}))}
|
||||
entities={entities}
|
||||
tileUrl={TILE_URL}
|
||||
tileAttribution={TILE_ATTRIBUTION}
|
||||
geocoderUrl={GEOCODER_URL}
|
||||
preselectEntityId={entities.some((e) => e.id === place) ? (place ?? null) : null}
|
||||
initialMarkerId={marker ?? null}
|
||||
/>
|
||||
|
||||
<div className="card mt-4">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">{t("map.settings")}</h3>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
<div className="row g-3">
|
||||
<div className="col-md-6">
|
||||
<form action={renameMap} className="input-group">
|
||||
<input type="hidden" name="bookId" value={bookId} />
|
||||
<input type="hidden" name="mapId" value={map.id} />
|
||||
<input name="name" className="form-control" defaultValue={map.name} required maxLength={200} aria-label={t("map.rename")} />
|
||||
<button type="submit" className="btn">
|
||||
{t("map.rename")}
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
<div className="col-md-6 d-flex align-items-center gap-3">
|
||||
<form action={deleteMap}>
|
||||
<input type="hidden" name="bookId" value={bookId} />
|
||||
<input type="hidden" name="mapId" value={map.id} />
|
||||
<ConfirmSubmit className="btn btn-outline-danger">{t("map.deleteMap")}</ConfirmSubmit>
|
||||
</form>
|
||||
<span className="text-secondary small">{t("map.deleteMapHelp")}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</PageBody>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user