onRevisionNew
Revision creation handler
This example demonstrates how the onRevisionNew callback
sends a request using the Fetch API to create a new revision. Once the request completes, the
result is returned to the widget through the
onResponse
callback.
Revision creation handler
onRevisionNew = async function(revision: DIQ_Revision, onResponse: (result: DIQ_Result) => void ) {
try {
const res = await fetch("/api/revisions", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(revision)
});
if (!res.ok) {
throw new Error(`HTTP ${res.status}`);
}
await res.json();
onResponse({ ok: true });
} catch (err) {
onResponse({
ok: false,
message: err.message || "Failed to create revision"
});
}
};