From 553f1a705346dd7c6291f158f479127064424dff Mon Sep 17 00:00:00 2001 From: Elliot Braem Date: Mon, 20 Jan 2025 13:48:53 -0700 Subject: [PATCH] last twitter id --- .gitignore | 2 +- backend/src/index.ts | 6 +++--- frontend/src/components/Settings.tsx | 5 +++-- frontend/src/lib/api.ts | 15 ++++++++++++++- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index f1b9c98..84eca3e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. # dependencies -/node_modules +**/node_modules /.pnp .pnp.js .yarn/install-state.gz diff --git a/backend/src/index.ts b/backend/src/index.ts index b174eb6..b28ee59 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -105,7 +105,7 @@ export async function main() { .use(swagger()) .get("/health", () => new Response("OK", { status: 200 })) // API Routes - .get("/api/last-tweet-id", () => { + .get("/api/twitter/last-tweet-id", () => { if (!twitterService) { throw new Error("Twitter service not available"); } @@ -113,7 +113,7 @@ export async function main() { return { lastTweetId }; }) .post( - "/api/last-tweet-id", + "/api/twitter/last-tweet-id", async ({ body }: { body: { tweetId: string } }) => { if (!twitterService) { throw new Error("Twitter service not available"); @@ -348,7 +348,7 @@ export async function main() { } // Start the application -logger.info("Starting Public Goods News Bot..."); +logger.info("Starting application..."); main().catch((error) => { logger.error("Unhandled Exception", error); process.exit(1); diff --git a/frontend/src/components/Settings.tsx b/frontend/src/components/Settings.tsx index 48572df..9cdd158 100644 --- a/frontend/src/components/Settings.tsx +++ b/frontend/src/components/Settings.tsx @@ -1,8 +1,9 @@ import { useState } from "react"; -import { useAppConfig, useUpdateLastTweetId, useClearCookies } from "../lib/api"; +import { useAppConfig, useUpdateLastTweetId, useClearCookies, useGetLastTweetId } from "../lib/api"; export default function Settings() { const { data: config } = useAppConfig(); + const { data: lastTweetData } = useGetLastTweetId(); const updateTweetId = useUpdateLastTweetId(); const [newTweetId, setNewTweetId] = useState(""); const [error, setError] = useState(null); @@ -38,7 +39,7 @@ export default function Settings() {

Current ID:

- {"Not set"} + {lastTweetData?.tweetId || "Not set"}
diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts index 9fda1f9..7b2b26a 100644 --- a/frontend/src/lib/api.ts +++ b/frontend/src/lib/api.ts @@ -64,10 +64,23 @@ export function useClearCookies() { }); } +export function useGetLastTweetId() { + return useQuery<{ tweetId: string }>({ + queryKey: ["last-tweet-id"], + queryFn: async () => { + const response = await fetch("/api/twitter/last-tweet-id"); + if (!response.ok) { + throw new Error("Failed to fetch last tweet ID"); + } + return response.json(); + }, + }); +} + export function useUpdateLastTweetId() { return useMutation({ mutationFn: async (tweetId: string) => { - const response = await fetch("/api/last-tweet-id", { + const response = await fetch("/api/twitter/last-tweet-id", { method: "POST", headers: { "Content-Type": "application/json",