Skip to content

Commit

Permalink
fix: update counter when load data opens
Browse files Browse the repository at this point in the history
  • Loading branch information
jsilva74 committed Dec 5, 2023
1 parent d71b4c4 commit 93c9e5a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
12 changes: 7 additions & 5 deletions src/Popups/Update.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ function UpdatePopup(props) {

const areas = React.useState(() => getAreas(props.icaodata, props.icaos))[0];

const hits= (storage.get('apiHits', [])).length
const [hits, setHits] = React.useState(0)

// Update custom area when map center is updated
React.useEffect(() => {
Expand Down Expand Up @@ -445,6 +445,8 @@ function UpdatePopup(props) {
const layers = l.filter(elm => jl.includes(elm.id));
setLayersOptions(l);
setJobsLayers(layers);
apiHits(false); // remove old entries from counter on init
setHits((storage.get('apiHits', [])).length);
}, [props.open, props.icaos, props.icaodata, props.settings.display.sim]);

// Update the number of request for loading jobs each time one input changes
Expand Down Expand Up @@ -505,7 +507,7 @@ function UpdatePopup(props) {
setLoading(false);
})
.finally(() => {
apiHits()
apiHits();
});
}
// Save jobs
Expand Down Expand Up @@ -599,7 +601,7 @@ function UpdatePopup(props) {
setLoading(false);
})
.finally(() => {
apiHits()
apiHits();
});
}
const updateOwnedPlanesRequest = (usernames, planes, callback) => {
Expand Down Expand Up @@ -631,7 +633,7 @@ function UpdatePopup(props) {
setLoading(false);
})
.finally(() => {
apiHits()
apiHits();
});
}
// Planes Update button clicked
Expand Down Expand Up @@ -723,7 +725,7 @@ function UpdatePopup(props) {
setLoading(false);
})
.finally(() => {
apiHits()
apiHits();
});
}

Expand Down
12 changes: 8 additions & 4 deletions src/util/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,12 @@ export function formatGPSCoord(lat, lng) {
}

// increments fse api hits counter
export function apiHits(){
const storage= new Storage()
const hits = storage.get('apiHits', [])?.filter(hit=> DateTime.now().diff(DateTime.fromMillis(hit), 'hours').hours < 7)
storage.set('apiHits', [...hits, DateTime.now().valueOf()])
export function apiHits(increment = true){
const storage= new Storage();
const hits = storage.get('apiHits', [])?.filter(hit => DateTime.now().diff(DateTime.fromMillis(hit), 'hours').hours < 7);
if (increment) {
storage.set('apiHits', [...hits, DateTime.now().valueOf()]);
return;
}
storage.set('apiHits', [...hits]);
}

0 comments on commit 93c9e5a

Please sign in to comment.