Skip to content

Commit a7a2109

Browse files
authored
Merge pull request #182 from penumbra-zone/twitter-embed
TwitterEmbed component with @penumbra-zone timeline
2 parents 4a8a376 + e8adbb6 commit a7a2109

File tree

2 files changed

+86
-2
lines changed

2 files changed

+86
-2
lines changed

apps/web/src/app/(index)/page.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { dehydrate, HydrationBoundary } from "@tanstack/react-query";
1616
import { PreviewTable } from "@/components/PreviewTable";
1717
import { getBlocks } from "@/components/BlocksTable/getBlocks";
1818
import { getTransactions } from "@/components/TransactionsTable/getTransactions";
19+
import { TwitterEmbed } from "@/components/Embedded";
1920

2021

2122
interface CardProps {
@@ -87,7 +88,8 @@ export default function Home() {
8788
queryName={transactionsQuery}
8889
pageIndex={0}
8990
endpoint={transactionEndpoint}
90-
errorMessage={errorMessage}/>
91+
errorMessage={errorMessage}
92+
/>
9193
</HydrationBoundary>
9294
}
9395
/>
@@ -103,7 +105,8 @@ export default function Home() {
103105
queryName={blocksQuery}
104106
pageIndex={0}
105107
endpoint={blocksEndpoint}
106-
errorMessage={errorMessage}/>
108+
errorMessage={errorMessage}
109+
/>
107110
</HydrationBoundary>
108111
}
109112
/>
@@ -146,6 +149,9 @@ export default function Home() {
146149
className="w-[380px]"
147150
disabled={true}
148151
/>
152+
<div className="flex w-full items-center justify-center">
153+
<TwitterEmbed className="w-full sm:w-1/2"/>
154+
</div>
149155
</div>
150156
);
151157
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
"use client";
2+
3+
import Script from "next/script";
4+
import { Card, CardContent, CardHeader, CardTitle } from "../ui/card";
5+
import Link from "next/link";
6+
import { cn } from "@/lib/utils";
7+
import { FC, useEffect, useState } from "react";
8+
import { Skeleton } from "../ui/skeleton";
9+
10+
export const TwitterEmbed: FC<{ className?: string }> = ({ className }) => {
11+
const [loaded, setLoaded] = useState(false);
12+
13+
useEffect(() => {
14+
// This useEffect is basically a hack to allow somekind of UI indication that an element is being loaded.
15+
// Complete and totally inadequate hack to cope with the fact that twitter is a zombie social media company.
16+
// The timeline embed is completely broken and does not respect requests to limit the total number of posts loaded.
17+
// As a result, this embed adds an additional ***~20mb*** to the page load. This is why we delay it.
18+
function checkIframeLoaded() {
19+
// Get a handle to the iframe element
20+
const iframeDiv = document.getElementsByClassName("twitter-timeline-rendered");
21+
if (iframeDiv === undefined || iframeDiv.length === 0 ) {
22+
// Nothing loaded yet, wait.
23+
window.setTimeout(checkIframeLoaded, 1000);
24+
} else {
25+
// console.log(iframeDiv);
26+
// Check if the iframe element itself is loaded yet
27+
const iframeDoc = document.getElementById("twitter-widget-0");
28+
if (iframeDoc === undefined) {
29+
window.setTimeout(checkIframeLoaded, 1000);
30+
} else {
31+
// Completely arbitrary. Seems to work OK on simulated low band 4g connections.
32+
window.setTimeout(() => setLoaded(true), 5000);
33+
return;
34+
}
35+
}
36+
}
37+
checkIframeLoaded();
38+
}, []);
39+
40+
return (
41+
<Card className={cn("bg-card/60", className)}>
42+
<CardHeader className="flex justify-center">
43+
<CardTitle className="text-lg font-medium">
44+
<span className="font-mono font-bold">@penumbrazone</span> on Twitter
45+
</CardTitle>
46+
</CardHeader>
47+
<CardContent className="p-2 h-[320px]">
48+
<div className="grid grid-cols-1 grid-rows-1">
49+
<div className="col-span-1 row-span-1 col-start-1 row-start-1">
50+
<Link
51+
id="twitter-tl"
52+
className={cn("twitter-timeline")}
53+
data-tweet-limit={5}
54+
data-limit="5"
55+
data-height="300"
56+
data-chrome="noheader"
57+
href="https://twitter.com/penumbrazone?ref_src=twsrc%5Etfw"
58+
/>
59+
</div>
60+
{ !loaded ? (
61+
<div className="col-span-1 row-span-1 col-start-1 row-start-1">
62+
<Skeleton className={cn("w-full h-[300px] opacity-85")}/>
63+
</div>
64+
) : null}
65+
<Script
66+
async
67+
src="https://platform.twitter.com/widgets.js"
68+
strategy="lazyOnload"
69+
data-tweet-limit="5"
70+
data-limit="5"
71+
data-height="300"
72+
data-chrome="noheader"
73+
/>
74+
</div>
75+
</CardContent>
76+
</Card>
77+
);
78+
};

0 commit comments

Comments
 (0)