Hoi im havin an issue with
Auto incrementing a variable in wix automatons without manually updating it along with figuring out the groups feed/comment deletion api
Working in
Wix studio editor? (I think)
Site link
cannot provide as of moment (student time issues)
What I’m trying to do
Creating a groups feed flag system for trusted member badge holders to lessen stress on moderation (will send the content and creator of the post to a group outlook email first before deleting said comment but requires 2-5 flag to do such actions)
What I’ve tried so far
Looking in site api refs (I know 0 coding but ive stressed way too many times trying to figure the syntax out along with figuring what im supposed to edit)along with trying to use sum to increment the variable itself to +1 each time it runs (as you can imagine i failed horribly)
Extra context
Unable to provide more as of the moment
Based on the information you’ve shared, I believe you might want to look into the scope (which determines where the variable is used, either globally, within the function or within a block) and using variables and variable shadowing to so you can update for scopes.
It’s not the same function but I created this page where you can type in a number in the input field, submit it and it will be saved as a cookie so if you come back you can see the same number. You can also increase or decrease the number but on recalling or refreshing the page, you will get the original submitted number.
I don’t believe you need all of this but this might help give you some guidance though I would say to primarily focus on the button handler and seeing how that works in terms setting variables and updating them.
import { local } from '@wix/site-storage';
let currentNumber = null;
let savedNumber = null;
$w.onReady(async function () {
// Hide the text element by default
$w('#textNumber').hide();
// Try to get the saved number from local storage
let storedValue = await local.getItem('userNumber');
if (storedValue !== undefined && storedValue !== null && storedValue !== '') {
savedNumber = Number(storedValue);
currentNumber = savedNumber;
$w('#textNumber').text = String(currentNumber);
$w('#textNumber').show();
}
// Set up button handlers
$w('#submitButton').onClick(async () => {
let inputValue = $w('#ogNumber').value;
if (inputValue !== undefined && inputValue !== null && inputValue !== '') {
let num = Number(inputValue);
if (!isNaN(num)) {
currentNumber = num;
savedNumber = num;
await local.setItem('userNumber', String(num));
$w('#textNumber').text = String(currentNumber);
$w('#textNumber').show();
}
}
});
$w('#plusButton').onClick(() => {
if (currentNumber !== null) {
currentNumber += 1;
$w('#textNumber').text = String(currentNumber);
}
});
$w('#minusButton').onClick(() => {
if (currentNumber !== null) {
currentNumber -= 1;
$w('#textNumber').text = String(currentNumber);
}
});
$w('#recallButton').onClick(() => {
if (savedNumber !== null) {
currentNumber = savedNumber;
$w('#textNumber').text = String(currentNumber);
}
});
});