feat(RicercaProvider): Sort unique values and enhance sorting logic for options based on proximity to the current month

This commit is contained in:
Marco Pedone 2025-10-30 09:42:21 +01:00
parent 4181223dae
commit afb1a24503

View file

@ -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 () => {