Skip to content

Commit

Permalink
Fixed number precision in locations page spool card
Browse files Browse the repository at this point in the history
  • Loading branch information
Donkie committed Nov 25, 2024
1 parent c571412 commit 04920e4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion client/src/pages/locations/components/spoolCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import utc from "dayjs/plugin/utc";
import { useEffect, useRef } from "react";
import { Link } from "react-router-dom";
import SpoolIcon from "../../../components/spoolIcon";
import { formatWeight } from "../../../utils/parsing";
import { ISpool } from "../../spools/model";
import { ItemTypes, SpoolDragItem, useCurrentDraggedSpool } from "../dnd";

Expand Down Expand Up @@ -145,7 +146,7 @@ export function SpoolCard({
if (spool.filament.material) str += spool.filament.material + " - ";
if (spool.filament.weight) {
const remaining_weight = spool.remaining_weight ?? spool.filament.weight;
str += `${remaining_weight} / ${spool.filament.weight} g`;
str += `${formatWeight(remaining_weight, 0)} / ${formatWeight(spool.filament.weight, 0)}`;
}
if (spool.last_used) {
// Format like "last used X time ago"
Expand Down
3 changes: 2 additions & 1 deletion client/src/utils/parsing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ export function formatWeight(weightInGrams: number, precision: number = 2): stri
const kilograms = (weightInGrams / 1000).toFixed(precision).replace(/\.?0+$/, ""); // Remove trailing zeros
return `${kilograms} kg`;
} else {
return `${weightInGrams} g`;
const grams = weightInGrams.toFixed(precision).replace(/\.?0+$/, ""); // Remove trailing zeros
return `${grams} g`;
}
}

Expand Down

0 comments on commit 04920e4

Please sign in to comment.