feat: Add button to copy article title and URL to clipboard
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
@@ -12,6 +12,7 @@ function Article({ cache }) {
|
||||
const [story, setStory] = useState(cache[id] || false);
|
||||
const [error, setError] = useState('');
|
||||
const [pConv, setPConv] = useState([]);
|
||||
const [copyButtonText, setCopyButtonText] = useState('Copy Link');
|
||||
|
||||
useEffect(() => {
|
||||
localForage.getItem(id)
|
||||
@@ -42,6 +43,16 @@ function Article({ cache }) {
|
||||
);
|
||||
}, [id]);
|
||||
|
||||
const copyLink = () => {
|
||||
navigator.clipboard.writeText(`${story.title} ${window.location.href}`).then(() => {
|
||||
setCopyButtonText('Copied!');
|
||||
setTimeout(() => setCopyButtonText('Copy Link'), 2000);
|
||||
}, () => {
|
||||
setCopyButtonText('Error!');
|
||||
setTimeout(() => setCopyButtonText('Copy Link'), 2000);
|
||||
});
|
||||
};
|
||||
|
||||
const pConvert = (n) => {
|
||||
setPConv(prevPConv => [...prevPConv, n]);
|
||||
};
|
||||
@@ -72,6 +83,7 @@ function Article({ cache }) {
|
||||
</Helmet>
|
||||
|
||||
<h1>{story.title}</h1>
|
||||
<button onClick={copyLink}>{copyButtonText}</button>
|
||||
|
||||
<div className='info'>
|
||||
Source: {sourceLink(story)}
|
||||
|
||||
Reference in New Issue
Block a user