mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-03-21 18:04:39 -05:00
Fix analyzer crash with invalid URL Closes #1291
This commit is contained in:
parent
a1d9add1ac
commit
b588be680c
|
|
@ -12,18 +12,20 @@ import { applySpecialEffects, SPECIAL_EFFECTS } from "./core/specialEffects";
|
|||
import { buildStats } from "./core/stats";
|
||||
import type { SpecialEffectType } from "./analyzer-types";
|
||||
import {
|
||||
buildIsEmpty,
|
||||
buildToAbilityPoints,
|
||||
serializeBuild,
|
||||
validatedBuildFromSearchParams,
|
||||
validatedWeaponIdFromSearchParams,
|
||||
} from "./core/utils";
|
||||
import invariant from "tiny-invariant";
|
||||
|
||||
export function useAnalyzeBuild() {
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
|
||||
const mainWeaponId = validatedWeaponIdFromSearchParams(searchParams);
|
||||
const build = validatedBuildFromSearchParams(searchParams);
|
||||
const build2 = validatedBuildFromSearchParams(searchParams, "build2");
|
||||
const build2 = validatedBuildFromSearchParams(searchParams, "build2", build);
|
||||
const ldeIntensity = validatedLdeIntensityFromSearchParams(searchParams);
|
||||
const effects = validatedEffectsFromSearchParams({ searchParams, build });
|
||||
const effects2 = validatedEffectsFromSearchParams({
|
||||
|
|
@ -32,6 +34,11 @@ export function useAnalyzeBuild() {
|
|||
});
|
||||
const focused = validatedFocusedFromSearchParams({ searchParams });
|
||||
|
||||
invariant(
|
||||
!(buildIsEmpty(build) && !buildIsEmpty(build2)),
|
||||
"build1 is empty but build2 isn't"
|
||||
);
|
||||
|
||||
const handleChange = ({
|
||||
newMainWeaponId = mainWeaponId,
|
||||
newBuild = build,
|
||||
|
|
|
|||
|
|
@ -191,13 +191,15 @@ function validateAbility(
|
|||
|
||||
export function validatedBuildFromSearchParams(
|
||||
searchParams: URLSearchParams,
|
||||
key = "build"
|
||||
key = "build",
|
||||
otherBuild?: BuildAbilitiesTupleWithUnknown
|
||||
): BuildAbilitiesTupleWithUnknown {
|
||||
const abilitiesArr = searchParams.get(key)
|
||||
? searchParams.get(key)?.split(",")
|
||||
: null;
|
||||
|
||||
if (!abilitiesArr) return EMPTY_BUILD;
|
||||
if (otherBuild && buildIsEmpty(otherBuild)) return EMPTY_BUILD;
|
||||
|
||||
try {
|
||||
return [
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user