I am trying to show items from my Clues collection in a repeater, however, I am trying to filter out items based on a query for another collection Inputs.
My code is:
import wixData from 'wix-data';
import { authentication, currentMember } from 'wix-members-frontend';
let memberId, memberEmail;
$w.onReady(async function () {
console.log("Loading Clues Page");
const thisMember = await currentMember.getMember();
memberEmail = thisMember.loginEmail
$w("#datasetClues").onReady((event) => {
$w("#repeaterClues").forEachItem( ($item, itemData, index) => {
let answered = false;
console.log(memberEmail, itemData.title) <=email and title load properly here
answered = getUserInput(memberEmail,itemData.title)
console.log("Call getUserInput")
if(answered === true){
console.log("Hide Clue")
itemData.showClue = false;
}
else {
console.log("Show Clue")
itemData.showClue = true;
}
} );
} );
$w('#datasetClues').setFilter(wixData.filter()
.eq("showClue",true))
});
export function getUserInput(userid,clueid){
console.log("Call getUserInput")
let answered = false;
wixData.query('Inputs')
.eq('clueId',clueid)
.eq('userId',userid)
.count()
.then( (results) =>{
let count = results;
console.log(count)
if(count === 1){
answered = true
}
})
return answered
}
Right now, the count always returns 0. Iāve tried with just one .eq statement and neither filters it. When I comment out the two .eq queries and run a count on all items in Inputs, it shows the right count.
The Inputs collection has a reference field of ClueId and UserId for when a user answers a clue.
Am I even approaching this correctly? Iāve looked into hooks and tried to do the query on Inputs there but that didnāt seem to work at all.
Any help or direction is appreciated, thanks!