Fix New button
This commit is contained in:
parent
2e796c3647
commit
533ca9982d
1 changed files with 20 additions and 5 deletions
|
|
@ -1,13 +1,19 @@
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
import { RouteComponentProps, useLocation, withRouter } from 'react-router-dom'
|
||||||
import { useCookies } from 'react-cookie'
|
import { useCookies } from 'react-cookie'
|
||||||
|
import history from '~utils/history'
|
||||||
|
|
||||||
import Button from '~components/Button/Button'
|
import Button from '~components/Button/Button'
|
||||||
import UnauthMenu from '~components/UnauthMenu/UnauthMenu'
|
import UnauthMenu from '~components/UnauthMenu/UnauthMenu'
|
||||||
|
|
||||||
import './Header.css'
|
import './Header.css'
|
||||||
|
|
||||||
const Header = () => {
|
interface Props {}
|
||||||
|
interface HeaderProps extends RouteComponentProps<Props> {}
|
||||||
|
|
||||||
|
const Header: React.FC<HeaderProps> = (props: HeaderProps) => {
|
||||||
const [cookies, setCookie] = useCookies(['user'])
|
const [cookies, setCookie] = useCookies(['user'])
|
||||||
|
let location = useLocation()
|
||||||
|
|
||||||
function copyToClipboard() {
|
function copyToClipboard() {
|
||||||
const el = document.createElement('input')
|
const el = document.createElement('input')
|
||||||
|
|
@ -20,6 +26,15 @@ const Header = () => {
|
||||||
el.remove()
|
el.remove()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function newParty() {
|
||||||
|
if (props.history.location.pathname === '/') {
|
||||||
|
window.history.replaceState(null, `Grid Tool`, `/`)
|
||||||
|
props.history.go(0)
|
||||||
|
} else {
|
||||||
|
props.history.push('/')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (cookies.user != null) {
|
if (cookies.user != null) {
|
||||||
console.log(`Logged in as user "${cookies.user.username}"`)
|
console.log(`Logged in as user "${cookies.user.username}"`)
|
||||||
}
|
}
|
||||||
|
|
@ -34,10 +49,10 @@ const Header = () => {
|
||||||
</div>
|
</div>
|
||||||
<div className="push" />
|
<div className="push" />
|
||||||
<div className="right">
|
<div className="right">
|
||||||
<Button type="link" click={this.copyToClipboard}>Copy link</Button>
|
{ (location.pathname !== '/') ?
|
||||||
<Link to='/'>
|
<Button type="link" click={copyToClipboard}>Copy link</Button> : ''
|
||||||
<Button type="new">New</Button>
|
}
|
||||||
</Link>
|
<Button type="new" click={newParty}>New</Button>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue