From 1f79360c6e7bd116354e24b81c8b09dfab64f297 Mon Sep 17 00:00:00 2001 From: qu1ck Date: Sun, 28 Apr 2024 14:02:49 -0700 Subject: [PATCH] Tweak field types of numeric fields Issue #194 --- src/components/tables/torrenttable.tsx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/components/tables/torrenttable.tsx b/src/components/tables/torrenttable.tsx index 0ebdfcc..6982735 100644 --- a/src/components/tables/torrenttable.tsx +++ b/src/components/tables/torrenttable.tsx @@ -123,7 +123,7 @@ const AllFields: readonly TableField[] = [ accessorFn: (t) => t.peersGettingFromUs * 1e+6 + t.cachedPeersTotal, }, { name: "eta", label: "ETA", component: EtaField }, - { name: "uploadRatio", label: "Ratio", component: PositiveNumberField }, + { name: "uploadRatio", label: "Ratio", component: FixedDecimalField }, { name: "trackerStats", label: "Tracker", @@ -142,8 +142,8 @@ const AllFields: readonly TableField[] = [ { name: "activityDate", label: "Last active", component: DateDiffField }, { name: "downloadDir", label: "Path", component: StringField }, { name: "bandwidthPriority", label: "Priority", component: PriorityField }, - { name: "id", label: "ID", component: StringField }, - { name: "queuePosition", label: "Queue position", component: StringField }, + { name: "id", label: "ID", component: PositiveNumberField }, + { name: "queuePosition", label: "Queue position", component: PositiveNumberField }, { name: "secondsSeeding", label: "Seeding time", component: TimeField }, { name: "isPrivate", label: "Private", component: StringField }, { name: "labels", label: "Labels", component: LabelsField }, @@ -217,6 +217,15 @@ function PositiveNumberField(props: TableFieldProps) { ); } +function FixedDecimalField(props: TableFieldProps) { + const num = props.torrent[props.fieldName]; + return ( +
+ {num < 0 ? "" : Number(num).toFixed(2)} +
+ ); +} + function UploadRatioField(props: TableFieldProps) { return (