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 [story, setStory] = useState(cache[id] || false);
|
||||||
const [error, setError] = useState('');
|
const [error, setError] = useState('');
|
||||||
const [pConv, setPConv] = useState([]);
|
const [pConv, setPConv] = useState([]);
|
||||||
|
const [copyButtonText, setCopyButtonText] = useState('Copy Link');
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
localForage.getItem(id)
|
localForage.getItem(id)
|
||||||
@@ -42,6 +43,16 @@ function Article({ cache }) {
|
|||||||
);
|
);
|
||||||
}, [id]);
|
}, [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) => {
|
const pConvert = (n) => {
|
||||||
setPConv(prevPConv => [...prevPConv, n]);
|
setPConv(prevPConv => [...prevPConv, n]);
|
||||||
};
|
};
|
||||||
@@ -72,6 +83,7 @@ function Article({ cache }) {
|
|||||||
</Helmet>
|
</Helmet>
|
||||||
|
|
||||||
<h1>{story.title}</h1>
|
<h1>{story.title}</h1>
|
||||||
|
<button onClick={copyLink}>{copyButtonText}</button>
|
||||||
|
|
||||||
<div className='info'>
|
<div className='info'>
|
||||||
Source: {sourceLink(story)}
|
Source: {sourceLink(story)}
|
||||||
|
|||||||
Reference in New Issue
Block a user