diff --git a/packages/dashboard/src/components/Storage.tsx b/packages/dashboard/src/components/Storage.tsx index 4fb48d9d..c65d4dab 100644 --- a/packages/dashboard/src/components/Storage.tsx +++ b/packages/dashboard/src/components/Storage.tsx @@ -43,7 +43,6 @@ export function Storage({ path }: StorageProps) { {contents ? ( a < b, + "<=": (a: number, b: number) => a <= b, + ">": (a: number, b: number) => a > b, + ">=": (a: number, b: number) => a >= b, +} as const; + export function filterVariants(variants: Variant[], resolution: string) { const [operator, value] = resolution.split(" "); const height = parseInt(value, 10); - if (operator === "<") { - return variants.filter( - (item) => item.resolution && item.resolution?.height < height, - ); - } - - if (operator === "<=") { - return variants.filter( - (item) => item.resolution && item.resolution?.height <= height, - ); - } - - if (operator === ">") { - return variants.filter( - (item) => item.resolution && item.resolution?.height > height, - ); - } - - if (operator === ">=") { - return variants.filter( - (item) => item.resolution && item.resolution?.height >= height, - ); + const fn = FILTER_VARIANTS_OPERATOR[operator]; + if (typeof fn !== "function") { + throw new Error(`Invalid filter: ${operator} ${value}`); } - throw new Error("Invalid filter"); + return variants.filter( + (item) => item.resolution && fn(item.resolution.height, height), + ); }