diff --git a/app/routes/u.$identifier/builds/new.tsx b/app/routes/u.$identifier/builds/new.tsx index 7fd437e2a..798bc1895 100644 --- a/app/routes/u.$identifier/builds/new.tsx +++ b/app/routes/u.$identifier/builds/new.tsx @@ -296,7 +296,9 @@ function WeaponsSelector() { const [searchParams] = useSearchParams(); const { buildToEdit } = useLoaderData(); const { t } = useTranslation(["common", "weapons", "builds"]); - const [count, setCount] = React.useState(buildToEdit?.weapons.length ?? 1); + const [weapons, setWeapons] = React.useState( + buildToEdit?.weapons ?? [validatedWeaponIdFromSearchParams(searchParams)] + ); return (
@@ -304,7 +306,7 @@ function WeaponsSelector() { {t("builds:forms.weapons")}
- {new Array(count).fill(null).map((_, i) => { + {weapons.map((weapon, i) => { return (
@@ -312,25 +314,37 @@ function WeaponsSelector() { inputName="weapon" id="weapon" required - initialWeaponId={ - buildToEdit?.weapons[i] ?? - validatedWeaponIdFromSearchParams(searchParams) + onChange={(opt) => + opt && + setWeapons((weapons) => { + const newWeapons = [...weapons]; + newWeapons[i] = Number(opt.value) as MainWeaponId; + return newWeapons; + }) } + initialWeaponId={weapon ?? undefined} + clearsInputOnFocus />
- {i === count - 1 && ( + {i === weapons.length - 1 && ( <> - {count > 1 && ( + {weapons.length > 1 && (