Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 app/api/v1/reports/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ export const GET = route(async (req) => {
});

/**
* Authenticated: submit a report. Accepts multipart/form-data (fields plus up
* to 3 `photos` files) or plain JSON when there are no photos.
* Authenticated: submit a report as multipart/form-data with 1 to 3 `photos` files.
*/
export const POST = route(async (req) => {
const session = await requireUser();
Expand All @@ -54,6 +53,7 @@ export const POST = route(async (req) => {
if (!withinBounds(input.lng, input.lat)) {
throw new HttpError(400, "The selected location is outside Sipocot");
}
if (files.length === 0) throw new HttpError(400, "Attach at least one photo of the problem");

const stored = await saveImages(files);
try {
Expand Down
85 changes: 85 additions & 0 deletions app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,88 @@ body {
border: 1px solid #e2e8f0;
border-radius: 0.75rem;
}

/* Map pins. Motion goes on the inner svg and pseudo-elements only: MapLibre sets transform on the marker root. */
@keyframes pin-drop {
0% { opacity: 0; transform: translateY(-16px) scale(0.6); }
60% { opacity: 1; transform: translateY(3px) scale(1.04); }
100% { transform: none; }
}
@keyframes pin-pulse {
0% { opacity: 0.7; transform: scale(0.4); }
100% { opacity: 0; transform: scale(1.9); }
}
@keyframes card-in {
from { opacity: 0; transform: translate(-50%, 4px); }
to { opacity: 1; transform: translate(-50%, 0); }
}
/* Hover and press use the individual translate/rotate/scale properties, so they do not fight the drop and launch transform animations. */
.pin-svg {
animation: pin-drop 0.55s cubic-bezier(0.2, 0.8, 0.2, 1) backwards;
transition: translate 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), rotate 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), scale 0.15s ease-out, transform 0.2s ease-out;
}
.pin:hover .pin-svg {
translate: 0 -4px;
rotate: -7deg;
}
.pin:active .pin-svg {
scale: 0.88;
}
.pin[data-selected="1"] .pin-svg {
transform: scale(1.25);
}
.pin[data-selected="1"]::before {
content: "";
position: absolute;
left: 0;
bottom: 0;
width: 34px;
height: 12px;
border-radius: 50%;
background: rgb(29 53 87 / 0.45);
z-index: -1;
animation: pin-pulse 1.6s ease-out infinite;
}
.pin-card {
animation: card-in 0.18s ease-out;
}
/* Click: the pin lifts off, a shock ring spreads, and the other pins fade while the map flies in. */
@keyframes pin-launch {
0% { transform: translateY(0) scale(1); }
30% { transform: translateY(-10px) scale(1.2); }
100% { transform: translateY(-140px) scale(0.35); opacity: 0; }
}
@keyframes pin-shock {
from { transform: scale(0.5); opacity: 1; }
to { transform: scale(7); opacity: 0; }
}
.pin.pin-launch .pin-svg {
animation: pin-launch 0.9s cubic-bezier(0.5, 0, 0.8, 0.4) forwards;
}
.pin.pin-launch::after {
content: "";
position: absolute;
left: 0;
bottom: 0;
width: 34px;
height: 12px;
border: 2px solid rgb(29 53 87 / 0.7);
border-radius: 50%;
animation: pin-shock 0.9s ease-out forwards;
}
.pin.pin-launch .pin-card {
display: none !important; /* beats the inline display set on hover */
}
.map-launching .pin:not(.pin-launch) {
opacity: 0.25;
transition: opacity 0.4s ease-out;
}
@media (prefers-reduced-motion: reduce) {
.pin-svg,
.pin-card,
.pin[data-selected="1"]::before,
.pin.pin-launch::after {
animation: none;
transition: none;
}
}
22 changes: 6 additions & 16 deletions app/reports/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import type { Metadata } from "next";
import Link from "next/link";
import { notFound } from "next/navigation";
import ProgressSteps from "@/components/ProgressSteps";
import LocationCard from "@/components/LocationCard";
import ShareReport from "@/components/ShareReport";
import PhotoGallery from "@/components/PhotoGallery";
import StaticMap from "@/components/StaticMap";
import StatusBadge from "@/components/StatusBadge";
import TransitionControls from "@/components/TransitionControls";
Expand Down Expand Up @@ -72,22 +75,7 @@ export default async function ReportPage({ params }: Props) {
<section className="card p-5">
<h2 className="text-lg font-semibold">Details</h2>
<p className="mt-2 whitespace-pre-line text-slate-700">{report.description}</p>
{report.media.length > 0 && (
<ul className="mt-4 grid grid-cols-2 gap-3 sm:grid-cols-3">
{report.media.map((m) => (
<li key={m.id}>
<a href={m.url} target="_blank" rel="noopener noreferrer">
{m.url.endsWith(".pdf") ? (
<span className="grid aspect-square w-full place-items-center rounded-lg bg-slate-100 text-sm font-semibold text-ink-700">Open PDF</span>
) : (
// eslint-disable-next-line @next/next/no-img-element
<img src={m.url} alt="Photo of the reported issue" className="aspect-square w-full rounded-lg object-cover" />
)}
</a>
</li>
))}
</ul>
)}
{report.media.length > 0 && <PhotoGallery photos={report.media} />}
</section>

<section className="card p-5">
Expand All @@ -114,6 +102,8 @@ export default async function ReportPage({ params }: Props) {

<aside className="space-y-6">
<StaticMap lng={report.lng} lat={report.lat} status={report.status} />
<LocationCard lat={report.lat} lng={report.lng} address={report.address} />
<ShareReport title={report.title} />

{isStaffRole(session?.role) && report.allowedTransitions && (
<section className="card space-y-3 p-5">
Expand Down
32 changes: 19 additions & 13 deletions components/Explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,26 @@ export default function Explorer({
const filtered = statuses.join() !== DEFAULT_STATUSES.join() || category !== "";
const btn = "inline-flex items-center gap-2 rounded-xl bg-white px-4 py-2.5 text-sm font-semibold text-slate-800 panel hover:bg-slate-50";

// Stats on the map (desktop) and in the list panel (phones): one definition, two places.
const statCells = (floating: boolean) => (
<dl className={floating ? "hidden grid-cols-4 gap-3 rounded-xl bg-white p-3 text-center shadow-lg ring-1 ring-black/5 sm:grid" : "grid grid-cols-4 gap-2 border-b border-slate-100 p-3 text-center"}>
{[
["Verified", stats.verified, "#d97706"],
["In progress", stats.inProgress, "#2563eb"],
["Resolved", stats.resolved, "#16a34a"],
["Avg. fix", stats.avgResolutionDays === null ? "—" : `${stats.avgResolutionDays}d`, "#1d3557"],
].map(([label, value, color]) => (
<div key={label as string}>
<dd className="text-lg font-bold" style={{ color: color as string }}>{value}</dd>
<dt className="text-[11px] text-slate-500">{label}</dt>
</div>
))}
</dl>
);

return (
<section aria-label="Reports map" className="relative h-[calc(100svh-4rem)] min-h-[480px]">
<div className="absolute right-3 top-3 z-10">{statCells(true)}</div>
<ReportsMap
reports={reports}
categories={categories}
Expand Down Expand Up @@ -178,19 +196,7 @@ export default function Explorer({

{panel === "list" && (
<div className="flex max-h-[calc(100svh-11rem)] flex-col rounded-xl bg-white shadow-lg ring-1 ring-black/5">
<dl className="grid grid-cols-4 gap-2 border-b border-slate-100 p-3 text-center">
{[
["Verified", stats.verified, "#d97706"],
["In progress", stats.inProgress, "#2563eb"],
["Resolved", stats.resolved, "#16a34a"],
["Avg. fix", stats.avgResolutionDays === null ? "—" : `${stats.avgResolutionDays}d`, "#1d3557"],
].map(([label, value, color]) => (
<div key={label as string}>
<dd className="text-lg font-bold" style={{ color: color as string }}>{value}</dd>
<dt className="text-[11px] text-slate-500">{label}</dt>
</div>
))}
</dl>
{statCells(false)}
{error && <p role="alert" className="m-3 rounded-lg bg-red-50 px-3 py-2 text-sm text-red-700">Could not refresh the map. Showing the last results.</p>}
<ul className="space-y-2 overflow-y-auto p-3">
{reports.length === 0 && !loading && <li className="p-6 text-center text-sm text-slate-500">No reports match these filters yet.</li>}
Expand Down
42 changes: 42 additions & 0 deletions components/LocationCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"use client";

import { useState } from "react";

/** Coordinates, copy and open-in-maps actions. Sharing lives in ShareReport. */
export default function LocationCard({ lat, lng, address }: { lat: number; lng: number; address: string | null }) {
const [message, setMessage] = useState<string | null>(null);
const gps = `${lat.toFixed(5)}, ${lng.toFixed(5)}`;

async function copy(text: string, done: string) {
try {
await navigator.clipboard.writeText(text);
setMessage(done);
} catch {
setMessage("Could not copy on this browser.");
}
}

return (
<section className="card space-y-3 p-5">
<h2 className="text-lg font-semibold">Location</h2>
{address && <p className="text-sm text-slate-700">{address}</p>}
<p className="font-mono text-sm text-slate-600">{gps}</p>
<div className="flex flex-wrap gap-2">
<button type="button" onClick={() => copy(gps, "GPS copied")} className="rounded-lg bg-slate-100 px-3 py-2 text-sm font-semibold text-slate-700 hover:bg-slate-200">
Copy GPS
</button>
<a
href={`https://www.google.com/maps?q=${lat},${lng}`}
target="_blank"
rel="noopener noreferrer"
className="rounded-lg bg-slate-100 px-3 py-2 text-sm font-semibold text-slate-700 hover:bg-slate-200"
>
Open in Maps
</a>
</div>
<p role="status" className="min-h-5 text-xs text-slate-500">
{message}
</p>
</section>
);
}
88 changes: 88 additions & 0 deletions components/PhotoGallery.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
"use client";

import { useRef, useState } from "react";

interface Photo {
id: string;
url: string;
}

/** Thumbnails open a full-size viewer. Uses the native <dialog>, so Escape and focus handling come from the browser. */
export default function PhotoGallery({ photos }: { photos: Photo[] }) {
const dialog = useRef<HTMLDialogElement>(null);
const [index, setIndex] = useState(0);
const images = photos.filter((p) => !p.url.endsWith(".pdf"));
const pdfs = photos.filter((p) => p.url.endsWith(".pdf"));
const current = images[index];

function open(i: number) {
setIndex(i);
dialog.current?.showModal();
}

function step(delta: number) {
setIndex((i) => (i + delta + images.length) % images.length);
}

return (
<>
<ul className="mt-4 grid grid-cols-2 gap-3 sm:grid-cols-3">
{images.map((m, i) => (
<li key={m.id}>
<button type="button" onClick={() => open(i)} aria-label={`Enlarge photo ${i + 1} of ${images.length}`} className="block w-full overflow-hidden rounded-lg">
{/* eslint-disable-next-line @next/next/no-img-element */}
<img src={m.url} alt="" className="aspect-square w-full object-cover transition duration-200 hover:scale-[1.03]" />
</button>
</li>
))}
{pdfs.map((m) => (
<li key={m.id}>
<a href={m.url} target="_blank" rel="noopener noreferrer" className="grid aspect-square w-full place-items-center rounded-lg bg-slate-100 text-sm font-semibold text-ink-700">
Open PDF
</a>
</li>
))}
</ul>

<dialog
ref={dialog}
aria-label="Photo viewer"
onKeyDown={(e) => {
if (e.key === "ArrowRight") step(1);
if (e.key === "ArrowLeft") step(-1);
}}
onClick={(e) => {
// A click on the backdrop (outside the image panel) closes the viewer.
if (e.target === dialog.current) dialog.current?.close();
}}
className="m-auto max-h-[95vh] max-w-[95vw] bg-transparent p-0 backdrop:bg-slate-900/90"
>
{current && (
<div className="relative flex flex-col items-center gap-3">
{/* eslint-disable-next-line @next/next/no-img-element */}
<img src={current.url} alt={`Photo ${index + 1} of ${images.length}`} className="max-h-[82vh] max-w-full rounded-lg object-contain" />
<div className="flex w-full items-center justify-between text-sm text-white">
<button type="button" onClick={() => step(-1)} disabled={images.length < 2} className="rounded-lg bg-white/15 px-4 py-2 font-semibold hover:bg-white/25 disabled:opacity-40">
← Previous
</button>
<span aria-live="polite">
{index + 1} / {images.length}
</span>
<button type="button" onClick={() => step(1)} disabled={images.length < 2} className="rounded-lg bg-white/15 px-4 py-2 font-semibold hover:bg-white/25 disabled:opacity-40">
Next →
</button>
</div>
<button
type="button"
onClick={() => dialog.current?.close()}
aria-label="Close photo viewer"
className="absolute -right-2 -top-2 grid h-9 w-9 place-items-center rounded-full bg-white text-lg font-bold text-slate-800 shadow-lg"
>
×
</button>
</div>
)}
</dialog>
</>
);
}
3 changes: 2 additions & 1 deletion components/ReportForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export default function ReportForm({
setError(null);
if (!location) return setError("Click the map to mark where the problem is.");
if (!withinBounds(location.lng, location.lat)) return setError(`The pin must be inside ${MUNICIPALITY.name}.`);
if (files.length === 0) return setError("Attach at least one photo of the problem.");

const form = new FormData(e.currentTarget);
form.set("lat", String(location.lat));
Expand Down Expand Up @@ -173,7 +174,7 @@ export default function ReportForm({

<section className="card space-y-3 p-5">
<h2 className="text-lg font-semibold">
Photos <span className="text-sm font-normal text-slate-500">(optional, up to {MAX_FILES})</span>
Photos <span className="text-sm font-normal text-slate-500">(at least one, up to {MAX_FILES})</span>
</h2>
<p className="text-sm text-slate-600">Clear photos help city crews find and assess the problem. JPEG, PNG or WebP, up to 5 MB each.</p>
{previews.length > 0 && (
Expand Down
Loading
Loading