From ba43703621270ad1b5765faa3273699bf434228e Mon Sep 17 00:00:00 2001 From: Domenic Horner Date: Wed, 1 Nov 2023 18:08:46 +0800 Subject: [PATCH] dashboard uplift --- package-lock.json | 4 +- package.json | 2 +- src/components/Dashboard/StatCards.jsx | 635 +++++++++---------------- 3 files changed, 215 insertions(+), 426 deletions(-) diff --git a/package-lock.json b/package-lock.json index ac4e018..924a57e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "lemmy-modder", - "version": "1.3.0", + "version": "1.3.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "lemmy-modder", - "version": "1.3.0", + "version": "1.3.2", "license": "MIT", "dependencies": { "@babel/core": "^7.23.2", diff --git a/package.json b/package.json index 97e875b..bff0fc7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lemmy-modder", - "version": "1.3.0", + "version": "1.3.2", "description": "Lemmy Moderation App", "author": "tgxn", "license": "MIT", diff --git a/src/components/Dashboard/StatCards.jsx b/src/components/Dashboard/StatCards.jsx index b4d0186..96051a8 100644 --- a/src/components/Dashboard/StatCards.jsx +++ b/src/components/Dashboard/StatCards.jsx @@ -3,6 +3,8 @@ import React from "react"; import moment from "moment"; import { NumericFormat } from "react-number-format"; +import Tooltip from "@mui/joy/Tooltip"; +import Button from "@mui/joy/Button"; import Chip from "@mui/joy/Chip"; import Card from "@mui/joy/Card"; import CardContent from "@mui/joy/CardContent"; @@ -13,7 +15,7 @@ import StickyNote2Icon from "@mui/icons-material/StickyNote2"; import ForumIcon from "@mui/icons-material/Forum"; import DraftsIcon from "@mui/icons-material/Drafts"; import SupervisedUserCircleIcon from "@mui/icons-material/SupervisedUserCircle"; - +import OpenInNewIcon from "@mui/icons-material/OpenInNew"; import HowToRegIcon from "@mui/icons-material/HowToReg"; import useLVQueryCache from "../../hooks/useLVQueryCache"; @@ -26,11 +28,24 @@ import { MomentAdjustedTimeAgo } from "../Display.jsx"; // Basic Elements (string, chip, etc) // ------------------------------------------------------------------------------------- -export const SimpleNumberFormat = React.memo(({ value }) => { - return ; +export const SimpleNumberFormat = React.memo(({ showChange = false, value }) => { + // get "+", "-", or "" depending on value + function plusMinusIndicator(value) { + return value > 0 ? "+" : value < 0 ? "-" : ""; + } + + return ( + + ); }); -export function StatCardChip({ value, icon = false, color = "primary", variant = "solid" }) { +function StatCardChip({ value, icon = false, color = "neutral", variant = "solid" }) { return ( {icon} {title}: {value} @@ -58,7 +73,7 @@ export function StatDataItem({ title, value, icon = false, color = "primary", va } // card that is in loading state -export function LoadingStatCard({ title }) { +function LoadingStatCard({ title }) { return ( ); } -export function ErrorStatCard({ title }) { + +// error state +function ErrorStatCard({ title }) { return ( ; - } - - let totalReports = reportCountsData?.post_reports + reportCountsData?.comment_reports; - if (userRole == "admin") totalReports += reportCountsData?.private_message_reports; - +// common card for usage with other stat cards +function CommonStatCard({ title, color = "neutral", hexBackground = null, flexDirection = "row", children }) { return ( 0 ? "danger" : "success"} + color={color} orientation="horizontal" sx={{ borderRadius: "8px", @@ -171,76 +170,81 @@ export function ReportsStat() { maxWidth: "100%", width: "100%", overflow: "hidden", + background: hexBackground ? hexBackground : null, }} > - Content Reports + {title} - } - value={reportCountsData?.post_reports !== undefined ? reportCountsData.post_reports : ""} - color={reportCountsData?.post_reports > 0 ? "danger" : "success"} - variant={reportCountsData?.post_reports > 0 ? "soft" : "soft"} - /> - } - value={reportCountsData?.comment_reports !== undefined ? reportCountsData.comment_reports : ""} - color={reportCountsData?.comment_reports > 0 ? "danger" : "success"} - variant={reportCountsData?.comment_reports > 0 ? "soft" : "soft"} - /> - {userRole == "admin" && ( - } - value={ - reportCountsData?.private_message_reports !== undefined - ? reportCountsData.private_message_reports - : "" - } - color={reportCountsData?.private_message_reports > 0 ? "danger" : "success"} - variant={reportCountsData?.private_message_reports > 0 ? "soft" : "soft"} - /> - )} - {/* */} + {children} ); } +// ------------------------------------------------------------------------------------- + +// Content Report Stat Card (TanStack API Response) +export function ReportsStat() { + const { baseUrl, siteData, localPerson, userRole } = getSiteData(); + + const { + isLoading: reportCountsLoading, + isFetching: reportCountsFetching, + error: reportCountsError, + data: reportCountsData, + } = useLemmyHttp("getReportCount"); + + if (reportCountsLoading) { + return ; + } + + let totalReports = reportCountsData?.post_reports + reportCountsData?.comment_reports; + if (userRole == "admin") totalReports += reportCountsData?.private_message_reports; + + return ( + 0 ? "danger" : "success"}> + } + value={reportCountsData?.post_reports !== undefined ? reportCountsData.post_reports : ""} + color={reportCountsData?.post_reports > 0 ? "danger" : "success"} + variant={reportCountsData?.post_reports > 0 ? "soft" : "soft"} + /> + } + value={reportCountsData?.comment_reports !== undefined ? reportCountsData.comment_reports : ""} + color={reportCountsData?.comment_reports > 0 ? "danger" : "success"} + variant={reportCountsData?.comment_reports > 0 ? "soft" : "soft"} + /> + {userRole == "admin" && ( + } + value={ + reportCountsData?.private_message_reports !== undefined + ? reportCountsData.private_message_reports + : "" + } + color={reportCountsData?.private_message_reports > 0 ? "danger" : "success"} + variant={reportCountsData?.private_message_reports > 0 ? "soft" : "soft"} + /> + )} + + ); +} + // User Registration Stat Card (TanStack API Response) export function ApprovalStat() { const { @@ -256,78 +260,21 @@ export function ApprovalStat() { } return ( - 0 ? "danger" : "success"} - orientation="horizontal" - sx={{ - // ...sx, - borderRadius: "8px", - display: "flex", - flexDirection: "column", - - // justifyContent: "center", - alignItems: "center", - - // space aroudn - // justifyContent: "space-between", - - maxWidth: "100%", - width: "100%", - overflow: "hidden", - }} > - - Pending Registrations - - - - } - value={ - regCountAppData?.registration_applications !== undefined - ? regCountAppData.registration_applications - : "" - } - color={regCountAppData?.registration_applications > 0 ? "danger" : "success"} - variant={regCountAppData?.registration_applications > 0 ? "soft" : "soft"} - /> - - + } + value={ + regCountAppData?.registration_applications !== undefined + ? regCountAppData.registration_applications + : "" + } + color={regCountAppData?.registration_applications > 0 ? "danger" : "success"} + variant={regCountAppData?.registration_applications > 0 ? "soft" : "soft"} + /> + ); } @@ -336,65 +283,28 @@ export function UserStat() { const { baseUrl, siteResponse, siteData, localPerson, userRole } = getSiteData(); return ( - - - Local Content - - - - } - value={} - /> - } - value={} - /> - } - value={} - /> - } - value={} - /> - - + + } + value={} + /> + } + value={} + /> + } + value={} + /> + } + value={} + /> + ); } @@ -403,65 +313,24 @@ export function ActivityStat() { const { baseUrl, siteResponse, siteData, localPerson, userRole } = getSiteData(); return ( - - - User Activity - - - - } - value={} - /> - } - value={} - /> - } - value={} - /> - } - value={} - /> - - + + } + /> + } + /> + } + /> + } + /> + ); } @@ -470,103 +339,52 @@ export function SiteStat() { const { baseUrl, siteResponse, siteData, localPerson, userRole } = getSiteData(); return ( - - - Site Config - - - - - - - - - - - - - {siteResponse?.site_view?.local_site?.published} - - } - /> - - {siteResponse?.site_view?.local_site?.updated} - - } - /> - - + + + + + + + + + + + {siteResponse?.site_view?.local_site?.published} + + } + /> + + {siteResponse?.site_view?.local_site?.updated} + + } + /> + ); } @@ -599,11 +417,6 @@ export function GrowthCard() { return latestValue - maxOneWeekValue.value; } - // get "+", "-", or "" depending on value - function plusMinusIndicator(value) { - return value > 0 ? "+" + value : value < 0 ? "-" + value : "" + value; - } - const usersWeekChange = React.useMemo(() => { if (isSuccess) { return getChangeOverTime(metaData.users, moment().subtract(1, "week").unix()); @@ -629,60 +442,36 @@ export function GrowthCard() { } return ( - + Growth Stats + + + + + } + hexBackground="#6a27ac78" + flexDirection="column" > - - Growth Stats - - - - } - title="Week User Growth" - value={plusMinusIndicator(usersWeekChange)} - /> - } - title="Week Comment Growth" - value={plusMinusIndicator(commentsWeekChange)} - /> - } - title="Week Post Growth" - value={plusMinusIndicator(postsWeekChange)} - /> - - + } + title="Week User Growth" + value={} + /> + } + title="Week Comment Growth" + value={} + /> + } + title="Week Post Growth" + value={} + /> + ); }