Skip to content

Commit

Permalink
5 minute timer on generator
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkarnold committed Oct 31, 2021
1 parent fbba5d1 commit 9e67fd0
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/app/components/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1270,20 +1270,20 @@ export class HomeComponent implements OnInit, OnDestroy {
alert("You must select a nation or random nationalities before generating a team");
return false
}
// let lastTime: any = localStorage.getItem('Last request time');
// if (lastTime !== null) {
// lastTime = parseInt(lastTime);
// let currentTime = new Date().getTime();
// if (lastTime + 300000 > currentTime) {
// let timeLeft = (lastTime + 300000) - currentTime;
// let min = Math.floor(timeLeft / 60000);
// let seconds = Math.round((timeLeft % 60000) / 1000)
// let str = seconds == 60 ? (min+1) + ":00" : min + ":" + (seconds < 10 ? "0" : "") + seconds;
let lastTime: any = localStorage.getItem('Last request time');
if (lastTime !== null) {
lastTime = parseInt(lastTime);
let currentTime = new Date().getTime();
if (lastTime + 300000 > currentTime) { // if 5 minutes haven't passed since last request
let timeLeft = (lastTime + 300000) - currentTime;
let min = Math.floor(timeLeft / 60000);
let seconds = Math.round((timeLeft % 60000) / 1000)
let str = seconds == 60 ? (min+1) + ":00" : min + ":" + (seconds < 10 ? "0" : "") + seconds;

// console.log(`Please wait for ${str} to generate a new team.`);
// return false;
// }
// }
alert(`Please wait ${str} to generate a new team.`);
return false;
}
}
if (this.players.length > 0) {
if (window.confirm("Are you sure? Any unsaved data will be deleted.")) {
this.resetStarters(true);
Expand Down Expand Up @@ -1425,7 +1425,6 @@ export class HomeComponent implements OnInit, OnDestroy {
}
});
// getMiddleName function
console.log(player, this.playerCount);
this.players.push(player);
this.sortedData.push(player);
this.playerCount++;
Expand Down

0 comments on commit 9e67fd0

Please sign in to comment.