Skip to content

Commit

Permalink
added max quantities on fleet send and collect debris
Browse files Browse the repository at this point in the history
  • Loading branch information
ametel01 committed Jan 29, 2024
1 parent 027cd61 commit ae1d082
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/frontend/src/components/buttons/ButtonAttackPlanet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { convertSecondsToTime } from '../../shared/utils';
import { TransactionStatus } from '../ui/TransactionStatus';
import { numberWithCommas } from '../../shared/utils';
import Slider from '@mui/material/Slider';
import KeyboardDoubleArrowUpIcon from '@mui/icons-material/KeyboardDoubleArrowUp';

type ShipName = 'carrier' | 'scraper' | 'sparrow' | 'frigate' | 'armade';

Expand Down Expand Up @@ -290,6 +291,14 @@ function ButtonAttackPlanet({
}
};

// Function to handle setting max quantity for each ship type
const handleMaxQuantity = (ship: ShipName) => {
setQuantities({
...quantities,
[ship]: Number(ownFleet[ship]), // Convert BigInt to Number
});
};

return (
<div>
{!isNoobProtected && !disabled ? (
Expand Down Expand Up @@ -362,6 +371,10 @@ function ButtonAttackPlanet({
variant="soft"
style={{ width: '80px' }}
/>
<KeyboardDoubleArrowUpIcon
onClick={() => handleMaxQuantity(ship as ShipName)}
style={{ cursor: 'pointer' }}
/>
</InputButtonContainer>
</FlexContainer>
))}
Expand Down
13 changes: 13 additions & 0 deletions packages/frontend/src/components/buttons/ButtonCollectDebris.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { convertSecondsToTime, numberWithCommas } from '../../shared/utils';
import { TransactionStatus } from '../ui/TransactionStatus';
import { SliderContainer, Text as SliderText } from './ButtonAttackPlanet';
import Slider from '@mui/material/Slider';
import KeyboardDoubleArrowUpIcon from '@mui/icons-material/KeyboardDoubleArrowUp';

export const StyledBox = styled(Box)({
fontWeight: 400,
Expand Down Expand Up @@ -185,6 +186,14 @@ export function ButtonCollectDebris({
setQuantities({ scraper: inputValue });
};

const handleMaxQuantity = () => {
// Update the quantities state to use the maximum available scrapers
setQuantities({
...quantities,
scraper: Number(ownFleet.scraper), // Setting to the total number of available scrapers
});
};

// Calculate the available scrapers after considering the input value
const availableScrapers =
Number(ownFleet.scraper) - (quantities.scraper || 0);
Expand Down Expand Up @@ -278,6 +287,10 @@ export function ButtonCollectDebris({
variant="soft"
style={{ width: '80px' }}
/>
<KeyboardDoubleArrowUpIcon
onClick={() => handleMaxQuantity()}
style={{ cursor: 'pointer' }}
/>
</InputButtonContainer>
<TotalDebrisText>
Total Debris{' '}
Expand Down

0 comments on commit ae1d082

Please sign in to comment.