Make copy link component copy better URL
This commit is contained in:
parent
a1d89fcc49
commit
8bd4764183
|
@ -1,5 +1,4 @@
|
||||||
import React, { useState } from 'react'
|
import React, { useState } from 'react'
|
||||||
import { ENV_CONFIG } from 'common/envs/constants'
|
|
||||||
import { copyToClipboard } from 'web/lib/util/copy'
|
import { copyToClipboard } from 'web/lib/util/copy'
|
||||||
import { DateTimeTooltip } from 'web/components/datetime-tooltip'
|
import { DateTimeTooltip } from 'web/components/datetime-tooltip'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
|
@ -21,9 +20,10 @@ export function CopyLinkDateTimeComponent(props: {
|
||||||
event: React.MouseEvent<HTMLAnchorElement, MouseEvent>
|
event: React.MouseEvent<HTMLAnchorElement, MouseEvent>
|
||||||
) {
|
) {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
const elementLocation = `https://${ENV_CONFIG.domain}/${prefix}/${slug}#${elementId}`
|
const commentUrl = new URL(window.location.href)
|
||||||
|
commentUrl.pathname = `/${prefix}/${slug}`
|
||||||
copyToClipboard(elementLocation)
|
commentUrl.hash = elementId
|
||||||
|
copyToClipboard(commentUrl.toString())
|
||||||
setShowToast(true)
|
setShowToast(true)
|
||||||
setTimeout(() => setShowToast(false), 2000)
|
setTimeout(() => setShowToast(false), 2000)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user