twitter embed

This commit is contained in:
keyan 2022-01-20 14:22:10 -06:00
parent 4c72a69b6c
commit 977639ccb9
4 changed files with 39 additions and 0 deletions

View File

@ -7,6 +7,8 @@ import styles from '../styles/item.module.css'
import { NOFOLLOW_LIMIT } from '../lib/constants' import { NOFOLLOW_LIMIT } from '../lib/constants'
import { useMe } from './me' import { useMe } from './me'
import { Button } from 'react-bootstrap' import { Button } from 'react-bootstrap'
import TweetEmbed from 'react-tweet-embed'
import useDarkMode from 'use-dark-mode'
function BioItem ({ item, handleClick }) { function BioItem ({ item, handleClick }) {
const me = useMe() const me = useMe()
@ -30,10 +32,21 @@ function BioItem ({ item, handleClick }) {
) )
} }
function ItemEmbed ({ item }) {
const darkMode = useDarkMode()
const twitter = item.url?.match(/^https?:\/\/twitter\.com\/(?:#!\/)?\w+\/status(?:es)?\/(?<id>\d+)$/)
if (twitter?.groups?.id) {
return <TweetEmbed id={twitter.groups.id} options={{ width: '100%', theme: darkMode.value ? 'dark' : 'light' }} />
}
return null
}
function TopLevelItem ({ item }) { function TopLevelItem ({ item }) {
return ( return (
<Item item={item}> <Item item={item}>
{item.text && <ItemText item={item} />} {item.text && <ItemText item={item} />}
{item.url && <ItemEmbed item={item} />}
<Reply parentId={item.id} replyOpen /> <Reply parentId={item.id} replyOpen />
</Item> </Item>
) )

15
package-lock.json generated
View File

@ -41,6 +41,7 @@
"react-markdown": "^6.0.2", "react-markdown": "^6.0.2",
"react-syntax-highlighter": "^15.4.3", "react-syntax-highlighter": "^15.4.3",
"react-textarea-autosize": "^8.3.3", "react-textarea-autosize": "^8.3.3",
"react-tweet-embed": "^1.3.1",
"remark-gfm": "^1.0.0", "remark-gfm": "^1.0.0",
"remove-markdown": "^0.3.0", "remove-markdown": "^0.3.0",
"sass": "^1.32.8", "sass": "^1.32.8",
@ -8917,6 +8918,14 @@
"react-dom": ">=16.6.0" "react-dom": ">=16.6.0"
} }
}, },
"node_modules/react-tweet-embed": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/react-tweet-embed/-/react-tweet-embed-1.3.1.tgz",
"integrity": "sha512-qVAlb3/d3YhYHHB6Y3J/8OCY+a5KOzCnY/qUaBnK8qtEKXK9qWePlpGevDQgryWuKxggwxW1UHPLZ3VpPc7XUQ==",
"peerDependencies": {
"react": ">=15"
}
},
"node_modules/read-pkg": { "node_modules/read-pkg": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-1.1.0.tgz", "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-1.1.0.tgz",
@ -18741,6 +18750,12 @@
"prop-types": "^15.6.2" "prop-types": "^15.6.2"
} }
}, },
"react-tweet-embed": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/react-tweet-embed/-/react-tweet-embed-1.3.1.tgz",
"integrity": "sha512-qVAlb3/d3YhYHHB6Y3J/8OCY+a5KOzCnY/qUaBnK8qtEKXK9qWePlpGevDQgryWuKxggwxW1UHPLZ3VpPc7XUQ==",
"requires": {}
},
"read-pkg": { "read-pkg": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-1.1.0.tgz", "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-1.1.0.tgz",

View File

@ -42,6 +42,7 @@
"react-markdown": "^6.0.2", "react-markdown": "^6.0.2",
"react-syntax-highlighter": "^15.4.3", "react-syntax-highlighter": "^15.4.3",
"react-textarea-autosize": "^8.3.3", "react-textarea-autosize": "^8.3.3",
"react-tweet-embed": "^1.3.1",
"remark-gfm": "^1.0.0", "remark-gfm": "^1.0.0",
"remove-markdown": "^0.3.0", "remove-markdown": "^0.3.0",
"sass": "^1.32.8", "sass": "^1.32.8",

View File

@ -69,6 +69,16 @@ $tooltip-bg: #5c8001;
line-height: 1.2rem; line-height: 1.2rem;
} }
.twitter-tweet {
margin-top: 0 !important;
margin-bottom: 0 !important;
padding-right: 12px;
}
.twitter-tweet iframe {
width: 100% !important;
}
.custom-checkbox.custom-control-inline { .custom-checkbox.custom-control-inline {
margin-right: .5rem; margin-right: .5rem;
} }