Skip to content

Commit 3db18fd

Browse files
committed
Fix formatting issues in many places
1 parent 1a3f712 commit 3db18fd

36 files changed

Lines changed: 403 additions & 326 deletions

Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/json/PlayerJSONCreator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,9 @@ private Map<String, Object> createInfoJSONMap(PlayerContainer player, Map<Server
229229
int bestPing = ping.min();
230230

231231
String unavailable = GenericLang.UNAVAILABLE.getKey();
232-
info.put("average_ping", averagePing != -1.0 ? decimals.apply(averagePing) + " ms" : unavailable);
233-
info.put("worst_ping", worstPing != -1.0 ? worstPing + " ms" : unavailable);
234-
info.put("best_ping", bestPing != -1.0 ? bestPing + " ms" : unavailable);
232+
info.put("average_ping", averagePing != -1.0 ? averagePing : unavailable);
233+
info.put("worst_ping", worstPing != -1.0 ? worstPing : unavailable);
234+
info.put("best_ping", bestPing != -1.0 ? bestPing : unavailable);
235235
info.put("registered", player.getValue(PlayerKeys.REGISTERED).map(Object.class::cast).orElse("-"));
236236
info.put("last_seen", player.getValue(PlayerKeys.LAST_SEEN).map(Object.class::cast).orElse("-"));
237237
info.put("last_seen_raw_value", player.getValue(PlayerKeys.LAST_SEEN).orElse(0L));

Plan/react/dashboard/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"@types/react": "^19.2.14",
6969
"@types/react-dom": "^19.2.3",
7070
"@vitejs/plugin-react": "^5.1.4",
71+
"baseline-browser-mapping": "^2.10.0",
7172
"typescript": "^5.9.3",
7273
"vite": "^7.3.1"
7374
}

Plan/react/dashboard/src/components/accordion/SessionAccordion.jsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ import {ChartLoader} from "../navigation/Loader";
1212
import {usePreferences} from "../../hooks/preferencesHook.jsx";
1313
import FormattedDate from "../text/FormattedDate.jsx";
1414
import FormattedTime from "../text/FormattedTime.jsx";
15-
import {formatDecimals} from "../../util/formatters.js";
1615
import PlayerPageLinkButton from "../input/button/PlayerPageLinkButton.jsx";
1716
import ServerPageLinkButton from "../input/button/ServerPageLinkButton.jsx";
17+
import {useDecimalFormatter} from "../../util/format/useDecimalFormatter.js";
18+
import {usePingFormatter} from "../../util/format/usePingFormatter.js";
1819

1920
const SessionHeader = ({session}) => {
2021
const {t} = useTranslation();
@@ -33,7 +34,8 @@ const SessionHeader = ({session}) => {
3334

3435
const SessionBody = ({i, session}) => {
3536
const {t} = useTranslation();
36-
const {decimalFormat} = usePreferences();
37+
const {formatDecimals} = useDecimalFormatter();
38+
const {formatPing} = usePingFormatter();
3739
return (
3840
<Row>
3941
<Col lg={6}>
@@ -55,7 +57,7 @@ const SessionBody = ({i, session}) => {
5557
/>
5658
{session.avg_ping ? <Datapoint
5759
icon={faSignal} color={"ping"}
58-
name={t('html.label.averagePing')} value={formatDecimals(session.avg_ping, decimalFormat)} bold
60+
name={t('html.label.averagePing')} value={formatPing(formatDecimals(session.avg_ping))} bold
5961
/> : ''}
6062
<br/>
6163
<Datapoint

Plan/react/dashboard/src/components/calendar/PlayerSessionCalendar.jsx

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,38 @@
1-
import React from "react";
1+
import React, {useCallback, useMemo} from "react";
22
import FullCalendar from '@fullcalendar/react'
33
import dayGridPlugin from '@fullcalendar/daygrid'
44
import {useTranslation} from "react-i18next";
5-
import {formatTimeAmount} from "../../util/format/TimeAmountFormat.js";
6-
import {formatDateWithPreferences, useDatePreferences} from "../text/FormattedDate.jsx";
7-
import {useTimePreferences} from "../text/FormattedTime.jsx";
85
import {localeService} from "../../service/localeService.js";
6+
import {useTimeAmountFormatter} from "../../util/format/useTimeAmountFormatter.js";
7+
import {useDateFormatter} from "../../util/format/useDateFormatter.js";
98

109
const PlayerSessionCalendar = ({series, firstDay}) => {
11-
const {t} = useTranslation();
10+
const {t, i18n} = useTranslation();
1211

13-
const timePreferences = useTimePreferences();
14-
const datePreferences = useDatePreferences();
12+
const {formatTime} = useTimeAmountFormatter();
13+
const {formatDate} = useDateFormatter();
1514

16-
const formatTitle = entry => {
15+
const formatTitle = useCallback(entry => {
1716
switch (entry.title) {
1817
case 'html.label.session':
19-
return formatTimeAmount(timePreferences, entry.value) + ' ' + t(entry.title);
18+
return formatTime(entry.value) + ' ' + t(entry.title);
2019
case 'html.label.playtime':
21-
return t(entry.title) + ": " + formatTimeAmount(timePreferences, entry.value)
20+
return t(entry.title) + ": " + formatTime(entry.value)
2221
case 'html.label.registered':
23-
return t(entry.title) + ": " + formatDateWithPreferences(datePreferences, entry.value)
22+
return t(entry.title) + ": " + formatDate(entry.value)
2423
default:
2524
return t(entry.title) + ": " + entry.value;
2625
}
27-
}
26+
}, [formatTime, formatDate])
2827

29-
const actualSeries = series.map(entry => {
28+
const actualSeries = useMemo(() => series.map(entry => {
3029
return {
3130
title: formatTitle(entry),
3231
start: entry.start,
3332
end: entry.end,
3433
color: entry.color
3534
}
36-
});
35+
}), [formatTitle]);
3736

3837
const buttonText = {
3938
today: t('plugin.generic.today').toLowerCase().replaceAll("'", ''),

Plan/react/dashboard/src/components/calendar/ServerCalendar.jsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,43 @@
1-
import React from "react";
1+
import React, {useCallback, useMemo} from "react";
22
import FullCalendar from '@fullcalendar/react'
33
import dayGridPlugin from '@fullcalendar/daygrid'
44
import interactionPlugin from '@fullcalendar/interaction'
55
import {useTranslation} from "react-i18next";
66
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
77
import {faHandPointer} from "@fortawesome/free-regular-svg-icons";
8-
import {useTimePreferences} from "../text/FormattedTime.jsx";
9-
import {formatTimeAmount} from "../../util/format/TimeAmountFormat.js";
108
import {localeService} from "../../service/localeService.js";
9+
import {useTimeAmountFormatter} from "../../util/format/useTimeAmountFormatter.js";
1110

1211
const ServerCalendar = ({series, firstDay, onSelect}) => {
1312
const {t} = useTranslation();
13+
const {formatTime} = useTimeAmountFormatter();
1414

1515
const explainerStyle = {
1616
position: "absolute",
1717
top: "0.5rem",
1818
right: "1rem"
1919
};
20-
const timePreferences = useTimePreferences();
2120

22-
const formatTitle = entry => {
21+
const formatTitle = useCallback(entry => {
2322
switch (entry.title) {
2423
case 'html.label.playtime':
25-
return t(entry.title) + ": " + formatTimeAmount(timePreferences, entry.value)
24+
return t(entry.title) + ": " + formatTime(entry.value)
2625
case 'html.calendar.unique':
2726
case 'html.calendar.new':
2827
return t(entry.title) + " " + entry.value
2928
default:
3029
return t(entry.title) + ": " + entry.value;
3130
}
32-
}
31+
}, [formatTime, t]);
3332

34-
const actualSeries = series.map(entry => {
33+
const actualSeries = useMemo(() => series.map(entry => {
3534
return {
3635
title: formatTitle(entry),
3736
start: entry.start,
3837
end: entry.end,
3938
color: entry.color
4039
}
41-
});
40+
}), [series, formatTitle]);
4241

4342
const buttonText = {
4443
today: t('plugin.generic.today').toLowerCase().replaceAll("'", ''),

Plan/react/dashboard/src/components/cards/player/PlayerOverviewCard.jsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import {faSuperpowers} from "@fortawesome/free-brands-svg-icons";
2828
import Datapoint from "../../Datapoint";
2929
import FormattedTime from "../../text/FormattedTime.jsx";
3030
import FormattedDate from "../../text/FormattedDate.jsx";
31+
import {useDecimalFormatter} from "../../../util/format/useDecimalFormatter.js";
32+
import {usePingFormatter} from "../../../util/format/usePingFormatter.js";
3133

3234
const PlayerHeadSection = ({player}) => {
3335
const {t} = useTranslation();
@@ -67,6 +69,8 @@ const PlayerOverviewCard = ({player}) => {
6769
const {t} = useTranslation();
6870
const {setHelpModalTopic} = useNavigation();
6971
const openHelp = useCallback(() => setHelpModalTopic('activity-index'), [setHelpModalTopic]);
72+
const {formatDecimals} = useDecimalFormatter();
73+
const {formatPing} = usePingFormatter();
7074

7175
return (
7276
<Card>
@@ -124,7 +128,7 @@ const PlayerOverviewCard = ({player}) => {
124128
<button onClick={openHelp}><Fa className={"col-help-icon"}
125129
icon={faQuestionCircle}/>
126130
</button></span></>}
127-
value={player.info.activity_index} bold
131+
value={formatDecimals(player.info.activity_index)} bold
128132
valueLabel={player.info.activity_index_group}
129133
title={t('html.label.activityIndex')}
130134
/>
@@ -139,15 +143,15 @@ const PlayerOverviewCard = ({player}) => {
139143
<hr/>
140144
<Datapoint
141145
icon={faSignal} color="ping"
142-
name={t('html.label.averagePing')} value={player.info.average_ping}
146+
name={t('html.label.averagePing')} value={formatPing(player.info.average_ping)}
143147
/>
144148
<Datapoint
145149
icon={faSignal} color="ping"
146-
name={t('html.label.bestPing')} value={player.info.best_ping}
150+
name={t('html.label.bestPing')} value={formatPing(player.info.best_ping)}
147151
/>
148152
<Datapoint
149153
icon={faSignal} color="ping"
150-
name={t('html.label.worstPing')} value={player.info.worst_ping}
154+
name={t('html.label.worstPing')} value={formatPing(player.info.worst_ping)}
151155
/>
152156
<hr/>
153157
<Datapoint

Plan/react/dashboard/src/components/cards/server/insights/OnlineActivityInsightsCard.jsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,24 @@ import ComparingLabel from "../../../trend/ComparingLabel";
99
import End from "../../../layout/End";
1010
import {CardLoader} from "../../../navigation/Loader";
1111
import FormattedTime from "../../../text/FormattedTime.jsx";
12+
import {useTimeAmountFormatter} from "../../../../util/format/useTimeAmountFormatter.js";
1213

1314
const OnlineActivityInsightsCard = ({data}) => {
1415
const {t} = useTranslation();
16+
const {formatTime} = useTimeAmountFormatter();
1517
if (!data) return <CardLoader/>;
1618

1719
return (
1820
<InsightsFor30DaysCard id={'online-activity-insights'}>
1921
<Datapoint name={t('html.label.onlineOnFirstJoin')} icon={faUserGroup} color="players-new"
2022
value={data.players_first_join_avg}
21-
trend={<SmallTrend trend={data.players_first_join_avg_trend}/>}/>
23+
trend={<SmallTrend trend={data.players_first_join_trend}/>}/>
2224
<Datapoint name={t('html.label.firstSessionLength.average')} icon={faUserClock} color="players-new"
2325
value={<FormattedTime timeMs={data.first_session_length_avg}/>}
24-
trend={<SmallTrend trend={<FormattedTime timeMs={data.first_session_length_avg_trend}/>}/>}/>
26+
trend={<SmallTrend trend={data.first_session_length_trend} format={formatTime}/>}/>
2527
<Datapoint name={t('html.label.firstSessionLength.median')} icon={faUserClock} color="players-new"
2628
value={<FormattedTime timeMs={data.first_session_length_median}/>}
27-
trend={<SmallTrend trend={<FormattedTime timeMs={data.first_session_length_median_trend}/>}/>}/>
29+
trend={<SmallTrend trend={data.first_session_length_median_trend} format={formatTime}/>}/>
2830
<Datapoint name={t('html.label.loneJoins')} icon={faCalendar} color="sessions"
2931
value={data.lone_joins}
3032
trend={<SmallTrend trend={data.lone_joins_trend}/>}/>

Plan/react/dashboard/src/components/cards/server/tables/PlayerbaseTrendsCard.jsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ import {faClock} from "@fortawesome/free-regular-svg-icons";
99
import {TableRow} from "../../../table/TableRow";
1010
import {CardLoader} from "../../../navigation/Loader";
1111
import FormattedTime from "../../../text/FormattedTime.jsx";
12+
import {useTimeAmountFormatter} from "../../../../util/format/useTimeAmountFormatter.js";
1213

1314
const PlayerbaseTrendsCard = ({data}) => {
1415
const {t} = useTranslation();
16+
const {formatTime} = useTimeAmountFormatter();
1517
if (!data) return <CardLoader/>;
1618
return (
1719
<Card id={"playerbase-trends"}>
@@ -33,10 +35,10 @@ const PlayerbaseTrendsCard = ({data}) => {
3335
<TableRow icon={faClock} color="playtime"
3436
text={t('html.label.averagePlaytime') + ' ' + t('html.label.perPlayer')}
3537
values={[
36-
<FormattedTime timeMs={data.playtime_avg_then}/>,
37-
<FormattedTime timeMs={data.playtime_avg_now}/>,
38+
<FormattedTime key={'p-a-t'} timeMs={data.playtime_avg_then}/>,
39+
<FormattedTime key={'p-a-n'} timeMs={data.playtime_avg_now}/>,
3840
<BigTrend key={JSON.stringify(data.total_players_trend)}
39-
trend={<FormattedTime timeMs={data.playtime_avg_trend}/>}/>]}/>
41+
trend={data.playtime_avg_trend} format={formatTime}/>]}/>
4042
<TableRow icon={faClock} color="playtime-afk"
4143
text={t('html.label.afk') + ' ' + t('html.label.perPlayer')}
4244
values={[data.afk_then, data.afk_now,
@@ -45,17 +47,17 @@ const PlayerbaseTrendsCard = ({data}) => {
4547
<TableRow icon={faClock} color="playtime"
4648
text={t('html.label.averagePlaytime') + ' ' + t('html.label.perRegularPlayer')}
4749
values={[
48-
<FormattedTime timeMs={data.regular_playtime_avg_then}/>,
49-
<FormattedTime timeMs={data.regular_playtime_avg_now}/>,
50+
<FormattedTime key={'rg-pl-avg-th'} timeMs={data.regular_playtime_avg_then}/>,
51+
<FormattedTime key={'rg-pl-av-n'} timeMs={data.regular_playtime_avg_now}/>,
5052
<BigTrend key={JSON.stringify(data.regular_playtime_avg_trend)}
51-
trend={<FormattedTime timeMs={data.regular_playtime_avg_trend}/>}/>]}/>
53+
trend={data.regular_playtime_avg_trend} format={formatTime}/>]}/>
5254
<TableRow icon={faClock} color="sessions"
5355
text={t('html.label.averageSessionLength') + ' ' + t('html.label.perRegularPlayer')}
5456
values={[
55-
<FormattedTime timeMs={data.regular_session_avg_then}/>,
56-
<FormattedTime timeMs={data.regular_session_avg_now}/>,
57+
<FormattedTime key={'rg-s-a-t'} timeMs={data.regular_session_avg_then}/>,
58+
<FormattedTime key={'rg-s-a-n'} timeMs={data.regular_session_avg_now}/>,
5759
<BigTrend key={JSON.stringify(data.regular_session_avg_trend)}
58-
trend={<FormattedTime timeMs={data.regular_session_avg_trend}/>}/>]}/>
60+
trend={data.regular_session_avg_trend} format={formatTime}/>]}/>
5961
<TableRow icon={faClock} color="playtime-afk"
6062
text={t('html.label.afk') + ' ' + t('html.label.perRegularPlayer')}
6163
values={[data.regular_afk_avg_then, data.regular_afk_avg_now,

Plan/react/dashboard/src/components/extensions/ExtensionIcon.jsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {FontAwesomeIcon as Fa} from '@fortawesome/react-fontawesome'
2-
import {iconTypeToFontAwesomeClass} from "../../util/icons";
2+
import {iconTypeToFontAwesomeClass} from "../../util/icons.ts";
33
import React from "react";
44

55
const ExtensionIcon = ({icon}) => {
@@ -13,8 +13,4 @@ const ExtensionIcon = ({icon}) => {
1313
)
1414
}
1515

16-
export const toExtensionIconHtmlString = (icon) => {
17-
return icon ? `<i class="${iconTypeToFontAwesomeClass(icon.family)} fa-${icon.iconName} ${icon.colorClass}"></i>` : '';
18-
}
19-
2016
export default ExtensionIcon;

Plan/react/dashboard/src/components/graphs/PlayerbaseGraph.jsx

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import {useTranslation} from "react-i18next";
2-
import React, {useEffect} from "react";
2+
import React, {useEffect, useMemo} from "react";
33
import {useTheme} from "../../hooks/themeHook";
44
import Highcharts from "highcharts/esm/highstock";
55
import "highcharts/esm/modules/no-data-to-display";
66
import "highcharts/esm/modules/accessibility";
77
import {nameToCssVariable} from "../../util/colors";
8-
import {formatDateWithPreferences, useDatePreferences} from "../text/FormattedDate.jsx";
9-
import {localeService} from "../../service/localeService.js";
8+
import {useI18nFriendlyLanguage} from "../../service/localeService.js";
9+
import {useDateFormatter} from "../../util/format/useDateFormatter.js";
1010

1111
export const activityGroupToColor = label => {
1212
switch (label) {
@@ -27,25 +27,16 @@ export const activityGroupToColor = label => {
2727

2828
const PlayerbaseGraph = ({data}) => {
2929
const {t} = useTranslation()
30-
const {nightModeEnabled, graphTheming} = useTheme();
31-
const datePreferences = useDatePreferences();
30+
const {graphTheming} = useTheme();
31+
const {formatDate} = useDateFormatter(false, {
32+
pattern: 'MMMM dd',
33+
recentDaysPattern: 'MMMM dd'
34+
});
3235

3336
const id = 'playerbase-graph';
3437

35-
useEffect(() => {
36-
Highcharts.setOptions({
37-
lang: {
38-
locale: localeService.getIntlFriendlyLocale(),
39-
noData: t('html.label.noDataToDisplay')
40-
}
41-
})
42-
Highcharts.setOptions(graphTheming);
43-
44-
const labels = data?.activity_labels.map(date => formatDateWithPreferences({
45-
...datePreferences,
46-
pattern: 'MMMM dd',
47-
recentDaysPattern: 'MMMM dd'
48-
}, date));
38+
const graphOptions = useMemo(() => {
39+
const labels = data?.activity_labels.map(formatDate);
4940
const series = data?.activity_series.map(dataSet => {
5041
return {
5142
...dataSet,
@@ -54,7 +45,7 @@ const PlayerbaseGraph = ({data}) => {
5445
}
5546
});
5647

57-
Highcharts.chart(id, {
48+
return {
5849
chart: {
5950
noData: t('html.label.noDataToDisplay'),
6051
type: "area"
@@ -79,8 +70,22 @@ const PlayerbaseGraph = ({data}) => {
7970
}
8071
},
8172
series: series
73+
};
74+
}, [t, data, formatDate]);
75+
76+
const locale = useI18nFriendlyLanguage();
77+
useEffect(() => {
78+
Highcharts.setOptions({
79+
lang: {
80+
locale: locale,
81+
noData: t('html.label.noDataToDisplay')
82+
}
8283
})
83-
}, [data, graphTheming, id, t, nightModeEnabled, datePreferences])
84+
}, [locale]);
85+
useEffect(() => {
86+
Highcharts.setOptions(graphTheming);
87+
Highcharts.chart(id, graphOptions)
88+
}, [graphTheming, id, t, graphOptions])
8489

8590
return (
8691
<div className="chart-area" id={id}>

0 commit comments

Comments
 (0)