diff --git a/src/components/TwitterEmbed.tsx b/src/components/TwitterEmbed.tsx deleted file mode 100644 index 1f9875f..0000000 --- a/src/components/TwitterEmbed.tsx +++ /dev/null @@ -1,59 +0,0 @@ -/** @jsx jsx */ -import { css, jsx } from '@emotion/core' -import { useRef, useState } from 'react' -import useTheme from 'src/hooks/useTheme' -import useInterval from 'src/hooks/useInterval' - -declare global { - interface Window { - twttr: any - __twttr: any - } -} - -const EMBED_DELAY = 500 - -const TwitterEmbed = ({ id, hideCard }: { id: string; hideCard?: boolean }) => { - const wrapperEl = useRef(null) - const [twitterLoaded, setTwitterLoaded] = useState(false) - const { spaces } = useTheme() - useInterval( - () => { - if ( - window.twttr && - window.twttr.widgets && - window.twttr.widgets.createTweet && - wrapperEl.current - ) { - wrapperEl.current.innerHTML = '' - window.twttr.widgets - .createTweet(id, wrapperEl.current, { - dnt: true, - cards: hideCard ? 'hidden' : undefined, - align: 'center', - conversation: 'none' - }) - .then(() => { - setTwitterLoaded(true) - }) - .catch(() => { - setTwitterLoaded(true) - }) - } - }, - twitterLoaded ? null : EMBED_DELAY - ) - return ( -
- ) -} - -export default TwitterEmbed diff --git a/src/hooks/useInterval.ts b/src/hooks/useInterval.ts deleted file mode 100644 index f770726..0000000 --- a/src/hooks/useInterval.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { useRef, useEffect } from 'react' - -// https://overreacted.io/making-setinterval-declarative-with-react-hooks/ -export default function useInterval( - callback: (...args: any[]) => void, - delay: number | null -) { - const savedCallback = useRef<(...args: any[]) => void>() - - // Remember the latest callback. - useEffect(() => { - savedCallback.current = callback - }, [callback]) - - // Set up the interval. - useEffect(() => { - function tick() { - savedCallback.current && savedCallback.current() - } - if (delay !== null) { - const id = setInterval(tick, delay) - return () => clearInterval(id) - } - }, [delay]) -} diff --git a/src/lib/reloadTwitterScript.ts b/src/lib/reloadTwitterScript.ts deleted file mode 100644 index 2badc9c..0000000 --- a/src/lib/reloadTwitterScript.ts +++ /dev/null @@ -1,12 +0,0 @@ -// Without this, page transition causes an error like: -// __twttr.callbacks.cb0 is not a function -const reloadTwitterScript = () => { - window.twttr = window.__twttr = {} - const scriptTag = document.createElement('script') - const firstScriptTag = document.getElementsByTagName('script')[0] - scriptTag.src = 'https://platform.twitter.com/widgets.js' - scriptTag.async = true - firstScriptTag.parentNode!.insertBefore(scriptTag, firstScriptTag) -} - -export default reloadTwitterScript diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx deleted file mode 100644 index 1aeafd9..0000000 --- a/src/pages/_app.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import App from 'next/app' -import Router from 'next/router' -import reloadTwitterScript from 'src/lib/reloadTwitterScript' - -Router.events.on('routeChangeStart', () => { - reloadTwitterScript() -}) - -export default App diff --git a/src/pages/generics.tsx b/src/pages/generics.tsx index ec9a4ad..3c541df 100644 --- a/src/pages/generics.tsx +++ b/src/pages/generics.tsx @@ -6,7 +6,6 @@ import CodeBlock from 'src/components/CodeBlock' import * as snippets from 'src/lib/snippets' import RunButtonText from 'src/components/RunButtonText' import TwitterLink from 'src/components/TwitterLink' -import TwitterEmbed from 'src/components/TwitterEmbed' import Emoji from 'src/components/Emoji' import { articlesData } from 'src/lib/articles' import { baseUrl } from 'src/lib/meta' @@ -797,11 +796,6 @@ const Page = () => ( .

-

- I’d love it if you could like or retweet - the tweet below! ↓ -

-

diff --git a/src/pages/refactor.tsx b/src/pages/refactor.tsx index d988991..b61374b 100644 --- a/src/pages/refactor.tsx +++ b/src/pages/refactor.tsx @@ -29,7 +29,6 @@ import { articlesData } from 'src/lib/articles' import { baseUrl } from 'src/lib/meta' import { SourceAvailableText } from 'src/components/GitHubButton' import TodoWithData from 'src/components/TodoWithData' -import TwitterEmbed from 'src/components/TwitterEmbed' const techniques = [ { @@ -1185,10 +1184,8 @@ const Page = () => ( url={`${baseUrl}/refactor`} > click here to tweet this article. - {' '} - Also, I’d love it if you could like or retweet the tweet below! ↓ +

- ), footer: { diff --git a/src/pages/todo.tsx b/src/pages/todo.tsx index 3ca1e6d..ac16da5 100644 --- a/src/pages/todo.tsx +++ b/src/pages/todo.tsx @@ -25,7 +25,6 @@ import { SourceAvailableText } from 'src/components/GitHubButton' import TwitterLink from 'src/components/TwitterLink' import { articlesData } from 'src/lib/articles' import { baseUrl } from 'src/lib/meta' -import TwitterEmbed from 'src/components/TwitterEmbed' const compileSuccess = 'Compiled successfully!' const section1 = 'Types, Read-only Properties, and Mapped Types' @@ -1970,11 +1969,6 @@ const Page = () => ( .

-

- I’d love it if you could like or retweet - the tweet below! ↓ -

- ), footer: {