perf(app): quick slide page transitions, close work after the page leaves, instant star/close/reopen

This commit is contained in:
2026-10-24 00:47:32 +01:00
parent fe7311ade0
commit f997964761
5 changed files with 172 additions and 12 deletions
@@ -137,14 +137,23 @@ class ChatSessionsController extends ChangeNotifier {
}
}
Future<void> star(String sessionId, bool starred) =>
_mutate(sessionId, () => repository.star(sessionId, starred));
Future<void> star(String sessionId, bool starred) => _mutate(
sessionId,
() => repository.star(sessionId, starred),
patch: {'starred': starred},
);
Future<void> close(String sessionId) =>
_mutate(sessionId, () => repository.close(sessionId));
Future<void> close(String sessionId) => _mutate(
sessionId,
() => repository.close(sessionId),
patch: {'closed_at': DateTime.now().toUtc().toIso8601String()},
);
Future<void> reopen(String sessionId) =>
_mutate(sessionId, () => repository.reopen(sessionId));
Future<void> reopen(String sessionId) => _mutate(
sessionId,
() => repository.reopen(sessionId),
patch: {'closed_at': null},
);
/// Renames through the shared server field. Throws the server's refusal so the
/// open dialog can keep it in view; success refreshes the list from the server.
@@ -241,15 +250,29 @@ class ChatSessionsController extends ChangeNotifier {
_notify();
}
/// Applies [patch] to the row at once, so the list answers the tap
/// immediately, then saves it. The server's refusal puts the row back and
/// shows the reason; success re-reads the list in the background.
Future<void> _mutate(
String sessionId,
Future<JsonMap> Function() action,
) async {
Future<JsonMap> Function() action, {
JsonMap? patch,
}) async {
final before = _sessions;
if (patch != null) {
_sessions = [
for (final row in _sessions)
if ('${row['id'] ?? ''}' == sessionId) {...row, ...patch} else row,
];
_actionErrors.remove(sessionId);
_notify();
}
try {
await action();
_actionErrors.remove(sessionId);
await refresh();
unawaited(refresh());
} catch (error) {
if (patch != null) _sessions = before;
_actionErrors[sessionId] = '$error';
_notify();
}