From b2fb1832e1a2573c7e5ad8abc38a937e4e63d1a1 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Sun, 12 May 2024 17:02:03 +0800 Subject: [PATCH] perf: improve mobile display --- src/client/components/TimeEventChart.tsx | 19 ++++++++- src/client/components/monitor/MonitorInfo.tsx | 2 +- .../components/monitor/MonitorStatsBlock.tsx | 2 +- .../components/website/WebsiteOnlineCount.tsx | 2 +- .../components/website/WebsiteOverview.tsx | 6 +-- src/client/pages/Layout/Menu.tsx | 34 ++++++++++++++++ src/client/pages/Layout/MobileLayout.tsx | 31 ++------------ src/client/routes/telemetry/$telemetryId.tsx | 15 +++++-- .../routes/website/$websiteId/index.tsx | 40 +++++++++++++++---- src/client/utils/event.ts | 24 +++++++++++ website/src/pages/index.tsx | 2 +- 11 files changed, 130 insertions(+), 47 deletions(-) create mode 100644 src/client/pages/Layout/Menu.tsx create mode 100644 src/client/utils/event.ts diff --git a/src/client/components/TimeEventChart.tsx b/src/client/components/TimeEventChart.tsx index ba76e78..a79286b 100644 --- a/src/client/components/TimeEventChart.tsx +++ b/src/client/components/TimeEventChart.tsx @@ -4,12 +4,22 @@ import { DateUnit } from '@tianji/shared'; import React from 'react'; import { formatDate, formatDateWithUnit } from '../utils/date'; import { Column, ColumnConfig } from '@ant-design/charts'; +import { useIsMobile } from '@/hooks/useIsMobile'; +import { useTranslation } from '@i18next-toolkit/react'; export const TimeEventChart: React.FC<{ + labelMapping?: Record; data: { x: string; y: number; type: string }[]; unit: DateUnit; }> = React.memo((props) => { const { colors } = useTheme(); + const isMobile = useIsMobile(); + const { t } = useTranslation(); + + const labelMapping = props.labelMapping ?? { + pageview: t('pageview'), + session: t('session'), + }; const config = useMemo( () => @@ -30,6 +40,13 @@ export const TimeEventChart: React.FC<{ title: (t) => formatDate(t), }, color: [colors.chart.pv, colors.chart.uv], + legend: isMobile + ? false + : { + itemName: { + formatter: (text) => labelMapping[text] ?? text, + }, + }, xAxis: { label: { autoHide: true, @@ -38,7 +55,7 @@ export const TimeEventChart: React.FC<{ }, }, }) satisfies ColumnConfig, - [props.data, props.unit] + [props.data, props.unit, props.labelMapping] ); return ; diff --git a/src/client/components/monitor/MonitorInfo.tsx b/src/client/components/monitor/MonitorInfo.tsx index 737e51b..bc816e5 100644 --- a/src/client/components/monitor/MonitorInfo.tsx +++ b/src/client/components/monitor/MonitorInfo.tsx @@ -177,7 +177,7 @@ export const MonitorInfo: React.FC = React.memo((props) => {
-
+
diff --git a/src/client/components/monitor/MonitorStatsBlock.tsx b/src/client/components/monitor/MonitorStatsBlock.tsx index ced296d..578f641 100644 --- a/src/client/components/monitor/MonitorStatsBlock.tsx +++ b/src/client/components/monitor/MonitorStatsBlock.tsx @@ -11,7 +11,7 @@ export const MonitorStatsBlock: React.FC = React.memo( (props) => { return (
-
+
{props.title} {props.tooltip && ( diff --git a/src/client/components/website/WebsiteOnlineCount.tsx b/src/client/components/website/WebsiteOnlineCount.tsx index 89a8107..54d481b 100644 --- a/src/client/components/website/WebsiteOnlineCount.tsx +++ b/src/client/components/website/WebsiteOnlineCount.tsx @@ -17,7 +17,7 @@ export const WebsiteOnlineCount: React.FC<{ if (typeof count === 'number' && count > 0) { return (
-
+
{count} {t('current visitor')} diff --git a/src/client/components/website/WebsiteOverview.tsx b/src/client/components/website/WebsiteOverview.tsx index 26a02d8..feeb325 100644 --- a/src/client/components/website/WebsiteOverview.tsx +++ b/src/client/components/website/WebsiteOverview.tsx @@ -83,8 +83,8 @@ export const WebsiteOverview: React.FC<{ return ( -
-
+
+
{website.name} @@ -102,7 +102,7 @@ export const WebsiteOverview: React.FC<{ )} -
+
= React.memo((props) => { + const [open, setOpen] = useState(false); + + useGlobalEventSubscribe('commonListSelected', () => { + setOpen(false); + }); + + if (!props.list) { + return
; + } + + return ( + + + + + + {props.list} + + + ); +}); +MobileLayoutMenu.displayName = 'MobileLayoutMenu'; diff --git a/src/client/pages/Layout/MobileLayout.tsx b/src/client/pages/Layout/MobileLayout.tsx index 974716c..9cc53fc 100644 --- a/src/client/pages/Layout/MobileLayout.tsx +++ b/src/client/pages/Layout/MobileLayout.tsx @@ -2,7 +2,6 @@ import React from 'react'; import { LuAreaChart, LuFilePieChart, - LuMenu, LuMonitorDot, LuMoreVertical, LuServer, @@ -16,19 +15,8 @@ import { cn } from '@/utils/style'; import { Separator } from '@/components/ui/separator'; import { LayoutProps } from './types'; import { UserConfig } from './UserConfig'; -import { ScrollArea } from '@/components/ui/scroll-area'; -import { Sheet, SheetContent, SheetTrigger } from '@/components/ui/sheet'; -import { Button } from '@/components/ui/button'; -import { - Drawer, - DrawerClose, - DrawerContent, - DrawerDescription, - DrawerFooter, - DrawerHeader, - DrawerTitle, - DrawerTrigger, -} from '@/components/ui/drawer'; +import { Drawer, DrawerContent, DrawerTrigger } from '@/components/ui/drawer'; +import { MobileLayoutMenu } from './Menu'; export const MobileLayout: React.FC = React.memo((props) => { const { t } = useTranslation(); @@ -36,20 +24,7 @@ export const MobileLayout: React.FC = React.memo((props) => { return (
- - - - - - {props.list} - - +
diff --git a/src/client/routes/telemetry/$telemetryId.tsx b/src/client/routes/telemetry/$telemetryId.tsx index 0728719..d9534a4 100644 --- a/src/client/routes/telemetry/$telemetryId.tsx +++ b/src/client/routes/telemetry/$telemetryId.tsx @@ -172,7 +172,10 @@ function TelemetryDetailComponent() { /> - + - + - + - + - + - + - + - + - + - +
- + void; +} + +export const globalEventBus = new EventEmitter(); + +export function useGlobalEventSubscribe( + eventName: T, + callback: GlobalEventMap[T] +) { + const fn = useEvent(callback); + + useEffect(() => { + globalEventBus.on(eventName, fn); + + return () => { + globalEventBus.off(eventName, fn); + }; + }, [eventName]); +} diff --git a/website/src/pages/index.tsx b/website/src/pages/index.tsx index b0d759f..6a508a7 100644 --- a/website/src/pages/index.tsx +++ b/website/src/pages/index.tsx @@ -82,7 +82,7 @@ function HomepageMain() {
-
+