- Introduced ExternalLink component to manage external links consistently across the application, enhancing user experience in Electron environments. - Updated About and UrlDisplay components to utilize ExternalLink for improved link handling and to ensure proper behavior in Electron. - Removed direct usage of Ant Design's Link component in favor of the new ExternalLink, streamlining the codebase and enhancing maintainability.
41 lines
901 B
JavaScript
41 lines
901 B
JavaScript
import { useContext } from 'react'
|
|
import PropTypes from 'prop-types'
|
|
import { Typography } from 'antd'
|
|
import { ElectronContext } from '../context/ElectronContext'
|
|
|
|
const { Link } = Typography
|
|
|
|
const ExternalLink = ({ href, children, onClick, ...props }) => {
|
|
const { isElectron, openExternalUrl } = useContext(ElectronContext)
|
|
|
|
const handleClick = (event) => {
|
|
onClick?.(event)
|
|
if (event.defaultPrevented) return
|
|
|
|
if (isElectron) {
|
|
event.preventDefault()
|
|
openExternalUrl(href)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<Link
|
|
{...props}
|
|
href={href}
|
|
target={isElectron ? undefined : '_blank'}
|
|
rel={isElectron ? undefined : 'noopener noreferrer'}
|
|
onClick={handleClick}
|
|
>
|
|
{children}
|
|
</Link>
|
|
)
|
|
}
|
|
|
|
ExternalLink.propTypes = {
|
|
href: PropTypes.string.isRequired,
|
|
children: PropTypes.node,
|
|
onClick: PropTypes.func
|
|
}
|
|
|
|
export default ExternalLink
|