Files
pipelines/app/lib/features/chat/ui/sessions/session_row_style.dart
T
alan fe24f228fe fix(app): one relative-time style, day-aware durations, consistent visit wording
Review r2 findings P2-4, P2-5, P3-13: a shared relative-time helper for
every list row's time, formatDuration switches to days past 24h ('9d
16h'), the stage page uses one visit numbering, drops a repeated stage
heading and fixes '1 files', and search run hits read 'Run 1'.
Implemented by pipeline run #205/#207 (Terra); its UIReview blocked on a
fixture without timestamps, verified by the manager.
2026-10-31 12:29:16 +00:00

55 lines
2.0 KiB
Dart

import '../../../../core/api_gateway.dart';
import '../../../../ui/text/relative_time.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';
}
/// The shared list-row recency, or nothing for an unusable `updated_at`.
String relativeChatSessionTime(Object? updatedAt, {DateTime? now}) {
final millis = chatSessionMillis(updatedAt);
if (millis <= 0) return '';
return formatRelativeTime(
DateTime.fromMillisecondsSinceEpoch(millis),
now: now,
) ??
'';
}
/// The row's one muted line: the recorded model and the folder (home as `~`).
/// The harness is the row's avatar, so it is not repeated as a word.
String chatSessionSubtitle(JsonMap session) => [
'${session['model'] ?? ''}'.trim(),
homeRelativePath('${session['directory'] ?? ''}'.trim()),
].where((part) => part.isNotEmpty).join(' · ');
final _homePrefix = RegExp(r'^(/Users/[^/]+|/home/[^/]+|/root)(?=/|$)');
/// `/Users/alan/repos/x` (or `/home/alan/...`) as `~/repos/x`.
String homeRelativePath(String path) => path.replaceFirst(_homePrefix, '~');
/// The row's attention/state word: `Closed` takes precedence, otherwise only
/// actually unread content is `New`. Loading activity is rendered separately.
String? chatSessionRowStatus(JsonMap session, {required bool unseen}) {
if (session['closed_at'] != null || session['closed'] == true) {
return 'Closed';
}
return unseen ? 'New' : null;
}