Skip to content

Commit

Permalink
Redirect to twitter with pre-filled text directly instead of just a c…
Browse files Browse the repository at this point in the history
…opy.

A new feature to the existing code to improve user experience when clicking on the "#OpenSourceWithKunal" hashtag. Instead of copying the hashtag, it now redirects the user to Twitter with the hashtag pre-filled in the compose tweet text box.

## Proposed Changes

- Updated the code in the specified component to include the required functionality.
- Created a new function `handleClick` to handle the button click event and open a new browser window with the Twitter intent URL.
- Modified the button to trigger the `handleClick` function when clicked.
  • Loading branch information
HectorShaw authored Jun 29, 2023
1 parent 8dce645 commit 4e15e52
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/pages/OpenSourceCoursePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,25 @@ import OpenSourceHeroImg from '@/assets/courses/opensource.avif';

const OpenSourcePage = ({ content }) => {
const [tweetId, setTweetId] = useState(opensourcetweet);
const [copied, setCopied] = useState(false);
const copyHashtag = () => {
navigator.clipboard.writeText('#OpenSourceWithKunal');
setCopied(true);
};
useEffect(() => {
const timeout = setTimeout(() => {
if (copied) setCopied(false);
}, 1000);
// const [copied, setCopied] = useState(false);
// const copyHashtag = () => {
// navigator.clipboard.writeText('#OpenSourceWithKunal');
// setCopied(true);
// };
// useEffect(() => {
// const timeout = setTimeout(() => {
// if (copied) setCopied(false);
// }, 1000);

return () => {
clearTimeout(timeout);
};
}, [copied]);
// return () => {
// clearTimeout(timeout);
// };
// }, [copied]);

const handleClick = () => {
const twitterUrl = 'https://twitter.com/intent/tweet?text=%23OpenSourceWithKunal';
window.open(twitterUrl, '_blank');
};

return (
<>
Expand Down Expand Up @@ -173,7 +178,7 @@ const OpenSourcePage = ({ content }) => {
Use{' '}
<button
className='relative bg-purple-700/50'
onClick={copyHashtag}
onClick={handleClick}
>
#OpenSourceWithKunal
<div
Expand Down

0 comments on commit 4e15e52

Please sign in to comment.