Move location changing to New
This commit is contained in:
parent
533ca9982d
commit
46ef45e732
2 changed files with 25 additions and 6 deletions
|
|
@ -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 => {
|
||||
|
|
|
|||
|
|
@ -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<Props> {}
|
||||
|
||||
const New: React.FC<NewProps> = (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 (
|
||||
<WeaponGrid userId={cookies.user ? cookies.user.user_id : ''} editable={true} exists={false} />
|
||||
<WeaponGrid
|
||||
userId={cookies.user ? cookies.user.user_id : ''}
|
||||
editable={true}
|
||||
exists={false}
|
||||
pushHistory={callback}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue