Added local storage to avoid all the api-requests getting called on every refresh of the page. Which again could lead to throttling

This commit is contained in:
Eli 2021-05-07 21:33:48 +02:00
parent 075ed56d1b
commit fa8de53a12
2 changed files with 12 additions and 3 deletions

View File

@ -1,6 +1,6 @@
{
"name": "react-calendar",
"version": "1.0.4",
"version": "1.0.10",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -122,8 +122,17 @@ export default class Calendar extends React.Component<ICalendarProps, ICalendarS
if (!this.props.list || !this.props.siteUrl || !this.props.eventStartDate.value || !this.props.eventEndDate.value) return;
this.userListPermissions = await this.spService.getUserPermissions(this.props.siteUrl, this.props.list);
const eventsData: IEventData[] = await this.spService.getEvents(escape(this.props.siteUrl), escape(this.props.list), this.props.eventStartDate.value, this.props.eventEndDate.value);
this.setState({ eventData: eventsData, hasError: false, errorMessage: "" });
let allEventsData: IEventData[];
if(window.localStorage.getItem("calendarEvents")){
allEventsData = JSON.parse(window.localStorage.getItem("calendarEvents"));
}else{
allEventsData = await this.spService.getEvents(escape(this.props.siteUrl), escape(this.props.list), this.props.eventStartDate.value, this.props.eventEndDate.value);
window.localStorage.setItem("calendarEvents", JSON.stringify(allEventsData));
}
// const eventsData: IEventData[] = await this.spService.getEvents(escape(this.props.siteUrl), escape(this.props.list), this.props.eventStartDate.value, this.props.eventEndDate.value);
this.setState({ eventData: allEventsData, hasError: false, errorMessage: "" });
} catch (error) {
this.setState({ hasError: true, errorMessage: error.message, isloading: false });
}