feat: update sorting options and default values in RicercaProvider; refine filter logic in RicercaFilters

This commit is contained in:
Marco Pedone 2025-11-11 15:54:04 +01:00
parent d116ebd3d5
commit 4ca16be4a4
3 changed files with 11 additions and 10 deletions

View file

@ -1,6 +1,5 @@
TODOS: TODOS:
- Modale Admin conferma, selettore per fast modifica di permanenza
- Modale admin conferma mostrare scorciatoia a doc lavoro o simile per facilitare la verifica e sezione per override pack in base a doc presentati
- Post modale conferma, mostrare se transitorio , modale con informativa tipo:" il saldo del servizio e il periodo di permanenza veranno adeguati alle condizioni stabilite insieme al locatore nel momento della trattativa e alla documentazione presentata come giustificazione di transitorietà" (modificato) - Post modale conferma, mostrare se transitorio , modale con informativa tipo:" il saldo del servizio e il periodo di permanenza veranno adeguati alle condizioni stabilite insieme al locatore nel momento della trattativa e alla documentazione presentata come giustificazione di transitorietà" (modificato)

View file

@ -238,7 +238,7 @@ const RicercaFilters = () => {
<SelectFilter <SelectFilter
defaultValue={sort} defaultValue={sort}
handleReset={async () => { handleReset={async () => {
await setSort(""); await setSort("Recenti");
}} }}
label={t.ordina_per} label={t.ordina_per}
onValueChange={async (value: SortTypes) => { onValueChange={async (value: SortTypes) => {
@ -451,12 +451,12 @@ export const SelectFilter = <T extends string>({
<Label <Label
className={cn( className={cn(
"font-semibold text-muted-foreground", "font-semibold text-muted-foreground",
value !== "" && "text-primary", value !== defaultValue && "text-primary",
)} )}
> >
{label} {label}
</Label> </Label>
{value !== "" && ( {value !== defaultValue && (
<button onClick={handleReset} type="button"> <button onClick={handleReset} type="button">
<RotateCcwIcon className="size-4" /> <RotateCcwIcon className="size-4" />
</button> </button>

View file

@ -50,7 +50,7 @@ type RicercaContextType = {
isLoading: boolean; isLoading: boolean;
}; };
const sortOptions = ["Recenti", "Prezzo", "Consegna", "Mq", ""] as const; const sortOptions = ["Recenti", "Prezzo", "Consegna", "Mq"] as const;
//sort as string union //sort as string union
export type SortTypes = (typeof sortOptions)[number]; export type SortTypes = (typeof sortOptions)[number];
@ -96,7 +96,7 @@ export const RicercaProvider: FC<{
const [sort, setSort] = useQueryState( const [sort, setSort] = useQueryState(
"sort", "sort",
parseAsStringLiteral(sortOptions) parseAsStringLiteral(sortOptions)
.withDefault("") .withDefault("Recenti")
.withOptions({ startTransition }), .withOptions({ startTransition }),
); );
@ -152,15 +152,17 @@ export const RicercaProvider: FC<{
await setTipo(""); await setTipo("");
await setComune(""); await setComune("");
await setConsegna(null); await setConsegna(null);
await setSort(""); await setSort("Recenti");
await setPage(0); await setPage(0);
}; };
const nFiltri = const nFiltri =
[tipo, comune, sort].reduce( [tipo, comune].reduce(
(count, item) => (item !== "" ? count + 1 : count), (count, item) => (item !== "" ? count + 1 : count),
0, 0,
) + (consegna !== null ? 1 : 0); ) +
(consegna !== null ? 1 : 0) +
(sort !== "Recenti" ? 1 : 0);
return ( return (
<RicercaContext.Provider <RicercaContext.Provider