Improve calculator progress tracking and responsive layout
All checks were successful
Deploy Sokko G / deploy (push) Successful in 18s
All checks were successful
Deploy Sokko G / deploy (push) Successful in 18s
This commit is contained in:
parent
3f86d863ac
commit
51853245ad
15 changed files with 329 additions and 75 deletions
|
|
@ -16,6 +16,20 @@ export function calculateExpression(expression, baseValue = null) {
|
|||
}
|
||||
}
|
||||
|
||||
export function parseCalculatorCurrent(value) {
|
||||
const normalized = String(value ?? "").replaceAll(",", ".").trim();
|
||||
if (!normalized) return 0;
|
||||
const parsed = Number(normalized);
|
||||
return Number.isFinite(parsed) ? parsed : null;
|
||||
}
|
||||
|
||||
export function calculateRemainingValue(expression, currentValue = 0, baseValue = null) {
|
||||
const total = calculateExpression(expression, baseValue);
|
||||
const current = parseCalculatorCurrent(currentValue);
|
||||
if (total == null || current == null) return null;
|
||||
return total - current;
|
||||
}
|
||||
|
||||
export function formatResult(value) {
|
||||
if (!Number.isFinite(value)) return "";
|
||||
return Number.parseFloat(value.toFixed(6)).toString();
|
||||
|
|
@ -58,7 +72,8 @@ export function getEntryFormula(entry) {
|
|||
}
|
||||
|
||||
export function getEditableFormula(entry) {
|
||||
return getEntryFormula(entry) || formatResult(entry.value);
|
||||
const current = Number(entry?.current);
|
||||
return getEntryFormula(entry) || formatResult(entry.value + (Number.isFinite(current) ? current : 0));
|
||||
}
|
||||
|
||||
export function createStoredFormula(expression, parentValue) {
|
||||
|
|
@ -82,7 +97,7 @@ export function evaluateCalculatorEntries(entries) {
|
|||
function visit(parentId = "", parentValue = null) {
|
||||
return (byParent.get(parentId) || []).flatMap((entry) => {
|
||||
const formula = getEntryFormula(entry);
|
||||
const calculatedValue = formula ? calculateExpression(formula, parentValue) : entry.value;
|
||||
const calculatedValue = formula ? calculateRemainingValue(formula, entry.current, parentValue) : entry.value;
|
||||
const nextEntry = { ...entry, value: calculatedValue ?? entry.value };
|
||||
return [nextEntry, ...visit(entry.id, nextEntry.value)];
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue