From 46ef45e7326bdb54cc30d8953d82439077b98c08 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Fri, 25 Sep 2020 05:25:04 -0700 Subject: [PATCH] Move location changing to New --- src/components/WeaponGrid/WeaponGrid.tsx | 11 ++++++++--- src/routes/New/New.tsx | 20 +++++++++++++++++--- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/components/WeaponGrid/WeaponGrid.tsx b/src/components/WeaponGrid/WeaponGrid.tsx index 4933f943..94735afd 100644 --- a/src/components/WeaponGrid/WeaponGrid.tsx +++ b/src/components/WeaponGrid/WeaponGrid.tsx @@ -1,5 +1,7 @@ import React, { useEffect, useState } from 'react' import api from '~utils/api' +import history from '~utils/history' + import WeaponUnit from '~components/WeaponUnit/WeaponUnit' import Button from '~components/Button/Button' @@ -14,6 +16,7 @@ interface Props { editable: boolean exists: boolean found?: boolean + pushHistory?: (path: string) => void } type GridArray = { [key: number]: Weapon } @@ -61,9 +64,11 @@ const WeaponGrid = (props: Props) => { .then(response => { return response.data.party }) - .then(party => { - window.history.replaceState(null, `Grid Tool`, `/p/${party.shortcode}`) - + .then(party => { + if (props.pushHistory) { + props.pushHistory(`/p/${party.shortcode}`) + } + return party.id }) .then(partyId => { diff --git a/src/routes/New/New.tsx b/src/routes/New/New.tsx index 28c7cfd9..f2f29a09 100644 --- a/src/routes/New/New.tsx +++ b/src/routes/New/New.tsx @@ -1,13 +1,27 @@ import React from 'react' +import { RouteComponentProps } from 'react-router-dom' import { useCookies } from 'react-cookie' -import SearchModal from '../../components/SearchModal/SearchModal' import WeaponGrid from '../../components/WeaponGrid/WeaponGrid' -const New = () => { +interface Props {} +interface NewProps extends RouteComponentProps {} + +const New: React.FC = (props: NewProps) => { const [cookies, setCookie] = useCookies(['userId']) + function callback(path: string) { + // This is scuffed, how do we do this natively? + window.history.replaceState(null, `Grid Tool`, `${path}`) + + } + return ( - + ) }