From afb1a245031872e58cec24f8c06e6a1621fca7ee Mon Sep 17 00:00:00 2001 From: Marco Pedone Date: Thu, 30 Oct 2025 09:42:21 +0100 Subject: [PATCH] feat(RicercaProvider): Sort unique values and enhance sorting logic for options based on proximity to the current month --- apps/infoalloggi/src/providers/RicercaProvider.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/infoalloggi/src/providers/RicercaProvider.tsx b/apps/infoalloggi/src/providers/RicercaProvider.tsx index 1f8e397..aa84368 100644 --- a/apps/infoalloggi/src/providers/RicercaProvider.tsx +++ b/apps/infoalloggi/src/providers/RicercaProvider.tsx @@ -126,7 +126,7 @@ export const RicercaProvider: FC<{ } } }); - return Array.from(set); + return Array.from(set).sort((a, b) => a.localeCompare(b)); }, [options, tipo, consegna]); const consegnaOptions = useMemo(() => { @@ -138,7 +138,14 @@ export const RicercaProvider: FC<{ } } }); - return Array.from(set); + const currentMonth = new Date().getMonth() + 1; // 1-12 + + return Array.from(set).sort((a, b) => { + // Calculate distance from current month (wrapping around) + const distA = (a - currentMonth + 12) % 12; + const distB = (b - currentMonth + 12) % 12; + return distA - distB; + }); }, [options, tipo, comune]); const ResetParams = async () => {