Need help in the final part of the code, which will prevent users from choosing more than one motivational card per day before midnight.
I did everything I could for my beginner's (0+) knowledge and will be grateful for some help!
Here how it works: the user scrolls through the gallery, clicks on the "pickCard" button, the database gives a random card (4 different values). After that, a message appears stating that "The attempt has been exhausted so far" and when the user enter the page again, all database values and the message must remain unchanged until midnight. Until know it works great, only the last part is out of my abilities to finish.
$w.onReady(function () {
$w('#gameCards').hide();
});
export function startButton_click(event) {
$w('#CardsIntro').hide();
$w('#gameCards').show();
$w('#cardGallery').show();
setTimeout(function () {
$w('#pickCard').show()
}, 1000);
}
export function pickCard_click(event, $w) {
let database = $w('#cardsDataset').getTotalCount();
let mixon = Math.floor(Math.random() * database);
$w('#cardsDataset').setCurrentItemIndex(mixon)
$w('#cardFrontText').show();
$w('#cardBackText').show();
$w('#recommendation').show();
$w('#explanation').show();
$w('#cardsWarning').show();
$w('#pickCard').hide();
$w('#cardGallery').pause();
}
//RANDOMIZING CARDS
function random(items) {
var settings = items.length, randomize, index;
while (0 !== settings) {
index = Math.floor(Math.random() * settings);
settings -= 1;
randomize = items[settings];
items[settings] = items[index];
items[settings] = randomize;
}
return items;
}
//FREEZE Dataset values onPageLeave and onPageEnter until midnight.
/*
var date = new Date();
var midnight = new Date();
midnight.setHours(23,59,59,0);
*/
I don't think that you can actually freeze a dataset so to speak, however what you can look at doing is to only allow the current user only the one submission per day and to save the cards values into Wix Storage so that you can recall them again when needed for that day.
As for the start button, you can simply look at getting the current time and then hiding that until a set time of your preference or for a set time period until it is shown again. For this you would be better off using the setTimeout method as that has an unlimited delay time option, whereas if you use the delay option from Wix inbuilt effect options then you are limited as that has a preset maximum delay that can't be changed.