From 594656e66a234b8a8db11359cb6ca5b6857a5961 Mon Sep 17 00:00:00 2001 From: Julius Marminge <51714798+juliusmarminge@users.noreply.github.com> Date: Thu, 22 Sep 2022 00:41:40 +0200 Subject: [PATCH 1/3] add ci mode to tweetwall --- .github/workflows/ci.yml | 2 +- .../landingPage/tweets/tweetSlider.tsx | 2 +- .../landingPage/tweets/tweets.astro | 56 +++++-------------- .../components/landingPage/tweets/types.ts | 29 ++++++++++ 4 files changed, 45 insertions(+), 44 deletions(-) create mode 100644 www/src/components/landingPage/tweets/types.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fc0d3b4a6e..81409eb81b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -196,6 +196,6 @@ jobs: # No need to lint & typecheck here (which is otherwise done by the `check` script), done in above jobs - run: pnpm run --filter=www astro check - - run: pnpm turbo run --filter=www build + - run: MODE=CI pnpm turbo run --filter=www build env: PUBLIC_GITHUB_TOKEN: ${{ secrets.PUBLIC_GITHUB_TOKEN }} diff --git a/www/src/components/landingPage/tweets/tweetSlider.tsx b/www/src/components/landingPage/tweets/tweetSlider.tsx index 102839dca8..fa37cedc18 100644 --- a/www/src/components/landingPage/tweets/tweetSlider.tsx +++ b/www/src/components/landingPage/tweets/tweetSlider.tsx @@ -7,7 +7,7 @@ import "swiper/css/pagination"; import "swiper/css/autoplay"; import "../../../styles/swiper.css"; import { Autoplay, Pagination } from "swiper"; -import type { Tweet } from "./tweets.astro"; +import type { Tweet } from "./types"; export default function TweetSlider({ tweets }: { tweets: Tweet[] }) { return ( diff --git a/www/src/components/landingPage/tweets/tweets.astro b/www/src/components/landingPage/tweets/tweets.astro index 5ca5c008a8..900f901a75 100644 --- a/www/src/components/landingPage/tweets/tweets.astro +++ b/www/src/components/landingPage/tweets/tweets.astro @@ -1,35 +1,7 @@ --- import PageSection from "../pageSection.astro"; import TweetSlider from "./tweetSlider"; - -export interface Tweet { - id: string; - handle: string; - verified: boolean; - author: string; - avatar: string; - date: Date; - text: string; - likes: number; - retweets: number; - replies: number; - quotes: number; -} - -const dummy: Tweet = { - id: "1544909672137867264", - handle: "ajcwebdev", - author: "Anthony (ajcwebdev.x)", - verified: false, - avatar: - "https://pbs.twimg.com/profile_images/1549247631867711488/hK_Qr-Dx_normal.png", - date: new Date("2022-07-07T05:02:23.000Z"), - text: "Now that Blitz.js has pivoted and Bison has stagnated, create-t3-app will be the only framework to give Redwood a run for its money in the quest to build a legitimate fullstack React framework.", - likes: 18, - retweets: 3, - replies: 9, - quotes: 1, -}; +import { type Tweet, dummyTweet } from "./types"; const token = import.meta.env.TWITTER_BEARER_TOKEN; const fetchTweets = async (ids: string[]) => { @@ -48,9 +20,6 @@ const fetchTweets = async (ids: string[]) => { .then((res) => res.json()) .then((res) => { // TODO: Maybe use Twitter SDK to make this typesafe in the future? - if (!res.data) { - return [dummy]; - } return res.data.map((d: any) => { const user = res.includes.users.find((u: any) => u.id === d.author_id); return { @@ -69,17 +38,20 @@ const fetchTweets = async (ids: string[]) => { }); }); }; -if (!token) { - console.error("TWITTER_BEARER_TOKEN is not set"); -} -const tweets = await fetchTweets([ - "1544909672137867264", - "1553580714591158272", - "1553191258771841024", - "1571922865078915079", - "1570054715240763393", -]); +let tweets: Tweet[]; +if (import.meta.env.MODE === "CI" || !token) { + console.warn("No Twitter token found, using dummy data"); + tweets = [dummyTweet, dummyTweet, dummyTweet]; +} else { + tweets = await fetchTweets([ + "1544909672137867264", + "1553580714591158272", + "1553191258771841024", + "1571922865078915079", + "1570054715240763393", + ]); +} --- Date: Thu, 22 Sep 2022 00:43:35 +0200 Subject: [PATCH 2/3] add comment where to add more --- www/src/components/landingPage/tweets/tweets.astro | 1 + 1 file changed, 1 insertion(+) diff --git a/www/src/components/landingPage/tweets/tweets.astro b/www/src/components/landingPage/tweets/tweets.astro index 900f901a75..29f6ab4bc0 100644 --- a/www/src/components/landingPage/tweets/tweets.astro +++ b/www/src/components/landingPage/tweets/tweets.astro @@ -45,6 +45,7 @@ if (import.meta.env.MODE === "CI" || !token) { tweets = [dummyTweet, dummyTweet, dummyTweet]; } else { tweets = await fetchTweets([ + // Feel free to add more tweets here "1544909672137867264", "1553580714591158272", "1553191258771841024", From 61075e9b732c482320e4bd724fd319b6e9f5b43f Mon Sep 17 00:00:00 2001 From: Julius Marminge <51714798+juliusmarminge@users.noreply.github.com> Date: Thu, 22 Sep 2022 00:45:57 +0200 Subject: [PATCH 3/3] add error check --- www/src/components/landingPage/tweets/tweets.astro | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/www/src/components/landingPage/tweets/tweets.astro b/www/src/components/landingPage/tweets/tweets.astro index 29f6ab4bc0..1500b03274 100644 --- a/www/src/components/landingPage/tweets/tweets.astro +++ b/www/src/components/landingPage/tweets/tweets.astro @@ -17,7 +17,14 @@ const fetchTweets = async (ids: string[]) => { Authorization: `Bearer ${token}`, }, }) - .then((res) => res.json()) + .then((res) => { + if (res.ok) { + return res.json(); + } else { + console.error(res); + throw new Error("Failed to fetch tweets"); + } + }) .then((res) => { // TODO: Maybe use Twitter SDK to make this typesafe in the future? return res.data.map((d: any) => {