From f4c34d3b7b752e4635cba9d6c9ee4813dcb9d79c Mon Sep 17 00:00:00 2001 From: i701 Date: Fri, 4 Jul 2025 23:11:01 +0500 Subject: [PATCH] =?UTF-8?q?feat:=20enhance=20dual-range-slider=20handling?= =?UTF-8?q?=20in=20DynamicFilter=20component=20=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/generic-filter.tsx | 59 +++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/components/generic-filter.tsx b/components/generic-filter.tsx index 6c00b4e..5ef3c53 100644 --- a/components/generic-filter.tsx +++ b/components/generic-filter.tsx @@ -315,25 +315,14 @@ export default function DynamicFilter< }> = []; for (const input of inputs) { - const urlValue = searchParams.get(input.name); - if (urlValue) { - if (input.type === "checkbox-group") { - const deserialize = input.deserialize || defaultDeserialize; - const deserialized = deserialize(urlValue); - if (deserialized.length > 0) { - filters.push({ - key: input.name, - value: deserialized, - label: input.label, - config: input, - }); - } - } else if (input.type === "dual-range-slider") { - const minValue = searchParams.get(`${input.name}_min`); - const maxValue = searchParams.get(`${input.name}_max`); - if (minValue && maxValue) { - const parsedMin = Number(minValue); - const parsedMax = Number(maxValue); + if (input.type === "dual-range-slider") { + const minValue = searchParams.get(`${input.name}_min`); + const maxValue = searchParams.get(`${input.name}_max`); + if (minValue && maxValue) { + const parsedMin = Number(minValue); + const parsedMax = Number(maxValue); + // Only show as applied filter if values are different from defaults + if (parsedMin !== input.min || parsedMax !== input.max) { filters.push({ key: input.name, value: [parsedMin, parsedMax], @@ -341,13 +330,29 @@ export default function DynamicFilter< config: input, }); } - } else { - filters.push({ - key: input.name, - value: urlValue, - label: input.label, - config: input, - }); + } + } else { + const urlValue = searchParams.get(input.name); + if (urlValue) { + if (input.type === "checkbox-group") { + const deserialize = input.deserialize || defaultDeserialize; + const deserialized = deserialize(urlValue); + if (deserialized.length > 0) { + filters.push({ + key: input.name, + value: deserialized, + label: input.label, + config: input, + }); + } + } else { + filters.push({ + key: input.name, + value: urlValue, + label: input.label, + config: input, + }); + } } } } @@ -577,4 +582,4 @@ export default function DynamicFilter< ); -} +} \ No newline at end of file