41d30a4280
Split the 406-line chat session browser into a controller, body, shared adaptive primitives and separate standard Material and Cupertino lists and dialogs. Preserve the existing server directory/backend catalogs, instructions field, closed/starred grouping, directory headings and empty/no-match states. - keep refresh generations so stale replies are discarded - open a created chat immediately and refresh the list in the background - disable rename Save while the trimmed name is blank - label row actions per session, with the id on duplicate titles - wrap Cupertino empty/no-match/error messages instead of clipping, and give them a Cupertino text style under a bare MaterialApp - allow the Material rename helper to wrap at large text scales - cover both native branches, lifecycle ordering, create/rename/close/star and the Cupertino theme path with widget tests
52 lines
1.6 KiB
Dart
52 lines
1.6 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../../../core/api_gateway.dart';
|
|
import '../../domain/chat_sessions.dart';
|
|
|
|
/// Titles shared by more than one visible session, so row action labels can
|
|
/// add the session id the way the web client does.
|
|
Set<String> duplicateChatTitles(Iterable<JsonMap> sessions) {
|
|
final seen = <String>{};
|
|
final duplicates = <String>{};
|
|
for (final session in sessions) {
|
|
final title = chatSessionTitle(session);
|
|
if (!seen.add(title)) duplicates.add(title);
|
|
}
|
|
return duplicates;
|
|
}
|
|
|
|
String sessionActionsLabel(JsonMap session, Set<String> duplicateTitles) {
|
|
final title = chatSessionTitle(session);
|
|
return duplicateTitles.contains(title)
|
|
? 'Chat actions for $title (${session['id'] ?? ''})'
|
|
: 'Chat actions for $title';
|
|
}
|
|
|
|
String sessionSubtitle(JsonMap session) {
|
|
final directory = '${session['directory'] ?? ''}';
|
|
switch (chatSessionActivity(
|
|
running: session['running'] == true,
|
|
unseen: session['unseen'] == true,
|
|
)) {
|
|
case 'streaming':
|
|
return '$directory · Streaming';
|
|
case 'new':
|
|
return '$directory · New';
|
|
default:
|
|
return directory;
|
|
}
|
|
}
|
|
|
|
IconData sessionMaterialIcon(JsonMap session) {
|
|
if (session['running'] == true) return Icons.sync;
|
|
if (session['starred'] == true) return Icons.star;
|
|
return Icons.chat_bubble_outline;
|
|
}
|
|
|
|
IconData sessionCupertinoIcon(JsonMap session) {
|
|
if (session['running'] == true) return CupertinoIcons.arrow_2_circlepath;
|
|
if (session['starred'] == true) return CupertinoIcons.star_fill;
|
|
return CupertinoIcons.chat_bubble;
|
|
}
|