Filterable Gallery by Dropdown

Hi all!

I’m trying to create a gallery that is filterable by a dropdown menu with no success. I read every possible thread and tutorial. This is where I’m standing:

This is the gallery and dropdown:


I managed to get the dropdown and the gallery to show the corresponding database items:


But when I choose an option from the dropdown, nothing shows in the gallery and the dropdown stops working:

Here’s the code I’m using for onChange on the dropdown menu:

import wixData from “wix-data”;

$w.onReady(() => {
loadCategories();
});

let lastFilterCategory;

export function iCategory_change(event, $w) {
filter($w(‘#iCategory’).value);
}

function filter(category) {
if (lastFilterCategory !== category) {
let newFilter = wixData.filter();

if (category)
newFilter = newFilter.contains(‘category’, category);
$w(‘#dataset1’).setFilter(newFilter);
lastFilterCategory = category;
}
}

function loadCategories() {
wixData.query(‘category’)
.find()
.then(res => {
let options = [{“value”: ‘’, “label”: ‘כל הקטגוריות’}];
options.push(…res.items.map(continent => {
return {“value”: continent.title, “label”: continent.title};
}));
$w(‘#iCategory’).options = options;
});

}

Any idea what’s wrong?
Bonus question: how do I get rid of duplicates in the dropdown menu?

Thanks a lot,
Yuval.