@@ -3,8 +3,9 @@ import { Clock, Cpu, HardDrive, type LucideIcon, MemoryStick, Wifi } from 'lucid
33import { Suspense } from 'react'
44import { Card , CardContent , CardHeader , CardTitle } from '@/components/ui/card'
55import { formatDuration } from '@/lib/format'
6+ import { cn } from '@/lib/utils'
67import SystemStatsProvider from './SystemStatsProvider'
7- import SystemStatValue from './SystemStatValue'
8+ import SystemStatValue , { type SystemStatValueType } from './SystemStatValue'
89import { type Store , store } from './store'
910
1011export default function SystemStats ( ) {
@@ -20,10 +21,13 @@ export default function SystemStats() {
2021}
2122
2223function SystemStatsMobile ( ) {
24+ const stats = statsProps . filter ( stat => {
25+ return ! ( 'hideOnMobile' in stat && stat . hideOnMobile )
26+ } )
2327 return (
2428 < Card size = "sm" className = "mx-1 block sm:hidden" >
2529 < CardContent className = "grid grid-cols-5 gap-y-2 [&>*:nth-child(odd)]:col-start-1 [&>*:nth-child(even)]:col-start-4" >
26- { statsProps . map ( stat => (
30+ { stats . map ( stat => (
2731 < MobileStatRow key = { stat . key } stat = { stat } />
2832 ) ) }
2933 </ CardContent >
@@ -35,9 +39,13 @@ function SystemStatsDesktop() {
3539 const hasSecondaryDisk = Boolean ( store . systemInfo . secondaryPartitionUsageDesc . use ( ) )
3640
3741 return (
38- < div className = "hidden sm:grid grid-cols-2 gap-2 px-1 sm:grid-cols-5 sm:gap-4" >
42+ < div className = "hidden sm:grid grid-cols-2 gap-2 px-1 sm:grid-cols-4 md:grid-cols- 5 sm:gap-4" >
3943 { statsProps . map ( stat => (
40- < Card key = { stat . key } size = "sm" className = "h-full" >
44+ < Card
45+ key = { stat . key }
46+ size = "sm"
47+ className = { cn ( 'h-full' , stat . key === 'networkSpeedUpload' && 'hidden md:flex' ) }
48+ >
4149 < CardHeader >
4250 < div className = "flex items-center justify-between gap-2" >
4351 < CardTitle className = "text-xs font-medium text-muted-foreground sm:text-sm" >
@@ -47,21 +55,28 @@ function SystemStatsDesktop() {
4755 </ div >
4856 </ CardHeader >
4957 < CardContent className = "space-y-1.5 sm:space-y-2" >
50- { stat . key === 'rootPartitionUsage' ? (
51- < >
52- < SystemStatValue
53- valueKey = { stat . key }
54- descriptionKey = { stat . descriptionKey }
55- type = { stat . type }
56- />
57- { hasSecondaryDisk && (
58+ { stat . key === 'rootPartitionUsage' && hasSecondaryDisk ? (
59+ < div className = "flex justify-between gap-3" >
60+ < div className = "space-y-1.5 sm:space-y-2 w-full xl:w-auto" >
5861 < SystemStatValue
59- valueKey = "secondaryPartitionUsage"
60- descriptionKey = "secondaryPartitionUsageDesc"
61- type = "progress"
62+ valueKey = { stat . key }
63+ descriptionKey = { stat . descriptionKey }
64+ type = { stat . type }
6265 />
63- ) }
64- </ >
66+ </ div >
67+ < div className = "space-y-1.5 sm:space-y-2 hidden xl:block" >
68+ < SystemStatValue
69+ valueKey = { stat . secondaryKey }
70+ descriptionKey = { stat . secondaryDescriptionKey }
71+ type = { stat . type }
72+ />
73+ </ div >
74+ </ div >
75+ ) : stat . key === 'networkSpeedUpload' ? (
76+ < div className = "flex flex-col gap-0.5" >
77+ < SystemStatValue valueKey = { stat . key } type = "upload" />
78+ < SystemStatValue valueKey = { stat . secondaryKey } type = "download" />
79+ </ div >
6580 ) : (
6681 < SystemStatValue
6782 valueKey = { stat . key }
@@ -77,14 +92,17 @@ function SystemStatsDesktop() {
7792}
7893
7994type StatProp = {
95+ hideOnMobile ?: boolean
8096 label : string
8197 mobileLabel : string
8298 icon : LucideIcon
83- mobileValueMode ?: 'percent' | 'description' | 'duration' | 'text'
84- type : 'text' | 'progress' | 'duration'
99+ mobileValueMode ?: 'percent' | 'description' | 'duration' | 'text' | 'networkSpeed'
100+ type : SystemStatValueType
85101 color : string
86102 key : FieldPath < Store [ 'systemInfo' ] >
87103 descriptionKey ?: FieldPath < Store [ 'systemInfo' ] >
104+ secondaryKey ?: FieldPath < Store [ 'systemInfo' ] >
105+ secondaryDescriptionKey ?: FieldPath < Store [ 'systemInfo' ] >
88106 format ?: ( value : number ) => string
89107}
90108
@@ -98,6 +116,9 @@ function MobileStatRow({ stat }: { stat: StatProp }) {
98116 if ( stat . mobileValueMode === 'text' ) {
99117 return String ( value )
100118 }
119+ if ( stat . mobileValueMode === 'networkSpeed' ) {
120+ return null
121+ }
101122 return `${ value } %`
102123 } ) ( )
103124
@@ -112,7 +133,7 @@ function MobileStatRow({ stat }: { stat: StatProp }) {
112133 )
113134}
114135
115- const statsProps : StatProp [ ] = [
136+ const statsProps = [
116137 {
117138 label : 'Uptime' ,
118139 mobileLabel : 'Up' ,
@@ -121,6 +142,7 @@ const statsProps: StatProp[] = [
121142 type : 'duration' ,
122143 color : 'text-primary' ,
123144 key : 'uptime' ,
145+ descriptionKey : undefined ,
124146 } ,
125147 {
126148 label : 'CPU Usage' ,
@@ -130,6 +152,7 @@ const statsProps: StatProp[] = [
130152 type : 'progress' ,
131153 color : 'bg-chart-1' ,
132154 key : 'cpuAverage' ,
155+ descriptionKey : undefined ,
133156 } ,
134157 {
135158 label : 'Memory' ,
@@ -150,14 +173,19 @@ const statsProps: StatProp[] = [
150173 color : 'bg-chart-3' ,
151174 key : 'rootPartitionUsage' ,
152175 descriptionKey : 'rootPartitionUsageDesc' ,
176+ secondaryKey : 'secondaryPartitionUsage' ,
177+ secondaryDescriptionKey : 'secondaryPartitionUsageDesc' ,
153178 } ,
154179 {
180+ hideOnMobile : true ,
155181 label : 'Network' ,
156182 mobileLabel : 'Net' ,
157183 icon : Wifi ,
158- mobileValueMode : 'text ' ,
184+ mobileValueMode : 'networkSpeed ' ,
159185 type : 'text' ,
160186 color : 'bg-chart-4' ,
161- key : 'networkSpeedSummary' ,
187+ key : 'networkSpeedUpload' ,
188+ secondaryKey : 'networkSpeedDownload' ,
189+ descriptionKey : undefined ,
162190 } ,
163- ] as const
191+ ] as const satisfies StatProp [ ]
0 commit comments