From c16173ea0fdbf6cc47b13756c0a77e8399669055 Mon Sep 17 00:00:00 2001
From: MohamedBassem <me@mbassem.com>
Date: Sat, 12 Oct 2024 16:47:22 +0000
Subject: feature: Introduce a mechanism to cleanup dangling assets

---
 apps/web/components/dashboard/admin/UserList.tsx | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

(limited to 'apps/web/components/dashboard/admin/UserList.tsx')

diff --git a/apps/web/components/dashboard/admin/UserList.tsx b/apps/web/components/dashboard/admin/UserList.tsx
index 024325a3..65bf4068 100644
--- a/apps/web/components/dashboard/admin/UserList.tsx
+++ b/apps/web/components/dashboard/admin/UserList.tsx
@@ -15,10 +15,18 @@ import { api } from "@/lib/trpc";
 import { Trash } from "lucide-react";
 import { useSession } from "next-auth/react";
 
+function toHumanReadableSize(size: number) {
+  const sizes = ["Bytes", "KB", "MB", "GB", "TB"];
+  if (size === 0) return "0 Bytes";
+  const i = Math.floor(Math.log(size) / Math.log(1024));
+  return (size / Math.pow(1024, i)).toFixed(2) + " " + sizes[i];
+}
+
 export default function UsersSection() {
   const { data: session } = useSession();
   const invalidateUserList = api.useUtils().users.list.invalidate;
   const { data: users } = api.users.list.useQuery();
+  const { data: userStats } = api.admin.userStats.useQuery();
   const { mutate: deleteUser, isPending: isDeletionPending } =
     api.users.delete.useMutation({
       onSuccess: () => {
@@ -35,7 +43,7 @@ export default function UsersSection() {
       },
     });
 
-  if (!users) {
+  if (!users || !userStats) {
     return <LoadingSpinner />;
   }
 
@@ -47,6 +55,8 @@ export default function UsersSection() {
         <TableHeader className="bg-gray-200">
           <TableHead>Name</TableHead>
           <TableHead>Email</TableHead>
+          <TableHead>Num Bookmarks</TableHead>
+          <TableHead>Asset Sizes</TableHead>
           <TableHead>Role</TableHead>
           <TableHead>Action</TableHead>
         </TableHeader>
@@ -55,6 +65,12 @@ export default function UsersSection() {
             <TableRow key={u.id}>
               <TableCell className="py-1">{u.name}</TableCell>
               <TableCell className="py-1">{u.email}</TableCell>
+              <TableCell className="py-1">
+                {userStats[u.id].numBookmarks}
+              </TableCell>
+              <TableCell className="py-1">
+                {toHumanReadableSize(userStats[u.id].assetSizes)}
+              </TableCell>
               <TableCell className="py-1 capitalize">{u.role}</TableCell>
               <TableCell className="py-1">
                 <ActionButton
-- 
cgit v1.2.3-70-g09d2

