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:
@@ -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 {
|
||||
setState(() {
|
||||
_loading = true;
|
||||
@@ -87,7 +114,7 @@ class _CartesFeedState extends State<CartesFeed> {
|
||||
);
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_items = items;
|
||||
_items = _trier(items);
|
||||
_loading = false;
|
||||
});
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) => _syncScrollFades());
|
||||
@@ -114,9 +141,9 @@ class _CartesFeedState extends State<CartesFeed> {
|
||||
);
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_items = [
|
||||
_items = _trier([
|
||||
for (final c in _items) if (c.id == updated.id) updated else c,
|
||||
];
|
||||
]);
|
||||
_busyCardId = null;
|
||||
});
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user