Stuck on Database Filtering

Hey everyone. Trying to code the following page:

http://www.ortizperformance.com/deals

It is functional, but not as intended. Currently the two sorting dropdowns act independently of each other. If I select one it shows relevant products, but when I select the other it only sorts by that one. These are using the native WixProducts dataset, with the following code:


import {local} from 'wix-storage';
import wixData from 'wix-data';

export async function brand_change(event) {
    defaultSort = await false;
    if (debounceTimer) {
        clearTimeout(debounceTimer);
        debounceTimer = undefined;
    }
    debounceTimer = setTimeout(() => {
        filter($w("#brand").value, collectionName);
    }, 200);
}

export async function collection_change(event) {
    defaultSort = await false;
    filter(filterBrand, $w("#collection").value);
}

let filterBrand;
let collectionName;

let debounceTimer;

async function filter(brand, collection) {
    if(filterBrand !== brand || collectionName !== collection) {
        let newFilter = wixData.filter();
        if(brand)
        newFilter = newFilter.contains('brand', brand);
        if(collection)
        newFilter = newFilter.hasSome('collections', [collection]);
    await $w("#dataset1").setFilter(newFilter);
    if(defaultSort === true) {
        $w("#dataset1").setSort(wixData.sort()
        .ascending("brand")
        );
        }
    }
}

my dataset is #dataset1, and the textboxes are #brand and #collection, respectively.

Any thoughts? I’ve used the code on my search page as well and it works flawlessly, but this section just doesn’t seem to want to play the same way.