tri par défaut : annonces les plus récentes d'abord (liste, carte, geojson) au lieu du prix croissant
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2 changed files +10 −8
modified
frontend/src/search/MapSearch.tsx
+4 −4
@@ -55,9 +55,9 @@ const PAGE_SIZE = 20; // annonces par page (vue carte) | ||
| 55 | 55 | const QUEBEC = { lat: 46.82, lng: -71.25, zoom: 11 }; |
| 56 | 56 | |
| 57 | 57 | const SORT_CHOICES: { key: SearchSort; label: string }[] = [ |
| 58 | + { key: "recent", label: "Plus récentes" }, | |
| 58 | 59 | { key: "prix", label: "Prix croissant" }, |
| 59 | 60 | { key: "prix_desc", label: "Prix décroissant" }, |
| 60 | − { key: "recent", label: "Plus récentes" }, | |
| 61 | 61 | { key: "deal", label: "Meilleures affaires" }, |
| 62 | 62 | { key: "ka", label: "Meilleur KA Score" }, |
| 63 | 63 | ]; |
@@ -197,12 +197,12 @@ export default function MapSearch({ filters, onTotal }: MapSearchProps) { | ||
| 197 | 197 | |
| 198 | 198 | // --- état de recherche partagé (la « seule vérité ») --- |
| 199 | 199 | const [qy, setQy] = useState<Query>(() => { |
| 200 | − const sort = (initialParams.get("tri") as SearchSort | null) ?? "prix"; | |
| 200 | + const sort = (initialParams.get("tri") as SearchSort | null) ?? "recent"; | |
| 201 | 201 | const p = Number(initialParams.get("page")); |
| 202 | 202 | return { |
| 203 | 203 | bboxStr: null, // posé au premier geste ou « zone » restaurée |
| 204 | 204 | poly: initialParams.get("zone"), |
| 205 | − sort: SORT_CHOICES.some((s) => s.key === sort) ? sort : "prix", | |
| 205 | + sort: SORT_CHOICES.some((s) => s.key === sort) ? sort : "recent", | |
| 206 | 206 | page: Number.isFinite(p) && p >= 1 ? Math.floor(p) : 1, |
| 207 | 207 | }; |
| 208 | 208 | }); |
@@ -342,7 +342,7 @@ export default function MapSearch({ filters, onTotal }: MapSearchProps) { | ||
| 342 | 342 | const url = new URL(window.location.href); |
| 343 | 343 | const set = (k: string, v: string | null) => |
| 344 | 344 | v === null ? url.searchParams.delete(k) : url.searchParams.set(k, v); |
| 345 | − set("tri", qy.sort === "prix" ? null : qy.sort); | |
| 345 | + set("tri", qy.sort === "recent" ? null : qy.sort); | |
| 346 | 346 | set("page", qy.page > 1 ? String(qy.page) : null); |
| 347 | 347 | set("zone", qy.poly); |
| 348 | 348 | set("move", searchOnMove ? null : "0"); |
modified
louka/web.py
+6 −4
@@ -144,8 +144,10 @@ def list_listings( | ||
| 144 | 144 | elif sort == "ka": # meilleurs emplacements d'abord (KA Score global) |
| 145 | 145 | sql += (" ORDER BY ks.global IS NULL, ks.global DESC," |
| 146 | 146 | " price IS NULL, price ASC LIMIT ? OFFSET ?") |
| 147 | − else: | |
| 147 | + elif sort == "prix": | |
| 148 | 148 | sql += " ORDER BY price IS NULL, price ASC LIMIT ? OFFSET ?" |
| 149 | + else: # défaut : les plus récentes d'abord | |
| 150 | + sql += " ORDER BY first_seen DESC, price IS NULL, price ASC LIMIT ? OFFSET ?" | |
| 149 | 151 | args += [limit, offset] |
| 150 | 152 | rows = [_row_to_dict(r) for r in con.execute(sql, args).fetchall()] |
| 151 | 153 | con.close() |
@@ -233,7 +235,7 @@ def listings_geojson( | ||
| 233 | 235 | del args_all[0:4] |
| 234 | 236 | total_all = con.execute(f"SELECT COUNT(*) c FROM ({sql_all})", args_all).fetchone()["c"] |
| 235 | 237 | |
| 236 | − sql += " ORDER BY price IS NULL, price ASC LIMIT ?" | |
| 238 | + sql += " ORDER BY first_seen DESC LIMIT ?" | |
| 237 | 239 | args.append(limit) |
| 238 | 240 | |
| 239 | 241 | features = [] |
@@ -270,7 +272,7 @@ def listings_geojson( | ||
| 270 | 272 | _SEARCH_SORTS = { |
| 271 | 273 | "prix": " ORDER BY price IS NULL, price ASC", |
| 272 | 274 | "prix_desc": " ORDER BY price IS NULL, price DESC", |
| 273 | − "recent": " ORDER BY first_seen DESC", | |
| 275 | + "recent": " ORDER BY first_seen DESC, price IS NULL, price ASC", | |
| 274 | 276 | "deal": (" ORDER BY fv.deviation IS NULL, fv.deviation ASC," |
| 275 | 277 | " price IS NULL, price ASC"), |
| 276 | 278 | "ka": (" ORDER BY ks.global IS NULL, ks.global DESC," |
@@ -326,7 +328,7 @@ def search_unified( | ||
| 326 | 328 | bbox: str | None = None, # ouest,sud,est,nord (zone visible carte) |
| 327 | 329 | poly: str | None = None, # lng,lat;… (zone dessinée) |
| 328 | 330 | kascore_min: float | None = None, # KA Score global minimal (0-100) |
| 329 | − sort: str = "prix", # prix | prix_desc | recent | deal | ka | |
| 331 | + sort: str = "recent", # recent (défaut) | prix | prix_desc | deal | ka | |
| 330 | 332 | page: int = 1, |
| 331 | 333 | page_size: int = Query(20, ge=1, le=100), |
| 332 | 334 | include: str = "tout", # tout | liste (points inchangés côté client) |
| 333 | 335 | |