feat(RicercaProvider): Sort unique values and enhance sorting logic for options based on proximity to the current month
This commit is contained in:
parent
4181223dae
commit
afb1a24503
1 changed files with 9 additions and 2 deletions
|
|
@ -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]);
|
}, [options, tipo, consegna]);
|
||||||
|
|
||||||
const consegnaOptions = useMemo(() => {
|
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]);
|
}, [options, tipo, comune]);
|
||||||
|
|
||||||
const ResetParams = async () => {
|
const ResetParams = async () => {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue