the-hideout / tarkov-dev

The official site for tarkov.dev - A web app to track item prices, view trader barters, quests, maps, and much more!
https://tarkov.dev
MIT License
130 stars 48 forks source link

fix ammo checkboxes #894

Closed KrystianSkwierawski closed 3 months ago

KrystianSkwierawski commented 3 months ago

fix ammo checkboxes

Checkboxes don't seem to work as expected; the only checkboxes that function properly are those without spaces.

Description 🗒️

When a string like ".300 Blackout" is passed in a URL, spaces are typically encoded as "%20" for proper URL formatting, resulting in ".300%20Blackout". However, when attempting to compare this URL-encoded string with its plain text equivalent (i.e., without URL encoding), the comparison fails because the strings do not match exactly due to the presence of "%20" instead of a space.

To solve this issue, I think you need to decode the URL-encoded string before comparison. This can be achieved by using a URL decoding function which converts "%20" back to a space, making both strings identical for comparison purposes.

Here's a brief pseudo-code example for clarification:

// Assume currentAmmo is the URL-encoded string, and props.displayText is the plain string
var currentAmmo = decodeURIComponent(currentAmmoFromURL);
// currentAmmoFromURL would be ".300%20Blackout", and after decoding, currentAmmo would be ".300 Blackout"

if (currentAmmo === props.displayText) {
    // The comparison is true because both strings are now ".300 Blackout"
    console.log("Strings match.");
} else {
    console.log("Strings do not match.");
}
  useEffect(() => {
        if (currentAmmo) {
            setChecked(currentAmmo.split(',').includes(props.displayText)); // here was the problem with comparison
        }
        else {
            setChecked(false);
        }
    }, [currentAmmo, props.displayText]);

Examples 📸

Sorry for the quality, but you can just click the checkboxes by yourself :) 2024-03-21_22-05-30

Related Issues 🔗

Razzmatazzz commented 3 months ago

.unlock production

github-actions[bot] commented 3 months ago

Reference does not exist - https://docs.github.com/rest/git/refs#delete-a-reference

Razzmatazzz commented 3 months ago

Thanks for the fix!

Razzmatazzz commented 3 months ago

.deploy

github-actions[bot] commented 3 months ago

Deployment Triggered 🚀

Razzmatazzz, started a branch deployment to production

You can watch the progress here 🔗

Branch: 920c3d68a960cd16e6b3ddbc331f51a6fedfcab9

github-actions[bot] commented 3 months ago

Deployment Results ✅

Razzmatazzz successfully deployed branch 920c3d68a960cd16e6b3ddbc331f51a6fedfcab9 to production

Environment URL: tarkov.dev