fix(workbench): preview staged lane arrow overrides
This commit is contained in:
1 parent
0318876e6a
commit
fe73d993a9
3 files changed
+49
-5
No files matched your search
@@ -284,6 +284,7 @@ function App() {
|
||||
* same id in the document, which `validateEditDocument()` rejects outright.
|
||||
*/
|
||||
const gesture = useRef<{ operationId: string; createdAt: string } | null>(null);
|
||||
const overridePreviewRef = useRef<AbortController | null>(null);
|
||||
const gestureIdentity = () => {
|
||||
if (!gesture.current)
|
||||
gesture.current = {
|
||||
@@ -457,7 +458,10 @@ function App() {
|
||||
const discardEdits = () => {
|
||||
if (!session) return;
|
||||
requester?.cancel();
|
||||
overridePreviewRef.current?.abort();
|
||||
overridePreviewRef.current = null;
|
||||
session.discard();
|
||||
setStaged([]);
|
||||
gesture.current = null;
|
||||
touch();
|
||||
setPreview(null);
|
||||
@@ -511,10 +515,45 @@ function App() {
|
||||
setStatus(`直接编辑已保存(版本 ${version}),但重新生成失败:${(error as Error).message}`);
|
||||
}
|
||||
};
|
||||
const previewOverrides = (overrides: Override[]) => {
|
||||
if (!session) return;
|
||||
const fragment = session.fragment();
|
||||
overridePreviewRef.current?.abort();
|
||||
const controller = new AbortController();
|
||||
overridePreviewRef.current = controller;
|
||||
void api
|
||||
.editPreview(
|
||||
{
|
||||
previewSeq: session.nextPreviewSeq(),
|
||||
constraints: fragment.constraints,
|
||||
operations: fragment.operations,
|
||||
overrides,
|
||||
selection: selectionRef.current,
|
||||
},
|
||||
controller.signal,
|
||||
)
|
||||
.then((response) => {
|
||||
setEditDiagnostics(response.diagnostics);
|
||||
setManifest(response.handles);
|
||||
setPreview(response.layers);
|
||||
})
|
||||
.catch((error) => {
|
||||
if ((error as Error)?.name !== 'AbortError') setStatus(`箭头预览失败:${(error as Error).message}`);
|
||||
})
|
||||
.finally(() => {
|
||||
if (overridePreviewRef.current === controller) overridePreviewRef.current = null;
|
||||
});
|
||||
};
|
||||
const stage = (change: Override) =>
|
||||
setStaged((current) => [...current.filter((item) => item.id !== change.id), change]);
|
||||
setStaged((current) => {
|
||||
const next = [...current.filter((item) => item.id !== change.id), change];
|
||||
if (change.kind === 'lane-maneuver' && state) previewOverrides([...state.overrides.overrides, ...next]);
|
||||
return next;
|
||||
});
|
||||
const save = async () => {
|
||||
if (!state || !staged.length) return true;
|
||||
overridePreviewRef.current?.abort();
|
||||
overridePreviewRef.current = null;
|
||||
try {
|
||||
const overrides = [
|
||||
...state.overrides.overrides.filter((item) => !staged.some((change) => change.id === item.id)),
|
||||
@@ -626,7 +665,7 @@ function App() {
|
||||
<Button onClick={redoEdit} disabled={!session?.canRedo}>
|
||||
重做
|
||||
</Button>
|
||||
<Button onClick={discardEdits} disabled={!session?.dirty}>
|
||||
<Button onClick={discardEdits} disabled={!session?.dirty && !staged.length}>
|
||||
放弃
|
||||
</Button>
|
||||
</>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
// imports from here rather than casting response fields locally, so there is one
|
||||
// definition of "a valid manifest" on this side of the wire.
|
||||
|
||||
import type { GeoJson } from '../types/state';
|
||||
import type { GeoJson, Override } from '../types/state';
|
||||
|
||||
export type Side = 'left' | 'right';
|
||||
export type Transition = 'smoothstep' | 'linear';
|
||||
@@ -207,6 +207,7 @@ export type EditSelection = { segment: string } | { junction: string };
|
||||
*/
|
||||
export interface EditPreviewRequest {
|
||||
previewSeq: number;
|
||||
overrides?: Override[];
|
||||
constraints?: RoadConstraint[];
|
||||
operations?: RoadEditOperation[];
|
||||
document?: RoadEditDocument;
|
||||
|
||||
Reference in new issue
Block a user