Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Tweet previews to CastRow component #25

Merged
merged 4 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"react-intersection-observer": "^9.5.2",
"react-qr-code": "^2.0.11",
"react-router-dom": "^6.16.0",
"react-tweet": "^3.1.1",
"rollup": "^2.0.0",
"squire-rte": "^2.0.3",
"tailwindcss": "^3.3.3",
Expand Down
28 changes: 18 additions & 10 deletions src/common/components/CastRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import Linkify from "linkify-react";
import { isImageUrl } from '../helpers/text';
import OnchainEmbed from './Embeds/OnchainEmbed';
import WarpcastEmbed from './Embeds/WarpcastEmbed';
import TweetEmbed from './Embeds/TweetEmbed';
import { ErrorBoundary } from '@sentry/react';

interface CastRowProps {
cast: CastType;
Expand Down Expand Up @@ -203,15 +205,21 @@ export const CastRow = ({ cast, isSelected, showChannel, onSelect, isThreadView
// in future: twitter, youtube videos, spotify embeds, etc
const renderEmbeds = () => (
<div className="mt-4">
{map(cast.embeds, (embed) => {
if (embed.url.startsWith('"chain:')) {
return <OnchainEmbed url={embed.url} />
} else if (embed.url.startsWith('https://warpcast.com')) {
return <WarpcastEmbed url={embed.url} />
} else {
return null;
}
})}
<ErrorBoundary>
{map(cast.embeds, (embed) => {
const url = embed.url
if (url.startsWith('"chain:')) {
return <OnchainEmbed url={url} />
} else if (url.startsWith('https://warpcast.com')) {
return <WarpcastEmbed url={url} />
} else if ((url.includes('twitter.com') || url.startsWith('https://x.com')) && url.includes('status/')) {
const tweetId = url.split('/').pop();
return tweetId ? <TweetEmbed tweetId={tweetId} /> : null;
} else {
return null;
}
})}
</ErrorBoundary>
</div>);

const channel = showChannel ? getChannelForParentUrl(cast.parent_url) : null;
Expand All @@ -226,7 +234,7 @@ export const CastRow = ({ cast, isSelected, showChannel, onSelect, isThreadView
className={classNames(
isSelected ? "bg-gray-900/20" : "hover:bg-gray-900/30 cursor-pointer",
isThreadView ? "" : (isSelected ? "border-l-2 border-gray-100/80" : "border-l-2 border-transparent"),
"px-5 py-4 grow rounded-r-sm"
"lg:px-5 py-4 grow rounded-r-sm"
)}>
<div className="flex items-top gap-x-4">
{!isThreadView && (
Expand Down
16 changes: 16 additions & 0 deletions src/common/components/Embeds/TweetEmbed.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';
import { Tweet } from 'react-tweet'

interface TweetEmbedProps {
tweetId: string;
}

const TweetEmbed: React.FC<TweetEmbedProps> = ({ tweetId }) => {
return (
<div className="dark">
<Tweet id={tweetId} />
</div>
);
};

export default TweetEmbed;
48 changes: 46 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,13 @@
dependencies:
regenerator-runtime "^0.14.0"

"@babel/runtime@^7.21.0":
version "7.23.1"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.23.1.tgz#72741dc4d413338a91dcb044a86f3c0bc402646d"
integrity sha512-hC2v6p8ZSI/W0HUzh3V8C5g+NwSKzKPtJwSpTjwl0o297GP9+ZLQSkdvHz46CM3LqyoXxq+5G9komY+eSqSO0g==
dependencies:
regenerator-runtime "^0.14.0"

"@babel/template@^7.22.15", "@babel/template@^7.22.5":
version "7.22.15"
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.22.15.tgz#09576efc3830f0430f4548ef971dde1350ef2f38"
Expand Down Expand Up @@ -1809,6 +1816,13 @@
"@supabase/realtime-js" "^2.7.4"
"@supabase/storage-js" "^2.5.4"

"@swc/helpers@^0.5.1":
version "0.5.2"
resolved "https://registry.yarnpkg.com/@swc/helpers/-/helpers-0.5.2.tgz#85ea0c76450b61ad7d10a37050289eded783c27d"
integrity sha512-E4KcWTpoLHqwPHLxidpOqQbcrZVgi0rsmmZXUle1jXmJfuIf/UWpczUJ7MZZ5tlxytgJXyp0w4PGkkeLiuIdZw==
dependencies:
tslib "^2.4.0"

"@tailwindcss/forms@^0.5.4":
version "0.5.6"
resolved "https://registry.yarnpkg.com/@tailwindcss/forms/-/forms-0.5.6.tgz#29c6c2b032b363e0c5110efed1499867f6d7e868"
Expand Down Expand Up @@ -2553,6 +2567,11 @@ cliui@^8.0.1:
strip-ansi "^6.0.1"
wrap-ansi "^7.0.0"

clsx@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/clsx/-/clsx-1.2.1.tgz#0ddc4a20a549b59c93a4116bb26f5294ca17dc12"
integrity sha512-EcR6r5a8bj6pu3ycsa/E/cKVGuTgZJZdsyUYHOksG/UHIiKfjxzRxYJpyVBwYaQeOvghal9fcc4PidlgzugAQg==

color-convert@^1.9.0:
version "1.9.3"
resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.3.tgz#bb71850690e1f136567de629d2d5471deda4c1e8"
Expand Down Expand Up @@ -2690,6 +2709,13 @@ d@1, d@^1.0.1:
es5-ext "^0.10.50"
type "^1.0.1"

date-fns@^2.30.0:
version "2.30.0"
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.30.0.tgz#f367e644839ff57894ec6ac480de40cae4b0f4d0"
integrity sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw==
dependencies:
"@babel/runtime" "^7.21.0"

debug@4, debug@^4.1.0, debug@^4.1.1, debug@^4.3.2, debug@^4.3.4:
version "4.3.4"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865"
Expand Down Expand Up @@ -4769,6 +4795,16 @@ react-style-singleton@^2.2.1:
invariant "^2.2.4"
tslib "^2.0.0"

react-tweet@^3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/react-tweet/-/react-tweet-3.1.1.tgz#dc9a3a5dfef5e6290698df23c459e805ffebe5b3"
integrity sha512-8GQLa5y0G56kvGQkN7OiaKkjFAhWYVdyFq62ioY2qVtpMrjchVU+3KnqneCyp0+BemOQZkg6WWp/qoCNeEMH6A==
dependencies:
"@swc/helpers" "^0.5.1"
clsx "^1.2.1"
date-fns "^2.30.0"
swr "^2.2.0"

react@18.2.0, react@^18.2.0:
version "18.2.0"
resolved "https://registry.yarnpkg.com/react/-/react-18.2.0.tgz#555bd98592883255fa00de14f1151a917b5d77d5"
Expand Down Expand Up @@ -5131,6 +5167,14 @@ supports-preserve-symlinks-flag@^1.0.0:
resolved "https://registry.yarnpkg.com/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz#6eda4bd344a3c94aea376d4cc31bc77311039e09"
integrity sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==

swr@^2.2.0:
version "2.2.4"
resolved "https://registry.yarnpkg.com/swr/-/swr-2.2.4.tgz#03ec4c56019902fbdc904d78544bd7a9a6fa3f07"
integrity sha512-njiZ/4RiIhoOlAaLYDqwz5qH/KZXVilRLvomrx83HjzCWTfa+InyfAjv05PSFxnmLzZkNO9ZfvgoqzAaEI4sGQ==
dependencies:
client-only "^0.0.1"
use-sync-external-store "^1.2.0"

tabbable@^6.2.0:
version "6.2.0"
resolved "https://registry.yarnpkg.com/tabbable/-/tabbable-6.2.0.tgz#732fb62bc0175cfcec257330be187dcfba1f3b97"
Expand Down Expand Up @@ -5293,7 +5337,7 @@ tslib@2.4.0:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.4.0.tgz#7cecaa7f073ce680a05847aa77be941098f36dc3"
integrity sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==

tslib@^2.0.0, tslib@^2.1.0, "tslib@^2.4.1 || ^1.9.3":
tslib@^2.0.0, tslib@^2.1.0, tslib@^2.4.0, "tslib@^2.4.1 || ^1.9.3":
version "2.6.2"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.2.tgz#703ac29425e7b37cd6fd456e92404d46d1f3e4ae"
integrity sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==
Expand Down Expand Up @@ -5426,7 +5470,7 @@ use-sidecar@^1.1.2:
detect-node-es "^1.1.0"
tslib "^2.0.0"

use-sync-external-store@1.2.0:
use-sync-external-store@1.2.0, use-sync-external-store@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/use-sync-external-store/-/use-sync-external-store-1.2.0.tgz#7dbefd6ef3fe4e767a0cf5d7287aacfb5846928a"
integrity sha512-eEgnFxGQ1Ife9bzYs6VLi8/4X6CObHMw9Qr9tPY43iKwsPw8xE8+EFsf/2cFZ5S3esXgpWgtSCtLNS41F+sKPA==
Expand Down