From 6423833ea4b9e40baaecb3f43f3035a82f97edc2 Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Wed, 10 Aug 2022 18:06:33 -0700 Subject: [PATCH] Prevent tweetId from getting interpreted as a number --- common/util/tweet-embed.tsx | 16 +++++++++++----- web/components/editor/tweetModal.tsx | 7 ++++--- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/common/util/tweet-embed.tsx b/common/util/tweet-embed.tsx index 5dc7d628..91b2fa65 100644 --- a/common/util/tweet-embed.tsx +++ b/common/util/tweet-embed.tsx @@ -1,13 +1,19 @@ import { NodeViewWrapper } from '@tiptap/react' import { TwitterTweetEmbed } from 'react-twitter-embed' -export default function WrappedTwitterTweetEmbed(props: any): JSX.Element { - console.log('wtwe props', props.node.attrs) +export default function WrappedTwitterTweetEmbed(props: { + node: { + attrs: { + tweetId: string + } + } +}): JSX.Element { + // Remove the leading 't' from the tweet id + const tweetId = props.node.attrs.tweetId.slice(1) + return ( - + ) } diff --git a/web/components/editor/tweetModal.tsx b/web/components/editor/tweetModal.tsx index e5983ad9..a6fac5db 100644 --- a/web/components/editor/tweetModal.tsx +++ b/web/components/editor/tweetModal.tsx @@ -22,8 +22,9 @@ export function TweetModal(props: { const { editor, open, setOpen } = props const [input, setInput] = useState('') const tweetId = getTweetId(input) - const tweetCode = `` - console.log('tweetCode', tweetCode) + // Append a leading 't', to prevent tweetId from being interpreted as a number. + // If it's a number, there may be numeric precision issues. + const tweetCode = `` return ( @@ -32,7 +33,7 @@ export function TweetModal(props: { htmlFor="embed" className="block text-sm font-medium text-gray-700" > - Tweet link + Paste a tweet link