fix(#173): tri stable des bulles entre parents

Même ordre API (statut puis modifie_le) avec départage par id,
appliqué au chargement et après chaque réponse.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-10-05 12:21:25 +02:00
co-authored by Cursor
parent 0c736f5605
commit 5a73da898b
@@ -76,6 +76,33 @@ class _CartesFeedState extends State<CartesFeed> {
} }
} }
/// Aligné sur le tri API : refusées → ouvertes → traitées, puis
/// `modifie_le` DESC, `id` en départage (ordre stable entre parents).
static List<CarteBulle> _trier(List<CarteBulle> items) {
int rang(CarteStatut s) {
switch (s) {
case CarteStatut.refusee:
return 0;
case CarteStatut.ouverte:
return 1;
case CarteStatut.traitee:
return 2;
}
}
final out = List<CarteBulle>.from(items);
out.sort((a, b) {
final byStatut = rang(a.statut).compareTo(rang(b.statut));
if (byStatut != 0) return byStatut;
final am = a.modifieLe?.millisecondsSinceEpoch ?? 0;
final bm = b.modifieLe?.millisecondsSinceEpoch ?? 0;
final byModif = bm.compareTo(am); // DESC
if (byModif != 0) return byModif;
return a.id.compareTo(b.id);
});
return out;
}
Future<void> _load() async { Future<void> _load() async {
setState(() { setState(() {
_loading = true; _loading = true;
@@ -87,7 +114,7 @@ class _CartesFeedState extends State<CartesFeed> {
); );
if (!mounted) return; if (!mounted) return;
setState(() { setState(() {
_items = items; _items = _trier(items);
_loading = false; _loading = false;
}); });
WidgetsBinding.instance.addPostFrameCallback((_) => _syncScrollFades()); WidgetsBinding.instance.addPostFrameCallback((_) => _syncScrollFades());
@@ -114,9 +141,9 @@ class _CartesFeedState extends State<CartesFeed> {
); );
if (!mounted) return; if (!mounted) return;
setState(() { setState(() {
_items = [ _items = _trier([
for (final c in _items) if (c.id == updated.id) updated else c, for (final c in _items) if (c.id == updated.id) updated else c,
]; ]);
_busyCardId = null; _busyCardId = null;
}); });
} catch (e) { } catch (e) {