Make calculator child drafts atomic
This commit is contained in:
parent
ef7eba73db
commit
72b3b15c7e
3 changed files with 27 additions and 33 deletions
|
|
@ -85,10 +85,10 @@ export function CalculatorModule({ toolboxId, moduleId, context, configurationTa
|
|||
}, []);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
if (!pendingExpressionFocusRef.current || !editingEntryId) return;
|
||||
if (!pendingExpressionFocusRef.current || (!editingEntryId && !activeParentId)) return;
|
||||
pendingExpressionFocusRef.current = false;
|
||||
window.requestAnimationFrame(() => focusExpressionInputAtEnd(expressionInputRef.current));
|
||||
}, [editingEntryId]);
|
||||
}, [activeParentId, editingEntryId]);
|
||||
|
||||
function save(entries) {
|
||||
context.setModuleData(toolboxId, moduleId, { ...data, entries: evaluateCalculatorEntries(entries) });
|
||||
|
|
@ -118,18 +118,22 @@ export function CalculatorModule({ toolboxId, moduleId, context, configurationTa
|
|||
return;
|
||||
}
|
||||
|
||||
save([
|
||||
...data.entries,
|
||||
{
|
||||
id: context.uid("calc"),
|
||||
parentId: formulaParentId,
|
||||
label: cleanLabel,
|
||||
value: result,
|
||||
formula: storedFormula,
|
||||
current: storedCurrent
|
||||
}
|
||||
]);
|
||||
setExpression(formulaParent ? BASE_TOKEN : "");
|
||||
const newEntry = {
|
||||
id: context.uid("calc"),
|
||||
parentId: formulaParentId,
|
||||
label: cleanLabel,
|
||||
value: result,
|
||||
formula: storedFormula,
|
||||
current: storedCurrent
|
||||
};
|
||||
save([...data.entries, newEntry]);
|
||||
if (formulaParent) {
|
||||
setEditingEntryId(newEntry.id);
|
||||
setActiveParentId("");
|
||||
setLabel(cleanLabel);
|
||||
return;
|
||||
}
|
||||
setExpression("");
|
||||
setCurrent("");
|
||||
setShowCurrent(false);
|
||||
setLabel("");
|
||||
|
|
@ -145,22 +149,9 @@ export function CalculatorModule({ toolboxId, moduleId, context, configurationTa
|
|||
}
|
||||
|
||||
function createChildEntry(entry) {
|
||||
const childId = context.uid("calc");
|
||||
save([
|
||||
...data.entries,
|
||||
{
|
||||
id: childId,
|
||||
parentId: entry.id,
|
||||
label: "",
|
||||
value: Number.isFinite(entry.value) ? entry.value : 0,
|
||||
formula: BASE_TOKEN,
|
||||
current: 0
|
||||
}
|
||||
]);
|
||||
setEditingEntryId("");
|
||||
pendingExpressionFocusRef.current = true;
|
||||
setEditingEntryId(childId);
|
||||
setActiveParentId("");
|
||||
setActiveParentId(entry.id);
|
||||
setExpression(BASE_TOKEN);
|
||||
setCurrent("");
|
||||
setShowCurrent(false);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue