Files
pipelines/app/lib/features/chat/ui/sessions/chat_sessions_body.dart
T
alan f7b5958d64 App: chat colours, Ctrl+1-9 opens the Nth list item, starred chats alphabetical
A chat's colour is picked from its row menu (Colour...), a long-press or
the chat information sheet. The list shows it as a leading bar, a faint
row tint and a coloured avatar; the open chat shows a faint wash under its
top bar. Shades are Cupertino's dynamic system colours and Material
swatches tuned per brightness. Changes from other devices apply live.

Ctrl+1...Ctrl+9 open the Nth item of the open tab's list (chats, runs,
pipelines) in on-screen order, also while typing. Starred chats are sorted
by name, case-insensitively, as one alphabetical group.
2026-11-03 11:05:38 +00:00

117 lines
3.5 KiB
Dart

import 'package:flutter/material.dart';
import '../../../../core/api_gateway.dart';
import '../../domain/chat_sessions.dart';
import 'chat_adaptive.dart';
import 'session_list_cupertino.dart';
import 'session_list_material.dart';
import 'session_row_style.dart';
typedef ChatSessionSection = ({String title, List<JsonMap> sessions});
/// Which list sections are folded away, kept by the list's screen so the
/// keyboard shortcuts count only rows on screen. Closed starts folded.
class ChatSectionFolds {
final Set<String> _folded = {'Closed'};
bool isOpen(String title) => !_folded.contains(title);
void set(String title, bool open) =>
open ? _folded.remove(title) : _folded.add(title);
}
/// Groups the visible sessions the way the server reports them.
class ChatSessionsBody extends StatelessWidget {
const ChatSessionsBody({
super.key,
required this.sessions,
required this.query,
required this.loading,
required this.error,
required this.onOpen,
required this.onRename,
required this.onClose,
required this.onReopen,
required this.onStar,
this.onColor,
required this.onHide,
required this.onClearSearch,
required this.isUnseen,
required this.errorFor,
this.folds,
this.activeSessionId,
this.onDismissError,
});
final ChatSectionFolds? folds;
final List<JsonMap> sessions;
final String? activeSessionId;
final String query;
final bool loading;
final String? error;
final ValueChanged<JsonMap> onOpen;
final ValueChanged<JsonMap> onRename;
final ValueChanged<JsonMap> onClose;
final ValueChanged<JsonMap> onReopen;
final ValueChanged<JsonMap> onStar;
final ValueChanged<JsonMap>? onColor;
final ValueChanged<JsonMap> onHide;
final VoidCallback onClearSearch;
final bool Function(JsonMap) isUnseen;
final String? Function(String sessionId) errorFor;
final ValueChanged<String>? onDismissError;
@override
Widget build(BuildContext context) {
final visible = filterChatSessions(sessions, query);
final sections = chatSessionSections(visible);
final emptyMessage = sessions.isEmpty
? error == null
? 'No chat sessions on this server yet.'
: null
: 'No chats match "${query.trim()}".';
if (loading && sessions.isEmpty) return const ChatLoadingIndicator();
final clearSearch = query.trim().isEmpty ? null : onClearSearch;
final duplicateTitles = duplicateChatTitles(visible);
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
return CupertinoSessionList(
sections: sections,
folds: folds,
activeSessionId: activeSessionId,
emptyMessage: visible.isEmpty ? emptyMessage : null,
duplicateTitles: duplicateTitles,
onOpen: onOpen,
onRename: onRename,
onClose: onClose,
onReopen: onReopen,
onStar: onStar,
onColor: onColor,
onHide: onHide,
onClearSearch: clearSearch,
isUnseen: isUnseen,
errorFor: errorFor,
onDismissError: onDismissError,
);
}
return MaterialSessionList(
sections: sections,
folds: folds,
activeSessionId: activeSessionId,
emptyMessage: visible.isEmpty ? emptyMessage : null,
duplicateTitles: duplicateTitles,
onOpen: onOpen,
onRename: onRename,
onClose: onClose,
onReopen: onReopen,
onStar: onStar,
onColor: onColor,
onHide: onHide,
onClearSearch: clearSearch,
isUnseen: isUnseen,
errorFor: errorFor,
onDismissError: onDismissError,
);
}
}