I want the button to be disabled after clicking it for 1 hr with displaying the countdown for current logged in user, is it possible to store time in firebase? And retrieve it and i want the time to be continue even the client refreshes the site. Any ideas or suggestions
Advertisement
Answer
For your initial question (without Firebase), here is a quick example
JavaScript
x
25
25
1
const button = document.querySelector('#mybutton');
2
let sec = 5;
3
let countdown = null;
4
5
const updateButton = () => {
6
button.innerHTML = `wait ${sec}s`;
7
8
if (sec === 0) {
9
clearInterval(countdown);
10
sec = 5;
11
button.innerHTML = 'Click me';
12
button.disabled = false;
13
return;
14
}
15
16
sec--;
17
}
18
19
button.onclick = () => {
20
button.disabled = true;
21
updateButton();
22
countdown = setInterval(function() {
23
updateButton();
24
}, 1000);
25
}
JavaScript
1
1
1
<button id="mybutton">Click me</button>
I guess you could make calls to Firebase when you init the sec
variable and when you update it, but you could just use local storage for that as you would not add any security using Firebase to prevent any request to be sent.