Improve MineGeo exploration and mapping features
This commit is contained in:
@@ -6,6 +6,7 @@ import type { DatasetManifest } from "@/shared/protocol";
|
||||
import type { ProcessingJob } from "@/shared/processing-progress";
|
||||
import { ProcessingProgress } from "./ProcessingProgress";
|
||||
import { PanoramaPreview } from "./PanoramaPreview";
|
||||
import { OwnerContributions } from "./OwnerContributions";
|
||||
type Draft = {
|
||||
id: string;
|
||||
name: string;
|
||||
@@ -15,8 +16,13 @@ type Draft = {
|
||||
rejection_reason: string | null;
|
||||
map: string | null;
|
||||
manifest: DatasetManifest;
|
||||
previews: { id: string; image: string | null }[];
|
||||
previews: { id: string; label: string; image: string | null }[];
|
||||
upload_jobs: ProcessingJob | null;
|
||||
parent_dataset_id: string | null;
|
||||
contribution_status: string | null;
|
||||
allow_contributions: boolean;
|
||||
contribution_server_address: string | null;
|
||||
update_state: string | null;
|
||||
};
|
||||
export function DraftEditor({ id }: { id: string }) {
|
||||
const [draft, setDraft] = useState<Draft | null>(null),
|
||||
@@ -27,6 +33,7 @@ export function DraftEditor({ id }: { id: string }) {
|
||||
[message, setMessage] = useState(""),
|
||||
[busy, setBusy] = useState(false);
|
||||
const [preview, setPreview] = useState<string | null>(null);
|
||||
const [version, setVersion] = useState(0);
|
||||
useEffect(() => {
|
||||
let disposed = false;
|
||||
let timer: ReturnType<typeof setTimeout>;
|
||||
@@ -53,7 +60,7 @@ export function DraftEditor({ id }: { id: string }) {
|
||||
disposed = true;
|
||||
clearTimeout(timer);
|
||||
};
|
||||
}, [id]);
|
||||
}, [id, version]);
|
||||
async function save(submit = false) {
|
||||
setBusy(true);
|
||||
setError("");
|
||||
@@ -66,8 +73,12 @@ export function DraftEditor({ id }: { id: string }) {
|
||||
);
|
||||
if (submit) {
|
||||
await api("datasets/" + id + "/submit", {});
|
||||
setDraft((d) => (d ? { ...d, state: "review" } : d));
|
||||
setMessage("Submitted for moderator review.");
|
||||
setVersion((v) => v + 1);
|
||||
setMessage(
|
||||
draft?.parent_dataset_id
|
||||
? "Submitted for map owner approval."
|
||||
: "Submitted for moderator review.",
|
||||
);
|
||||
} else setMessage("Draft saved.");
|
||||
} catch (e) {
|
||||
setError((e as Error).message);
|
||||
@@ -79,6 +90,11 @@ export function DraftEditor({ id }: { id: string }) {
|
||||
setBusy(true);
|
||||
try {
|
||||
await api("datasets/" + id + "/cancel", {});
|
||||
if (draft?.parent_dataset_id) {
|
||||
setVersion((v) => v + 1);
|
||||
setMessage("Contribution withdrawn. Its pending quota is released.");
|
||||
return;
|
||||
}
|
||||
setDraft((d) =>
|
||||
d
|
||||
? { ...d, state: "failed", rejection_reason: "Processing cancelled" }
|
||||
@@ -95,10 +111,40 @@ export function DraftEditor({ id }: { id: string }) {
|
||||
return (
|
||||
<p role={error ? "alert" : undefined}>{error || "Loading your draft…"}</p>
|
||||
);
|
||||
const editable = ["draft", "rejected"].includes(draft.state);
|
||||
const editable =
|
||||
(["draft", "rejected"].includes(draft.state) ||
|
||||
draft.state === "published") &&
|
||||
draft.update_state !== "review" &&
|
||||
!["submitted", "accepted", "rejected"].includes(
|
||||
draft.contribution_status ?? "",
|
||||
);
|
||||
const minimum = draft.parent_dataset_id ? 1 : 5;
|
||||
return (
|
||||
<>
|
||||
<span className="badge">{draft.state}</span>
|
||||
{draft.update_state && (
|
||||
<span className="badge">Update: {draft.update_state}</span>
|
||||
)}
|
||||
{draft.contribution_status && (
|
||||
<p role="status">
|
||||
Contribution: {draft.contribution_status}.{" "}
|
||||
{draft.state === "failed"
|
||||
? "This contribution no longer reserves panorama slots. Upload a fresh capture to try again."
|
||||
: draft.contribution_status === "accepted"
|
||||
? "The owner included your panoramas in the map draft. Map updates become playable after moderator approval."
|
||||
: draft.contribution_status === "submitted"
|
||||
? "Waiting for the map owner's approval."
|
||||
: draft.contribution_status === "rejected"
|
||||
? "Upload a fresh capture if you want to try again."
|
||||
: "Choose your locations, then submit them to the map owner."}
|
||||
</p>
|
||||
)}
|
||||
{draft.state === "published" && (
|
||||
<p className="muted">
|
||||
The approved version stays playable while you edit and moderators
|
||||
review your update.
|
||||
</p>
|
||||
)}
|
||||
<ProcessingProgress job={draft.upload_jobs} />
|
||||
{["uploading", "processing"].includes(draft.state) && (
|
||||
<p role="status" className="success-message">
|
||||
@@ -146,7 +192,8 @@ export function DraftEditor({ id }: { id: string }) {
|
||||
</label>
|
||||
<h2>Choose your locations.</h2>
|
||||
<p className="muted">
|
||||
Keep at least five clear, useful panoramas. Selected: {selected.length}
|
||||
Keep at least {minimum} clear, useful panorama{minimum === 1 ? "" : "s"}
|
||||
. Selected: {selected.length} / 24
|
||||
</p>
|
||||
<div className="preview-grid">
|
||||
{draft.previews.map((p) => (
|
||||
@@ -156,7 +203,7 @@ export function DraftEditor({ id }: { id: string }) {
|
||||
type="checkbox"
|
||||
checked={selected.includes(p.id)}
|
||||
disabled={!editable || busy}
|
||||
aria-label={`Keep location ${p.id}`}
|
||||
aria-label={`Keep ${p.label}`}
|
||||
onChange={(e) =>
|
||||
setSelected((s) =>
|
||||
e.target.checked
|
||||
@@ -170,11 +217,11 @@ export function DraftEditor({ id }: { id: string }) {
|
||||
src={p.image}
|
||||
width={512}
|
||||
height={512}
|
||||
alt={`Viewpoint ${p.id}`}
|
||||
alt={p.label}
|
||||
unoptimized
|
||||
/>
|
||||
)}
|
||||
<span>{p.id}</span>
|
||||
<span>{p.label}</span>
|
||||
</label>
|
||||
{p.image && (
|
||||
<button className="button full" onClick={() => setPreview(p.id)}>
|
||||
@@ -195,23 +242,41 @@ export function DraftEditor({ id }: { id: string }) {
|
||||
<div className="inline-actions">
|
||||
<button
|
||||
className="button"
|
||||
disabled={busy || selected.length < 5}
|
||||
disabled={busy || selected.length < minimum}
|
||||
onClick={() => save()}
|
||||
>
|
||||
Save draft
|
||||
</button>
|
||||
<button
|
||||
className="button primary"
|
||||
disabled={busy || selected.length < 5}
|
||||
disabled={busy || selected.length < minimum}
|
||||
onClick={() => save(true)}
|
||||
>
|
||||
Submit for review →
|
||||
{draft.parent_dataset_id
|
||||
? "Submit to map owner →"
|
||||
: "Submit for review →"}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
{["uploading", "processing"].includes(draft.state) && (
|
||||
{!draft.parent_dataset_id && (
|
||||
<OwnerContributions
|
||||
id={id}
|
||||
allowed={draft.allow_contributions}
|
||||
serverAddress={draft.contribution_server_address}
|
||||
bounds={draft.manifest.bounds}
|
||||
locked={draft.state === "review" || draft.update_state === "review"}
|
||||
onChange={() => setVersion((v) => v + 1)}
|
||||
/>
|
||||
)}
|
||||
{(["uploading", "processing"].includes(draft.state) ||
|
||||
(draft.parent_dataset_id &&
|
||||
["pending", "submitted"].includes(
|
||||
draft.contribution_status ?? "",
|
||||
))) && (
|
||||
<button className="button" disabled={busy} onClick={cancel}>
|
||||
Cancel processing
|
||||
{draft.parent_dataset_id
|
||||
? "Withdraw contribution"
|
||||
: "Cancel processing"}
|
||||
</button>
|
||||
)}
|
||||
{error && (
|
||||
|
||||
Reference in New Issue
Block a user