From 9a027af98ed675f6d617d573a5fe6e663eb7cc4b Mon Sep 17 00:00:00 2001 From: ejmg Date: Wed, 28 Aug 2024 11:58:10 -0500 Subject: [PATCH 1/6] TwitterEmbed component with @penumbra-zone timeline --- apps/web/src/app/(index)/page.tsx | 10 ++- apps/web/src/app/layout.tsx | 2 +- apps/web/src/components/Embedded/index.tsx | 76 ++++++++++++++++++++++ 3 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 apps/web/src/components/Embedded/index.tsx diff --git a/apps/web/src/app/(index)/page.tsx b/apps/web/src/app/(index)/page.tsx index 4c1f39c..154db2a 100644 --- a/apps/web/src/app/(index)/page.tsx +++ b/apps/web/src/app/(index)/page.tsx @@ -16,6 +16,7 @@ import { dehydrate, HydrationBoundary } from "@tanstack/react-query"; import { PreviewTable } from "@/components/PreviewTable"; import { getBlocks } from "@/components/BlocksTable/getBlocks"; import { getTransactions } from "@/components/TransactionsTable/getTransactions"; +import { TwitterEmbed } from "@/components/Embedded"; interface CardProps { @@ -87,7 +88,8 @@ export default function Home() { queryName={transactionsQuery} pageIndex={0} endpoint={transactionEndpoint} - errorMessage={errorMessage}/> + errorMessage={errorMessage} + /> } /> @@ -103,7 +105,8 @@ export default function Home() { queryName={blocksQuery} pageIndex={0} endpoint={blocksEndpoint} - errorMessage={errorMessage}/> + errorMessage={errorMessage} + /> } /> @@ -146,6 +149,9 @@ export default function Home() { className="w-[380px]" disabled={true} /> +
+ +
); } diff --git a/apps/web/src/app/layout.tsx b/apps/web/src/app/layout.tsx index e564a4e..8a97ea6 100644 --- a/apps/web/src/app/layout.tsx +++ b/apps/web/src/app/layout.tsx @@ -14,7 +14,7 @@ export const metadata: Metadata = { description: "A block explorer for Penumbra.", }; -export default function RootLayout({ +export default async function RootLayout({ children, }: { children: React.ReactNode; diff --git a/apps/web/src/components/Embedded/index.tsx b/apps/web/src/components/Embedded/index.tsx new file mode 100644 index 0000000..7db00ab --- /dev/null +++ b/apps/web/src/components/Embedded/index.tsx @@ -0,0 +1,76 @@ +"use client"; + +import Script from "next/script"; +import { Card, CardContent, CardHeader, CardTitle } from "../ui/card"; +import Link from "next/link"; +import { cn } from "@/lib/utils"; +import { FC, useEffect, useState } from "react"; +import { Skeleton } from "../ui/skeleton"; + +export const TwitterEmbed: FC<{ className?: string }> = ({ className }) => { + const [loaded, setLoaded] = useState(false); + + useEffect(() => { + // This useEffect is basically a hack to allow somekind of UI indication that an element is being loaded. + // Complete and totally inadequate hack to cope with the fact that twitter is a zombie social media company. + // The timeline embed is completely broken and does not respect requests to limit the total number of posts loaded. + // As a result, this embed adds an additional ***~20mb*** to the page load. This is why we delay it. + function checkIframeLoaded() { + // Get a handle to the iframe element + const iframeDiv = document.getElementsByClassName("twitter-timeline-rendered"); + if (iframeDiv === undefined || iframeDiv.length === 0 ) { + // Nothing loaded yet, wait. + window.setTimeout(checkIframeLoaded, 1000); + } else { + // console.log(iframeDiv); + // Check if the iframe element itself is loaded yet + const iframeDoc = document.getElementById("twitter-widget-0"); + if (iframeDoc === undefined) { + window.setTimeout(checkIframeLoaded, 1000); + } else { + // Completely arbitrary. Seems to work OK on simulated low band 4g connections. + window.setTimeout(() => setLoaded(true), 5000); + return; + } + } + } + checkIframeLoaded(); + }, []); + + return ( + + + + @penumbrazone on Twitter + + + +
+
+ +
+
+ { !loaded ? : null} +
+