Last active
January 16, 2020 18:11
-
-
Save rylandg/774a7edfe6f2a28a36c17a461e9b9295 to your computer and use it in GitHub Desktop.
React parser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const parseOriginalTweet = (body) => { | |
const parser = new DOMParser(); | |
const doc = parser.parseFromString(body, 'text/html'); | |
return doc.querySelector('blockquote p').innerText || ''; | |
} | |
const RenderedTweet = ({ tweet }) => { | |
const now = new Date(); | |
const formattedTime = new Intl.DateTimeFormat(navigator.language, { | |
hour: 'numeric', | |
minute: 'numeric', | |
}).format(now); | |
const originalTweet = parseOriginalTweet(tweet.original_tweet); | |
return ( | |
<div> | |
<p> | |
<small> | |
{formattedTime} | |
</small> | |
</p> | |
<p> | |
Hidden | |
<a | |
target='_blank' | |
href={`https://twitter.com/${tweet.user.name}`} | |
> | |
@{tweet.user.name} | |
</a>’s reply to “${originalTweet}” | |
</p> | |
<p> | |
<a | |
target='_blank' | |
href={`https://twitter.com/${tweet.user.name}/status/${tweet.id_str}`} | |
class='tweet-link'> | |
Show reply on Twitter | |
</a> | |
</p> | |
</div> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment