saving udates, not missing much i guess
This commit is contained in:
@@ -6,6 +6,8 @@ const URLPlayerMaps = "http://localhost:8080/racetimer_endpoints-1.0/api/timers/
|
||||
const URLMaps = "http://localhost:8080/racetimer_endpoints-1.0/api/timers/map/";
|
||||
const URLAllMaps = "http://localhost:8080/racetimer_endpoints-1.0/api/timers/allmaps";
|
||||
const URLMapsSize = "http://localhost:8080/racetimer_endpoints-1.0/api/timers/mapsizecache";
|
||||
const URLSearchPlayers = "http://localhost:8080/racetimer_endpoints-1.0/api/timers/searchplayers/";
|
||||
const URLSearchMaps = "http://localhost:8080/racetimer_endpoints-1.0/api/timers/searchmaps/";
|
||||
|
||||
function handleHttpErrors(res) {
|
||||
if (!res.ok) {
|
||||
@@ -75,7 +77,25 @@ class DataFacade extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
getPlayerBadgesFromCache = async (steamID) => {
|
||||
const CachedTime = JSON.parse(localStorage.getItem("initialBadgesCachedplayers" + steamID));
|
||||
const timeExpired = CachedTime ? Date.now() - CachedTime : 0;
|
||||
//30 mins
|
||||
if (!CachedTime || timeExpired > 30 * 60000) {
|
||||
localStorage.setItem("initialBadgesCachedplayers" + steamID, JSON.stringify(Date.now()));
|
||||
localStorage.removeItem("player/badges/" + steamID)
|
||||
}
|
||||
var storageString = "player/badges/" + steamID;
|
||||
const badgesData = localStorage.getItem(storageString);
|
||||
if (badgesData) {
|
||||
const badges = JSON.parse(badgesData);
|
||||
return badges;
|
||||
} else {
|
||||
const badges = await trackPromise(fetch(URLPlayer + "badges/" + steamID).then(handleHttpErrors));
|
||||
localStorage.setItem(storageString, JSON.stringify(badges));
|
||||
return badges;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
getPlayerFromCache = async (steamID) => {
|
||||
@@ -173,5 +193,44 @@ class DataFacade extends React.Component {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getPlayersBySearchCache = async (keyword) => {
|
||||
const CachedTime = JSON.parse(localStorage.getItem("searchCache/time/" + keyword));
|
||||
const timeExpired = CachedTime ? Date.now() - CachedTime : 0;
|
||||
//30 mins
|
||||
if (!CachedTime || timeExpired > 30 * 60000) {
|
||||
localStorage.setItem("searchCache/time/" + keyword, JSON.stringify(Date.now()));
|
||||
localStorage.removeItem("searchCache/" + keyword)
|
||||
}
|
||||
var storageString = "searchCache/" + keyword;
|
||||
var searchData = localStorage.getItem(storageString);
|
||||
if (searchData) {
|
||||
const cachedSearch = JSON.parse(searchData)
|
||||
return cachedSearch;
|
||||
} else {
|
||||
const searchPlayers = await trackPromise(fetch(URLSearchPlayers + keyword).then(handleHttpErrors));
|
||||
localStorage.setItem(storageString, JSON.stringify(searchPlayers));
|
||||
return searchPlayers;
|
||||
}
|
||||
}
|
||||
getMapsBySearchCache = async(keyword) => {
|
||||
const CachedTime = JSON.parse(localStorage.getItem("searchCacheMaps/time/" + keyword));
|
||||
const timeExpired = CachedTime ? Date.now() - CachedTime : 0;
|
||||
//30 mins
|
||||
if (!CachedTime || timeExpired > 30 * 60000) {
|
||||
localStorage.setItem("searchCacheMaps/time/" + keyword, JSON.stringify(Date.now()));
|
||||
localStorage.removeItem("searchCacheMaps/" + keyword)
|
||||
}
|
||||
var storageString = "searchCache/" + keyword;
|
||||
var searchData = localStorage.getItem(storageString);
|
||||
if (searchData) {
|
||||
const cachedSearch = JSON.parse(searchData)
|
||||
return cachedSearch;
|
||||
} else {
|
||||
const searchMaps = await trackPromise(fetch(URLSearchMaps + keyword).then(handleHttpErrors));
|
||||
localStorage.setItem(storageString, JSON.stringify(searchMaps));
|
||||
return searchMaps;
|
||||
}
|
||||
}
|
||||
};
|
||||
export default new DataFacade();
|
||||
Reference in New Issue
Block a user