I have a dataset that I have filtered by the current user (based on currentUser.getEmail) when it loads, so that users can see what’s in their account. I wanted to add a dropdown and a search bar so that they could further refine the content, and have followed the tutorials posted. The basic functionality works, however the dropdown/search bar filters run against the entire dataset, instead of the dataset filtered by the current user, so they no longer see just their items. I have tried to add a similar userEmail filter, but it doesn’t seem to be working. Any help would be greatly appreciated! Code below.
Note: I need to filter by current user and not owner because I am the one uploading the content into their accounts
import wixUsers from ‘wix-users’ ;
import wixData from ‘wix-data’ ;
$w.onReady( async function () {
let userEmail = await wixUsers.currentUser.getEmail()
$w( “#memberVc” ).onReady(() => {
$w( “#memberVc” ).setFilter(wixData.filter().eq( “userEmail” , userEmail))
});
});
$w.onReady(() => {
loadAgeRecommendation();
});
let lastFilterFood;
let lastFilterRecommendation;
let debounceTimer
export function iFood_keyPress(event,$w) {
if (debounceTimer){
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w( ‘#iFood’ ).value, lastFilterRecommendation);
}, 200 );
}
export function iRecommendation_change(event,$w) {
filter(lastFilterFood,$w( ‘#iRecommendation’ ).value);
}
function filter(food,ageRecommendation){
if (lastFilterFood !== food || lastFilterRecommendation !== ageRecommendation) {
let newFilter = wixData.filter();
if (food)
newFilter = newFilter.contains( ‘foodName’ ,food);
if (ageRecommendation)
newFilter = newFilter.contains( ‘ageRecommendation’ ,ageRecommendation);
let userEmail = wixUsers.currentUser.getEmail()
let emailFilter = wixData.filter().eq( ‘userEmail’ ,userEmail);
$w( ‘#memberVc’ ).setFilter(newFilter,emailFilter);
lastFilterFood = food;
lastFilterRecommendation = ageRecommendation;
}
}
function loadAgeRecommendation() {
wixData.query( “MemberVC” )
.limit( 10 )
.ascending( “ageRecommendation” )
.distinct( “ageRecommendation” )
.then(results => {
let distinctList = buildOptions(results.items);
distinctList.unshift({ “value” : ‘’ , “label” : ‘All Recommendations’ });
$w( “#iRecommendation” ).options = distinctList;
});
}
function buildOptions(items) {
return items.map(curr => {
return { label: curr, value: curr };
});
}