updated filter functions

This commit is contained in:
Xinrui Chen 2022-09-03 18:16:48 -07:00
parent b5cbaffca3
commit b62e9b96c3
2 changed files with 15 additions and 9 deletions

View File

@ -22,6 +22,6 @@
}
.container {
@apply text-sm flex rounded-md pl-2 pr-2 pt-1 pb-1 bg-gray-200;
@apply text-sm flex rounded-md pl-2 pr-2 pt-1 pb-1 bg-gray-200 w-auto;
}
</style>

View File

@ -7,15 +7,21 @@
const stars = ['⭐ ⬆', '⭐⭐ ⬆', '⭐⭐⭐ ⬆', '⭐⭐⭐⭐ ⬆', '⭐⭐⭐⭐⭐ ⬆'];
const filterProducts = (name, otherVal, { rating = '', tag = '', $tags = [] }) => {
const filterArgs = (name) => (name === 'rating' ? { value: rating } : { value: tag, $tags });
const otherFilterArgs = (name) =>
name === 'rating' ? { value: otherVal } : { value: otherVal, $tags };
const otherValName = name === 'rating' ? 'tag' : 'rating';
const { otherValName, filterArgs, otherFilterArgs } =
name === 'rating'
? {
otherValName: 'tag',
filterArgs: { value: rating },
otherFilterArgs: { value: otherVal, $tags }
}
: {
otherValName: 'rating',
filterArgs: { value: tag, $tags },
otherFilterArgs: { value: otherVal }
};
const filterOne = filterProductsBy(name, $products, filterArgs(name));
const filterBoth = filterProductsBy(otherValName, filterOne, otherFilterArgs(otherValName));
console.log(filterOne, filterBoth);
const filterOne = filterProductsBy(name, $products, filterArgs);
const filterBoth = filterProductsBy(otherValName, filterOne, otherFilterArgs);
return otherVal ? filterBoth : filterOne;
};