From 64a821268326953adbb2cf8abb06ca3c5160ea80 Mon Sep 17 00:00:00 2001 From: "Kalle (Sendou)" <38327916+Sendouc@users.noreply.github.com> Date: Sat, 5 Sep 2020 11:55:07 +0300 Subject: [PATCH] fixes #92 --- .../components/analyzer/BuildAnalyzerPage.tsx | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/frontend-react/src/components/analyzer/BuildAnalyzerPage.tsx b/frontend-react/src/components/analyzer/BuildAnalyzerPage.tsx index 65e7d7214..a0597f176 100644 --- a/frontend-react/src/components/analyzer/BuildAnalyzerPage.tsx +++ b/frontend-react/src/components/analyzer/BuildAnalyzerPage.tsx @@ -1,6 +1,6 @@ import { Box, FormLabel, Switch, Badge, Flex } from "@chakra-ui/core" import { RouteComponentProps, useLocation } from "@reach/router" -import React, { useState, useContext } from "react" +import React, { useState, useContext, useEffect } from "react" import { Helmet } from "react-helmet-async" import useAbilityEffects from "../../hooks/useAbilityEffects" import { Ability, Weapon, AnalyzerBuild } from "../../types" @@ -27,7 +27,7 @@ const BuildAnalyzerPage: React.FC = () => { const { themeColor, grayWithShade } = useContext(MyThemeContext) const { t } = useTranslation() const location = useLocation() - const [build, setBuild] = useState(getBuildFromUrl()) + const [build, setBuild] = useState({ ...defaultBuild }) const [otherBuild, setOtherBuild] = useState({ ...defaultBuild, }) @@ -54,13 +54,16 @@ const BuildAnalyzerPage: React.FC = () => { ) function getBuildFromUrl() { - const buildToReturn = { ...defaultBuild } + const buildToReturn: AnalyzerBuild = { + ...defaultBuild, + weapon: "Splattershot Jr.", + } const decoded = new URLSearchParams(location.search) for (const [key, value] of decoded) { switch (key) { case "weapon": - setWeapon(value as Weapon) + buildToReturn.weapon = value as Weapon break case "headgear": case "clothing": @@ -73,6 +76,13 @@ const BuildAnalyzerPage: React.FC = () => { return buildToReturn } + useEffect(() => { + const { weapon, ...buildFromUrl } = getBuildFromUrl() + + setWeapon(weapon) + setBuild(buildFromUrl) + }, []) + return ( <>