Skip to content

Commit

Permalink
last twitter id
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotBraem committed Jan 20, 2025
1 parent d6b409c commit 553f1a7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ 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");
}
const lastTweetId = twitterService.getLastCheckedTweetId();
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");
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/components/Settings.tsx
Original file line number Diff line number Diff line change
@@ -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<string | null>(null);
Expand Down Expand Up @@ -38,7 +39,7 @@ export default function Settings() {
<div>
<p className="text-gray-600 mb-2">Current ID:</p>
<code className="bg-gray-50 p-2 border-2 border-black block font-mono">
{"Not set"}
{lastTweetData?.tweetId || "Not set"}
</code>
</div>

Expand Down
15 changes: 14 additions & 1 deletion frontend/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 553f1a7

Please sign in to comment.