Skip to content

Commit

Permalink
Crawler debug info added to home page
Browse files Browse the repository at this point in the history
  • Loading branch information
dorukgezici committed Aug 5, 2023
1 parent b2bd635 commit b7db933
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 9 deletions.
5 changes: 5 additions & 0 deletions backend/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ async def health():
@app.get("/feeds")
def read_feeds() -> List[dict]:
return fetch_all(db_feeds)


@app.get("/keywords")
def read_keywords() -> List[dict]:
return fetch_all(db_keywords)
46 changes: 37 additions & 9 deletions frontend/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import RobotTile from "@/components/RobotTile";
import SlackButton from "@/components/SlackButton";
import { faMagnifyingGlass } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import dayjs from "dayjs";
import relativeTime from "dayjs/plugin/relativeTime";
dayjs.extend(relativeTime);

async function getFeeds() {
const res = await fetch(`${process.env.NEXT_PUBLIC_BACKEND_URL}/feeds`, {
Expand All @@ -11,8 +14,17 @@ async function getFeeds() {
return res.json();
}

async function getKeywords() {
const res = await fetch(`${process.env.NEXT_PUBLIC_BACKEND_URL}/keywords`, {
next: { revalidate: 1 },
});
if (!res.ok) return [];
return res.json();
}

export default async function Home() {
const feeds = await getFeeds();
const keywords = await getKeywords();

return (
<main>
Expand Down Expand Up @@ -59,15 +71,31 @@ export default async function Home() {
</div>
</section>

<section className="flex items-center justify-center p-8 sm:p-16">
<h1>Sources</h1>
<div>
{feeds.map((feed: any) => (
<div key={feed.id}>
<h2>{feed.name}</h2>
<p>{feed.url}</p>
</div>
))}
<section className="flex flex-wrap justify-center p-8 sm:p-16 gap-8">
<div className="flex flex-col">
<h2 className="text-xl font-bold">Sources</h2>
<ul className="list-disc">
{feeds.map((feed: any) => (
<li key={feed.key}>
<h3>{feed.title}</h3>
<p>{feed.url}</p>
<p>{dayjs.unix(feed.refreshed_at).fromNow()}</p>
</li>
))}
</ul>
</div>

<div className="flex flex-col">
<h2 className="text-xl font-bold">Keywords</h2>
<ul className="list-disc">
{keywords.map((keyword: any) => (
<li key={keyword.key}>
<h3>{keyword.value}</h3>
<p>{keyword.matches}</p>
<p>refreshed {dayjs(keyword.checkedAt).fromNow()}</p>
</li>
))}
</ul>
</div>
</section>

Expand Down
6 changes: 6 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@fortawesome/free-solid-svg-icons": "^6.4.2",
"@fortawesome/react-fontawesome": "^0.2.0",
"classnames": "^2.3.2",
"dayjs": "^1.11.9",
"next": "^13.4.12",
"react": "^18.2.0",
"react-dom": "^18.2.0"
Expand Down

0 comments on commit b7db933

Please sign in to comment.