Added save to local storage so that the api-calls to getLocalTime is not made for every event, on every refresh. No the code will first compare the results with the localStorage results - and if they are equal - use the local to display the event. If they are not equal, the for loop will run like before. WARNING: This triggers a bug in the 'week'-view. Have not fixed this yet
This commit is contained in:
parent
4fad8bd29e
commit
76c8cbcd96
|
@ -490,7 +490,7 @@ export default class spservices {
|
|||
|
||||
if (results && results.Row.length > 0) {
|
||||
let event: any = '';
|
||||
|
||||
const mapEvents = async () : Promise<boolean> => {
|
||||
for (event of results.Row) {
|
||||
const eventDate = await this.getLocalTime(event.EventDate);
|
||||
const endDate = await this.getLocalTime(event.EndDate);
|
||||
|
@ -541,6 +541,27 @@ export default class spservices {
|
|||
|
||||
let parseEvt: parseRecurrentEvent = new parseRecurrentEvent();
|
||||
events = parseEvt.parseEvents(events, null, null);
|
||||
return true;
|
||||
};
|
||||
//Checks to see if there are any results saved in local storage
|
||||
if(window.localStorage.getItem("eventResult")){
|
||||
//if there is a local version - compares it to the current version
|
||||
if(window.localStorage.getItem("eventResult") === JSON.stringify(results)){
|
||||
//No update needed use current savedEvents
|
||||
events = JSON.parse(window.localStorage.getItem("calendarEventsWithLocalTime"));
|
||||
}else{
|
||||
//update local storage
|
||||
window.localStorage.setItem("eventResult", JSON.stringify(results));
|
||||
//when they are not equal then we loop through the results and maps them to IEventData
|
||||
/* tslint:disable:no-unused-expression */
|
||||
await mapEvents() ? window.localStorage.setItem("calendarEventsWithLocalTime", JSON.stringify(events)) : null;
|
||||
}
|
||||
}else{
|
||||
//if there is no local storage of the events we create them
|
||||
window.localStorage.setItem("eventResult", JSON.stringify(results));
|
||||
//we also needs to map through the events the first time and save the mapped version to local storage
|
||||
await mapEvents() ? window.localStorage.setItem("calendarEventsWithLocalTime", JSON.stringify(events)) : null;
|
||||
}
|
||||
}
|
||||
|
||||
// Return Data
|
||||
|
|
Loading…
Reference in New Issue