Support ctrl or command click to open link in new tab
This commit is contained in:
parent
5152be57ba
commit
93bb1dd519
|
@ -65,7 +65,14 @@ export function ContractCard(props: {
|
||||||
{onClick ? (
|
{onClick ? (
|
||||||
<a
|
<a
|
||||||
className="absolute top-0 left-0 right-0 bottom-0"
|
className="absolute top-0 left-0 right-0 bottom-0"
|
||||||
onClick={onClick}
|
href={contractPath(contract)}
|
||||||
|
onClick={(e) => {
|
||||||
|
// Let the browser handle the link click (opens in new tab).
|
||||||
|
if (e.ctrlKey || e.metaKey) return
|
||||||
|
|
||||||
|
e.preventDefault()
|
||||||
|
onClick()
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<Link href={contractPath(contract)}>
|
<Link href={contractPath(contract)}>
|
||||||
|
|
|
@ -23,10 +23,7 @@ const Home = () => {
|
||||||
if (!username || !contractSlug) setContract(undefined)
|
if (!username || !contractSlug) setContract(undefined)
|
||||||
else {
|
else {
|
||||||
// Show contract if route is to a contract: '/[username]/[contractSlug]'.
|
// Show contract if route is to a contract: '/[username]/[contractSlug]'.
|
||||||
getContractFromSlug(contractSlug).then((c) => {
|
getContractFromSlug(contractSlug).then(setContract)
|
||||||
setContract(c)
|
|
||||||
window.scrollTo(0, 0)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,6 +32,10 @@ const Home = () => {
|
||||||
return () => window.removeEventListener('popstate', onBack)
|
return () => window.removeEventListener('popstate', onBack)
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (contract) window.scrollTo(0, 0)
|
||||||
|
}, [contract])
|
||||||
|
|
||||||
if (user === null) {
|
if (user === null) {
|
||||||
Router.replace('/')
|
Router.replace('/')
|
||||||
return <></>
|
return <></>
|
||||||
|
@ -55,7 +56,6 @@ const Home = () => {
|
||||||
setContract(c)
|
setContract(c)
|
||||||
// Update the url without switching pages in Nextjs.
|
// Update the url without switching pages in Nextjs.
|
||||||
history.pushState(null, '', `/${c.creatorUsername}/${c.slug}`)
|
history.pushState(null, '', `/${c.creatorUsername}/${c.slug}`)
|
||||||
window.scrollTo(0, 0)
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user