"amount page changes "

new_001
sonali 2024-10-07 18:41:33 +05:30
parent e259fabdaa
commit 8e3f11218d
3 changed files with 19 additions and 25 deletions

View File

@ -1,6 +1,5 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import { Outlet } from 'react-router-dom'; import { Outlet } from 'react-router-dom';
import '../Common/ExpenseLayout.css'; import '../Common/ExpenseLayout.css';
import TotalExpenseAmount from '../ExpenseAmount/TotalExpenseAmount'; import TotalExpenseAmount from '../ExpenseAmount/TotalExpenseAmount';
@ -8,14 +7,21 @@ const ExpenseLayout = () => {
const [totalAmount, setTotalAmount] = useState(0); const [totalAmount, setTotalAmount] = useState(0);
const [category, setCategory] = useState(''); const [category, setCategory] = useState('');
const handleManualAmountChange = (amount) => {
setTotalAmount(amount);
};
return ( return (
<div className="layout-container"> <div className="layout-container">
<div className="page-content"> <div className="page-content">
<Outlet context={[totalAmount, setTotalAmount, category, setCategory]} /> <Outlet context={[totalAmount, setTotalAmount, category, setCategory]} />
</div> </div>
<TotalExpenseAmount
<TotalExpenseAmount totalAmount={totalAmount} category={category} setCategory={setCategory} /> totalAmount={totalAmount}
category={category}
setCategory={setCategory}
handleManualAmountChange={handleManualAmountChange} // Pass the function here
/>
</div> </div>
); );
}; };

View File

@ -12,22 +12,16 @@ function ExpenseAmount() {
const [totalAmount, setTotalAmount] = useOutletContext(); const [totalAmount, setTotalAmount] = useOutletContext();
const [isClickable, setIsClickable] = useState(true); const [isClickable, setIsClickable] = useState(true);
const [lastAddedAmount, setLastAddedAmount] = useState(0);
const handleCoinClick = (amount) => { const handleCoinClick = (coinAmount) => {
if (isClickable) { if (isClickable) {
setTotalAmount((prevAmount) => prevAmount + amount); // Update totalAmount based on coin click
setLastAddedAmount(amount); const newAmount = parseFloat(totalAmount) + coinAmount;
setTotalAmount(newAmount); // Update the total amount
setIsClickable(false); setIsClickable(false);
setTimeout(() => { setTimeout(() => {
setIsClickable(true); setIsClickable(true);
}, 500); }, 500);
}
};
const handleSubtractClick = (amount) => {
if (totalAmount >= amount) { // Ensure you do not go negative
setTotalAmount((prevAmount) => prevAmount - amount);
} }
}; };
@ -73,15 +67,6 @@ function ExpenseAmount() {
<div className="coin-value">1000</div> <div className="coin-value">1000</div>
</div> </div>
</section> </section>
<div className="btn-group">
<button onClick={() => handleSubtractClick(lastAddedAmount)} disabled={lastAddedAmount === 0}>
-
</button>
<button onClick={() => handleCoinClick(lastAddedAmount)}>
+
</button>
</div>
</div> </div>
); );
} }

View File

@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react';
import { useNavigate, useLocation } from 'react-router-dom'; import { useNavigate, useLocation } from 'react-router-dom';
import '../ExpenseAmount/TotalExpenseAmount.css'; import '../ExpenseAmount/TotalExpenseAmount.css';
function TotalExpenseAmount({ totalAmount, category, setCategory }) { function TotalExpenseAmount({ totalAmount, category, setCategory, handleManualAmountChange }) {
const [amount, setAmount] = useState(totalAmount || ''); const [amount, setAmount] = useState(totalAmount || '');
const location = useLocation(); const location = useLocation();
const { entryType } = location.state || {}; const { entryType } = location.state || {};
@ -118,7 +118,10 @@ function TotalExpenseAmount({ totalAmount, category, setCategory }) {
id="amount-input" id="amount-input"
type="number" type="number"
value={amount} value={amount}
onChange={(e) => setAmount(e.target.value)} onChange={(e) => {
setAmount(e.target.value);
handleManualAmountChange(e.target.value); // Ensure it's called properly
}}
onMouseDown={handleAmountMouseDown} onMouseDown={handleAmountMouseDown}
onDoubleClick={handleAmountDoubleClick} onDoubleClick={handleAmountDoubleClick}
placeholder="Enter Amount" placeholder="Enter Amount"