Я пытаюсь использовать окна оповещений для реализации запланированных уведомлений.Я получаю объект JSON из ответа API, содержащего все уведомления за день.Существует две категории уведомлений PTP
и Call back
.Первое уведомление пришло вовремя, но последующее уведомление задерживается на произвольное время от запланированного времени.Эта проблема происходит именно в Chrome.Firefox не дает мне этой проблемы.
Следует отметить, что Firefox обновляет окно, как только пользователь нажимает «Да» в окне предупреждения, но Chrome этого не делает.В чем здесь проблема?Похоже, проблема производительности.
import React, { Component } from "react";
import ReactDOM from "react-dom";
class Dashboard extends Component {
constructor(props) {
super(props);
this.state = {
ptp_list: {
"0": { customer_id: 0, ptp: "15:14:20", callback: "" },
"1": { customer_id: 1, ptp: "", callback1: "" },
"2": { customer_id: 2, ptp: "", callback: "" }
}
};
this.updatePTP = this.updatePTP.bind(this);
}
componentDidMount() {
this.updatePTP();
}
updatePTP() {
//initialize time variables
var currenttime = new Date();
var i = 0;
//find current time upto milliseconds
//get notifications list
var notificationsList = JSON.parse(JSON.stringify(this.state.ptp_list));
//store notifications list in localstorage
window.localStorage.setItem(Constant.PTP_LIST, JSON.stringify(notificationsList));
//find the number of ptp/callback notifications for the day
var objectsList = Object.keys(notificationsList).length;
for (var i = 0; i < objectsList; i++) {
var ptp_time_list = []; var callback_time_list = [];
var ptp_time_list_milli = new Date();
var callback_time_list_milli = new Date();
currenttime.setHours(currenttime.getHours(), currenttime.getMinutes(), currenttime.getSeconds(), currenttime.getMilliseconds());
//check PTP notifications
if (notificationsList[i].ptp != "" && notificationsList[i].ptp != null) {
//remove ':' from time
ptp_time_list.push(notificationsList[i].ptp.split(':'));
//create date object for storing time and to perform operations later while using setTimeout function
ptp_time_list_milli.setHours(ptp_time_list[0][0], ptp_time_list[0][1], ptp_time_list[0][2], 0);
if (ptp_time_list_milli >= currenttime) {
//set timeout for PTP notification alert
setTimeout(function (i) {
alert("PTP Reminder!\n\nCustomer ID : " + notificationsList[i].customer_id);
}, (ptp_time_list_milli - currenttime), i);
}
}
//same process as above
if (notificationsList[i].callback != "" && notificationsList[i].callback != null) {
callback_time_list.push(notificationsList[i].callback.split(':'));
callback_time_list_milli.setHours(callback_time_list[0][0], callback_time_list[0][1], callback_time_list[0][2], 0);
if (callback_time_list_milli >= currenttime) {
//set timeout for Call back notification alert
setTimeout(function (i) {
alert("Callback Reminder!\n\nCustomer ID : " + notificationsList[i].customer_id);
}, (callback_time_list_milli - currenttime), i);
}
}
}
}