diff --git a/frontend/app/admin/page.tsx b/frontend/app/admin/page.tsx index b3f14e93..9f339543 100644 --- a/frontend/app/admin/page.tsx +++ b/frontend/app/admin/page.tsx @@ -8,7 +8,7 @@ import { Table, TableBody, TableCell, TableColumn, TableHeader, TableRow } from import { siteConfig } from "@/config/site"; import { title } from "@/components/primitives"; import { Card, CardBody } from "@nextui-org/card"; -import { CubeIcon, FlagIcon, PencilSquareIcon, UserCircleIcon } from "@heroicons/react/24/solid"; +import { CubeIcon, FlagIcon, MapPinIcon, PencilSquareIcon, UserCircleIcon } from "@heroicons/react/24/solid"; import Link from "next/link"; import { HttpCodes } from "@/types/HttpCodes"; import { Modal, ModalContent, ModalHeader, ModalBody, ModalFooter, useDisclosure } from "@nextui-org/modal"; @@ -24,7 +24,15 @@ const AdminHomepage = () => { const [amLoggedIn, setAmLoggedIn] = useState(false); const [users, setUsers] = useState([]); + const [posts, setPosts] = useState([]); + const [postsSources, setPostsSources] = useState<{ + [key: string]: number; + }>({}); + const [postsDestinations, setPostsDestinations] = useState<{ + [key: string]: number; + }>({}); + const [error, setError] = useState(""); const [reports, setReports] = useState([]); const [loading, setLoading] = useState(true); @@ -71,6 +79,22 @@ const AdminHomepage = () => { if (res.status == HttpCodes.OK) { setAmLoggedIn(true); setPosts(res.data.data); + + // Make a list of all sources and destinations + let sources: { + [key: string]: number; + } = {}; + let destinations: { + [key: string]: number; + } = {}; + for (let post of res.data.data) { + if (!sources[post.source]) sources[post.source] = 0; + if (!destinations[post.destination]) destinations[post.destination] = 0; + sources[post.source] += 1; + destinations[post.destination] += 1; + } + setPostsSources(sources); + setPostsDestinations(destinations); } else if (res.status == HttpCodes.INTERNAL_SERVER_ERROR) { console.error(res.data.message); } @@ -376,6 +400,63 @@ const AdminHomepage = () => { +
+ + {/* Sources Card */} + + +
+ +
+ Top Sources +
+
+
+ Unique: {Object.keys(postsSources).length} +
+ +
+
+ {Object.keys(postsSources).slice(0, 5).map((source, index) => ( +
+
+ {source.toUpperCase()}: {postsSources[source]} +
+
+ ))} +
+
+
+
+ + {/* Destinations Card */} + + +
+ +
+ Top Destinations +
+
+
+ Unique: {Object.keys(postsDestinations).length} +
+ +
+
+ {Object.keys(postsDestinations).slice(0, 5).map((destination, index) => ( +
+
+ {destination.toUpperCase()}: {postsDestinations[destination]} +
+
+ ))} +
+
+
+
+ +
@@ -384,7 +465,7 @@ const AdminHomepage = () => { { {