Goals:
-Get stored time button was last clicked
-If stored time is greater than (>) Date.now() - delay then enable the button
I need to have this button operate as follows, mind you this is javascript done in Velo (Wix)
User click > grab current time of click to a database (done) check the time of the database against date.now and get a differential of time (done)
Now I need to write an if-else for enabling and disabling the button until a delayed disable is done.
Here is what I have written so far:
$w.onReady(function () {
$w.onReady( () => {
$w("#dataset2").onReady( () => {
const itemObj = $w("#dataset2").getCurrentItem();
const dateNow = new Date();
const updatedDate = itemObj._updatedDate;
const diffTime = Math.abs(updatedDate - dateNow);
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
console.log(diffTime + "milliseconds");
});
});
console.log("Site is ready & button enabled.");
});
export function button1_click_1(event) {
$w('#button1').label = "Currently Occupied"
if (diffTime > Date.now) {
setTimeout(function() {
$w("#button2").enable();
}, 20000);
} else if (Date.now < diffTime) {
$w('#button1').disable();
} else {
$w('#button1').enable();
console.log('Button Clicked and checked.');
}}