Skip to content

Commit

Permalink
[maud] Replace permalink with ours
Browse files Browse the repository at this point in the history
Signed-off-by: lindwurm <lindwurm.q@gmail.com>
  • Loading branch information
lindwurm committed Dec 8, 2023
1 parent 80b732d commit fd6ccf0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 40 deletions.
40 changes: 0 additions & 40 deletions app/javascript/mastodon/components/permalink.js

This file was deleted.

41 changes: 41 additions & 0 deletions app/javascript/mastodon/components/permalink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from 'react';
import { useHistory } from 'react-router';

interface Props
extends React.PropsWithChildren<React.HTMLAttributes<HTMLAnchorElement>> {
className?: string;
href: string;
to: string;
onInterceptClick: () => boolean;
}

const Permalink: React.FC<Props> = (inProps) => {
const { className, href, to, onInterceptClick, children, ...props } = inProps;
const history = useHistory();

const linkClickHandler = (e: React.MouseEvent<HTMLAnchorElement>) => {
if (onInterceptClick && onInterceptClick()) {
e.preventDefault();
return;
}

if (e.button === 0 && !(e.ctrlKey || e.metaKey)) {
e.preventDefault();
history.push(to);
}
};

return (
<a
target="_blank"
href={href}
onClick={linkClickHandler}
{...props}
className={`permalink${className ? ' ' + className : ''}`}
>
{children}
</a>
);
};

export default Permalink;

0 comments on commit fd6ccf0

Please sign in to comment.