Skip to content

Commit

Permalink
Merge branch 'master' into jfdoming/reload-on-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jfdoming authored Nov 3, 2024
2 parents 63fc5b5 + 15b2ef1 commit a27d0a5
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 14 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ export function ScheduleDetails({ id, transaction }) {
fields: {
payee: schedule._payee,
account: schedule._account,
// defalut to a non-zero value so the sign can be changed before the value
amount: schedule._amount || -1000,
amount: schedule._amount || 0,
amountOp: schedule._amountOp || 'isapprox',
date: schedule._date,
posts_transaction: action.schedule.posts_transaction,
Expand Down
38 changes: 26 additions & 12 deletions packages/desktop-client/src/components/util/AmountInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ export function AmountInput({
autoDecimals = false,
}: AmountInputProps) {
const format = useFormat();
const negative = (initialValue === 0 && zeroSign === '-') || initialValue < 0;
const [symbol, setSymbol] = useState<'+' | '-'>(
initialValue === 0 ? zeroSign : initialValue > 0 ? '+' : '-',
);

const initialValueAbsolute = format(Math.abs(initialValue || 0), 'financial');
const [value, setValue] = useState(initialValueAbsolute);
Expand All @@ -73,12 +75,16 @@ export function AmountInput({
}, [focused]);

function onSwitch() {
fireUpdate(!negative);
const amount = getAmount();
if (amount === 0) {
setSymbol(symbol === '+' ? '-' : '+');
}
fireUpdate(amount * -1);
}

function getAmount(negate) {
const valueOrInitial = Math.abs(amountToInteger(evalArithmetic(value)));
return negate ? valueOrInitial * -1 : valueOrInitial;
function getAmount() {
const signedValued = symbol === '-' ? symbol + value : value;
return amountToInteger(evalArithmetic(signedValued));
}

function onInputTextChange(val) {
Expand All @@ -89,13 +95,19 @@ export function AmountInput({
onChangeValue?.(val);
}

function fireUpdate(negate) {
onUpdate?.(getAmount(negate));
function fireUpdate(amount) {
onUpdate?.(amount);
if (amount > 0) {
setSymbol('+');
} else if (amount < 0) {
setSymbol('-');
}
}

function onInputAmountBlur(e) {
if (!ref.current?.contains(e.relatedTarget)) {
fireUpdate(negative);
const amount = getAmount();
fireUpdate(amount);
}
onBlur?.(e);
}
Expand All @@ -109,14 +121,15 @@ export function AmountInput({
<Button
variant="bare"
isDisabled={disabled}
aria-label={`Make ${negative ? 'positive' : 'negative'}`}
aria-label={`Make ${symbol === '-' ? 'positive' : 'negative'}`}
style={{ padding: '0 7px' }}
onPress={onSwitch}
ref={buttonRef}
>
{negative ? (
{symbol === '-' && (
<SvgSubtract style={{ width: 8, height: 8, color: 'inherit' }} />
) : (
)}
{symbol === '+' && (
<SvgAdd style={{ width: 8, height: 8, color: 'inherit' }} />
)}
</Button>
Expand All @@ -128,7 +141,8 @@ export function AmountInput({
inputStyle={inputStyle}
onKeyUp={e => {
if (e.key === 'Enter') {
fireUpdate(negative);
const amount = getAmount();
fireUpdate(amount);
}
}}
onChangeValue={onInputTextChange}
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/3732.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [lelemm]
---

Fix #2932: Schedule reset amount to ten (10) when amount is zero (0).

0 comments on commit a27d0a5

Please sign in to comment.