Serach Filtr Drop dowbn

import wixData from "wix-data";

 

$w.onReady(() => {

loadRegion();

});

 

let lastFilterWineName;

let lastFilterRegion;

let debounceTimer;

export function iTitle_keyPress_1(event, $w) {

if (debounceTimer) {

clearTimeout(debounceTimer);

debounceTimer = undefined;

}

debounceTimer = setTimeout(() => {

filter($w('#iTitle').value, lastFilterRegion);

}, 500);

}

 

export function iContinent_change_1(event, $w) {

filter(lastFilterRegion, $w('#iContinent').value);

}

 

function filter(wineName, region) {

if (lastFilterWineName !== wineName || lastFilterRegion !== region) {

let newFilter = wixData.filter();

if (wineName)

newFilter = newFilter.contains('wineName', wineName);

if (region)

newFilter = newFilter.contains('region', region);

$w('#dataset1').setFilter(newFilter);

lastFilterWineName = wineName;

lastFilterRegion = region;

}

}

 

function loadRegion() {

wixData.query('Region')

.find()

.then(res => {

let options = [{"value": '', "label": 'All Regions'}];

options.push(...res.items.map(Region => {

return {"value": Region.region, "label": Region.region};

}));

$w('#iContinent').options = options;

});

 

}