Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a button to copy pull URL #118

Merged
merged 3 commits into from
Nov 2, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
format
pvcnt committed Nov 2, 2024
commit 08753e885bd4312f16bee45c906202241d3997e6
26 changes: 13 additions & 13 deletions apps/webapp/src/components/CopyToClipboardIcon.tsx
Original file line number Diff line number Diff line change
@@ -3,25 +3,25 @@ import { useState } from "react";

export type Props = {
text: string;
title: string;
className?: string;
title: string;
className?: string;
};

export default function CopyToClipboardIcon({ text, title, className }: Props) {
const [clicked, setClicked] = useState(false);
const [clicked, setClicked] = useState(false);
const handleClick = async (e: React.MouseEvent) => {
e.stopPropagation();
await navigator.clipboard.writeText(text);
setClicked(true);
setTimeout(() => setClicked(false), 1500);
await navigator.clipboard.writeText(text);
setClicked(true);
setTimeout(() => setClicked(false), 1500);
};
return (
<IconWithTooltip
title={clicked ? "Copied!" : title}
icon={clicked ? "tick" : "clipboard"}
className={className}
size={14}
onClick={(e) => handleClick(e)}
/>
<IconWithTooltip
title={clicked ? "Copied!" : title}
icon={clicked ? "tick" : "clipboard"}
className={className}
size={14}
onClick={(e) => handleClick(e)}
/>
);
}
8 changes: 7 additions & 1 deletion apps/webapp/src/components/IconWithTooltip.tsx
Original file line number Diff line number Diff line change
@@ -21,7 +21,13 @@ export default function IconWithTooltip({
}: Props) {
return (
<Tooltip content={title} openOnTargetFocus={false} usePortal={false}>
<Icon icon={icon} color={color} size={size} className={className} onClick={onClick} />
<Icon
icon={icon}
color={color}
size={size}
className={className}
onClick={onClick}
/>
</Tooltip>
);
}
6 changes: 5 additions & 1 deletion apps/webapp/src/components/PullRow.tsx
Original file line number Diff line number Diff line change
@@ -135,7 +135,11 @@ export default function PullRow({ pull, onStar }: Props) {
<div className={styles.title}>
<span>{pull.title}</span>
{active && (
<CopyToClipboardIcon title="Copy URL to clipboard" text={pull.url} className={styles.copy}/>
<CopyToClipboardIcon
title="Copy URL to clipboard"
text={pull.url}
className={styles.copy}
/>
)}
</div>
<div className={styles.source}>
8 changes: 7 additions & 1 deletion apps/webapp/src/components/PullTable.tsx
Original file line number Diff line number Diff line change
@@ -32,7 +32,13 @@ export default function PullTable({ pulls, onStar }: Props) {
</tr>
</thead>
<tbody>
{pulls.map((pull, idx) => <PullRow key={idx} pull={pull} onStar={() => onStar && onStar(pull)} />)}
{pulls.map((pull, idx) => (
<PullRow
key={idx}
pull={pull}
onStar={() => onStar && onStar(pull)}
/>
))}
</tbody>
</HTMLTable>
);