remove 0 calibers from graph

This commit is contained in:
blaisadmin
2026-03-29 22:36:45 -04:00
parent 8aaf6f7902
commit a0c0d2a9eb
+12 -10
View File
@@ -299,18 +299,20 @@ export default function Home() {
[ammoPageCaliberIds, enabledCalibers],
);
const ammoChartData = useMemo(() => {
const sortedInventory = [...enabledAmmoInventory].sort((left, right) => {
if (right.roundsOnHand !== left.roundsOnHand) {
return right.roundsOnHand - left.roundsOnHand;
}
const withRounds = enabledAmmoInventory
.filter((inventory) => inventory.roundsOnHand > 0)
.sort((left, right) => {
if (right.roundsOnHand !== left.roundsOnHand) {
return right.roundsOnHand - left.roundsOnHand;
}
return left.caliber.localeCompare(right.caliber);
});
const maxRounds = sortedInventory[0]?.roundsOnHand ?? 0;
return left.caliber.localeCompare(right.caliber);
});
const maxRounds = withRounds[0]?.roundsOnHand ?? 0;
return sortedInventory.map((inventory) => ({
return withRounds.map((inventory) => ({
...inventory,
widthPercent: maxRounds > 0 ? Math.max((inventory.roundsOnHand / maxRounds) * 100, inventory.roundsOnHand > 0 ? 8 : 0) : 0,
widthPercent: maxRounds > 0 ? Math.max((inventory.roundsOnHand / maxRounds) * 100, 8) : 0,
}));
}, [enabledAmmoInventory]);
const firearmCategoryCounts = useMemo(
@@ -1295,7 +1297,7 @@ export default function Home() {
</div>
{ammoChartData.length === 0 ? (
<p className="placeholder-copy">Enable calibers in Settings to see your ammo inventory chart.</p>
<p className="placeholder-copy">Add rounds to a caliber to see how your inventory stacks up.</p>
) : (
<div className="ammo-chart">
{ammoChartData.map((inventory) => (