Export template source from be30143a326d5d7d7b0cbabea5bc5ac0301ef5b9:examples/local-first/packages/language-reader-presentation
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import { useCrdtText, useLiveField, type ExactReference } from "@quixos/camino-react";
|
||||
import { interfaces } from "./gen/client.js";
|
||||
|
||||
/** Clear only the submitted text, preserving a newer collaborative draft. */
|
||||
export function usePrompt(reference: ExactReference, path: "name" | "change" | "followup" | "generate") {
|
||||
const operation = interfaces.ReadingNavigation.prompts.edit;
|
||||
const draft = useCrdtText({ key: reference.object + "/prompt/" + path, operation, reference, path: [path] });
|
||||
const field = useLiveField({ key: reference.object + "/prompt-clear/" + path, operation, reference });
|
||||
return {
|
||||
...draft,
|
||||
clearSubmitted(expected: string) {
|
||||
const current = field.current();
|
||||
if (current.status !== "ready") return;
|
||||
const snapshot = current.binding.getSnapshot();
|
||||
if (snapshot.value[path] === expected)
|
||||
current.binding.edit((editor) => editor.spliceText([path], 0, expected.length, ""), snapshot);
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user