Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a toggle to filter out ammo types you can't buy based on your trader levels #930

Merged
merged 7 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

## Opening a Pull Request 🌟

If you have a fix for a bug or a feature request, follow the flow below to purpose your change
If you have a fix for a bug or a feature request, follow the flow below to propose your change

> If you are new to creating pull requests from a repository fork, check out this [guide](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork)

Expand Down
31 changes: 28 additions & 3 deletions src/pages/ammo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { formatCaliber } from '../../modules/format-ammo.mjs';
import symbols from '../../symbols.json';

import './index.css';
import { useSelector } from 'react-redux';
import { selectAllTraders } from '../../features/settings/settingsSlice.js';

const MAX_DAMAGE = 170;
const MAX_PENETRATION = 70;
Expand All @@ -34,6 +36,7 @@ const skipTypes = [
];

function Ammo() {
const allTraders = useSelector(selectAllTraders);
const { currentAmmo } = useParams();
let currentAmmoList = useMemo(() => [], []);
let redirect = false;
Expand All @@ -54,7 +57,8 @@ function Ammo() {
navigate(`/ammo/${currentAmmoList.join(',')}`);
}
}, [redirect, currentAmmoList, navigate]);


const [showOnlyTraderAmmo, setShowOnlyTraderAmmo] = useState(false);
const [selectedLegendName, setSelectedLegendName] = useState(currentAmmoList);
const [showAllTraderPrices, setShowAllTraderPrices] = useState(false);
const [useAllProjectileDamage, setUseAllProjectileDamage] = useState(false);
Expand Down Expand Up @@ -158,6 +162,16 @@ function Ammo() {
!selectedLegendName ||
selectedLegendName.length === 0 ||
selectedLegendName.includes(ammo.type),
).filter(ammo => {
if (showOnlyTraderAmmo) {
if (!ammo.buyFor.some(buyForEntry =>
buyForEntry.vendor.normalizedName !== 'flea-market' &&
buyForEntry.vendor.minTraderLevel <= allTraders[buyForEntry.vendor.normalizedName])
)
return false;
}
return true;
}
).filter(ammo => {
if (minPen === 0 && maxPen === 60) {
return true;
Expand Down Expand Up @@ -194,9 +208,8 @@ function Ammo() {
chartName: `${ammo.chartName} (${ammo.fragmentationChance})`,
};
});

return returnData;
}, [selectedLegendName, shiftPress, ammoData, minPen, maxPen]);
}, [selectedLegendName, shiftPress, ammoData, minPen, maxPen, showOnlyTraderAmmo, allTraders]);

const handleLegendClick = useCallback(
(event, { datum: { name } }) => {
Expand Down Expand Up @@ -269,6 +282,18 @@ function Ammo() {
</>
}
/>
<ToggleFilter
checked={showOnlyTraderAmmo}
label={t('Trader Ammo')}
onChange={(e) =>
setShowOnlyTraderAmmo(!showOnlyTraderAmmo)
}
tooltipContent={
<>
{t('Only show ammo available from traders on your settings')}
</>
}
/>
<ToggleFilter
checked={showAllTraderPrices}
label={t('Ignore settings')}
Expand Down
4 changes: 3 additions & 1 deletion src/translations/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -600,5 +600,7 @@
"{{count}} days_other": "{{count}} days",
"Wipe Length": "Wipe Length",
"wipe-length-description": "Get the latest information on the average wipe length in Escape from Tarkov. Find out how long wipes typically last, and prepare for the next wipe.",
"Average Wipe Length among last 6 wipes:": "Average Wipe Length among last 6 wipes:"
"Average Wipe Length among last 6 wipes:": "Average Wipe Length among last 6 wipes:",
"Trader Ammo": "Trader Ammo",
"Only show ammo available from traders on your settings": "Only show ammo available from traders on your settings"
}