mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-13 03:32:13 +00:00
useMemo to create numberFormater instance
This commit is contained in:
parent
1098418a3e
commit
2ae3f95a73
1 changed files with 10 additions and 6 deletions
|
@ -22,6 +22,8 @@ export interface HeroPanelProps {
|
||||||
getGame: () => void;
|
getGame: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const MAX_MINUTES_TO_SHOW_IN_PLAYTIME = 120;
|
||||||
|
|
||||||
export function HeroPanel({
|
export function HeroPanel({
|
||||||
game,
|
game,
|
||||||
gameDetails,
|
gameDetails,
|
||||||
|
@ -58,23 +60,25 @@ export function HeroPanel({
|
||||||
}
|
}
|
||||||
}, [game?.lastTimePlayed, formatDistance]);
|
}, [game?.lastTimePlayed, formatDistance]);
|
||||||
|
|
||||||
|
const numberFormatter = useMemo(() => {
|
||||||
|
return new Intl.NumberFormat(i18n.language, {
|
||||||
|
maximumFractionDigits: 1,
|
||||||
|
});
|
||||||
|
}, [i18n]);
|
||||||
|
|
||||||
const formatPlayTime = () => {
|
const formatPlayTime = () => {
|
||||||
const milliseconds = game?.playTimeInMilliseconds || 0;
|
const milliseconds = game?.playTimeInMilliseconds || 0;
|
||||||
const seconds = milliseconds / 1000;
|
const seconds = milliseconds / 1000;
|
||||||
const minutes = seconds / 60;
|
const minutes = seconds / 60;
|
||||||
|
|
||||||
if (minutes < 120) {
|
if (minutes < MAX_MINUTES_TO_SHOW_IN_PLAYTIME) {
|
||||||
return t("amount_minutes", {
|
return t("amount_minutes", {
|
||||||
amount: minutes.toFixed(0),
|
amount: minutes.toFixed(0),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const numberFormat = new Intl.NumberFormat(i18n.language, {
|
|
||||||
maximumFractionDigits: 1,
|
|
||||||
});
|
|
||||||
|
|
||||||
const hours = minutes / 60;
|
const hours = minutes / 60;
|
||||||
return t("amount_hours", { amount: numberFormat.format(hours) });
|
return t("amount_hours", { amount: numberFormatter.format(hours) });
|
||||||
};
|
};
|
||||||
|
|
||||||
const finalDownloadSize = useMemo(() => {
|
const finalDownloadSize = useMemo(() => {
|
||||||
|
|
Loading…
Reference in a new issue