aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2021-12-26 01:19:37 -0600
committerIván Ávalos <avalos@disroot.org>2021-12-26 01:19:37 -0600
commit91a28424283de9a435a42018f5902078d7843aed (patch)
tree83d2efa26bdb47a264a6fbb793b80769be6b0e90
parentf03db519c6ea4c59430a27e06df3058accd67dd4 (diff)
downloadetbsa-traccar-web-91a28424283de9a435a42018f5902078d7843aed.tar.gz
etbsa-traccar-web-91a28424283de9a435a42018f5902078d7843aed.tar.bz2
etbsa-traccar-web-91a28424283de9a435a42018f5902078d7843aed.zip
Translated event type in notification
-rw-r--r--modern/src/SocketController.js10
-rw-r--r--modern/src/common/formatter.js2
2 files changed, 7 insertions, 5 deletions
diff --git a/modern/src/SocketController.js b/modern/src/SocketController.js
index ac95019..7718db8 100644
--- a/modern/src/SocketController.js
+++ b/modern/src/SocketController.js
@@ -4,18 +4,19 @@ import { useDispatch, useSelector, connect } from 'react-redux';
import { useHistory } from 'react-router-dom';
import { positionsActions, devicesActions, sessionActions } from './store';
import { useEffectAsync } from './reactHelper';
+import { useTranslation } from './LocalizationProvider';
-const displayNotifications = (events) => {
+const displayNotifications = (events, t) => {
if ('Notification' in window) {
if (Notification.permission === 'granted') {
events.forEach((event) => {
- const notification = new Notification(`Event: ${event.type}`);
+ const notification = new Notification(`Evento: ${t(event.type)}`);
setTimeout(notification.close.bind(notification), 4 * 1000);
});
} else if (Notification.permission !== 'denied') {
Notification.requestPermission((permission) => {
if (permission === 'granted') {
- displayNotifications(events);
+ displayNotifications(events, t);
}
});
}
@@ -25,6 +26,7 @@ const displayNotifications = (events) => {
const SocketController = () => {
const dispatch = useDispatch();
const history = useHistory();
+ const t = useTranslation();
const authenticated = useSelector((state) => !!state.session.user);
@@ -48,7 +50,7 @@ const SocketController = () => {
dispatch(positionsActions.update(data.positions));
}
if (data.events) {
- displayNotifications(data.events);
+ displayNotifications(data.events, t);
}
};
};
diff --git a/modern/src/common/formatter.js b/modern/src/common/formatter.js
index 87d8b00..d824e83 100644
--- a/modern/src/common/formatter.js
+++ b/modern/src/common/formatter.js
@@ -7,7 +7,7 @@ export const formatNumber = (value, precision = 1) => Number(value.toFixed(preci
export const formatDate = (value, locale = 'es') => value ? new Intl.DateTimeFormat(locale, {
dateStyle: 'medium',
timeStyle: 'short',
- hour12: true,
+ hourCycle: 'h12',
}).format(new Date(value)) : '';
export const formatPosition = (value, key, t, locale = 'es') => {