From c5119146f2a769ab50f337ca91c7501e975d63ae Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Fri, 23 Oct 2026 12:40:37 +0100 Subject: [PATCH] fix(app): chat rows put the state word on the title line and recency in the meta, as on the web --- .../ui/sessions/session_list_cupertino.dart | 32 ++++++------ .../ui/sessions/session_list_material.dart | 33 ++++++------ .../chat/ui/sessions/session_row_content.dart | 52 +------------------ .../chat/ui/sessions/session_row_style.dart | 7 +++ .../chat_session_row_layout_test.dart | 31 ++++++----- .../chat_session_row_material_test.dart | 21 +++++--- 6 files changed, 69 insertions(+), 107 deletions(-) diff --git a/app/lib/features/chat/ui/sessions/session_list_cupertino.dart b/app/lib/features/chat/ui/sessions/session_list_cupertino.dart index 446a63ae..2c65c062 100644 --- a/app/lib/features/chat/ui/sessions/session_list_cupertino.dart +++ b/app/lib/features/chat/ui/sessions/session_list_cupertino.dart @@ -126,16 +126,13 @@ class _CupertinoSessionRow extends StatelessWidget { Widget build(BuildContext context) { final id = '${session['id'] ?? ''}'; // Cupertino's grouped list owns the separators and the native tile metrics; - // the row only decides where the title, its muted meta and the recency go. - // The recency sits at the trailing edge of the title line at the tile's - // body size; the meta line keeps the tile's native 12pt subtitle style by + // the row only decides where the title, its state word and the muted meta + // go. The meta line (recency first) keeps the tile's native 12pt style by // passing colour only, so `Text` merges with `CupertinoListTile`'s own // `DefaultTextStyle` instead of overriding it with the title's size. final theme = CupertinoTheme.of(context); final secondary = CupertinoColors.secondaryLabel.resolveFrom(context); - final timeStyle = theme.textTheme.textStyle.copyWith(color: secondary); - final time = relativeChatSessionTime(session['updated_at']); - final meta = chatSessionMeta(session); + final meta = chatSessionRowMetaLine(session); final status = chatSessionRowStatus(session, unseen: unseen); final statusStyle = TextStyle( color: status == 'Closed' ? secondary : theme.primaryColor, @@ -143,18 +140,21 @@ class _CupertinoSessionRow extends StatelessWidget { return CupertinoListTile( key: Key('chat-row-$id'), leading: Icon(sessionCupertinoIcon(session)), - title: ChatSessionRowTitle( - title: chatSessionTitle(session), - time: time, - timeStyle: timeStyle, + // As on the web: the title with the unread/closed word trailing, then + // the muted `recency · directory · model` line. + title: ChatSessionRowMeta( + meta: chatSessionTitle(session), + status: status, + metaStyle: const TextStyle(), + statusStyle: statusStyle, ), - subtitle: meta.isEmpty && status == null + subtitle: meta.isEmpty ? null - : ChatSessionRowMeta( - meta: meta, - status: status, - metaStyle: TextStyle(color: secondary), - statusStyle: statusStyle, + : Text( + meta, + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: TextStyle(color: secondary), ), onTap: () => onOpen(session), trailing: Row( diff --git a/app/lib/features/chat/ui/sessions/session_list_material.dart b/app/lib/features/chat/ui/sessions/session_list_material.dart index 94c73545..c0140999 100644 --- a/app/lib/features/chat/ui/sessions/session_list_material.dart +++ b/app/lib/features/chat/ui/sessions/session_list_material.dart @@ -139,18 +139,14 @@ class _MaterialSessionRow extends StatelessWidget { @override Widget build(BuildContext context) { final id = '${session['id'] ?? ''}'; - // The same content as the Cupertino row: title with trailing recency, then - // a muted `directory · model` line with the unread/closed word trailing. + // The same content as the Cupertino row: title with the unread/closed word + // trailing, then a muted `recency · directory · model` line. // `ListTile` does not force one ellipsised line like `CupertinoListTile`, // so both text widgets state their line limit themselves. The meta line // passes colour only, so it keeps the tile's native subtitle style. final theme = Theme.of(context); final secondary = theme.colorScheme.onSurfaceVariant; - final timeStyle = - theme.textTheme.bodyMedium?.copyWith(color: secondary) ?? - TextStyle(color: secondary); - final time = relativeChatSessionTime(session['updated_at']); - final meta = chatSessionMeta(session); + final meta = chatSessionRowMetaLine(session); final status = chatSessionRowStatus(session, unseen: unseen); final statusStyle = TextStyle( color: status == 'Closed' ? secondary : theme.colorScheme.primary, @@ -158,18 +154,21 @@ class _MaterialSessionRow extends StatelessWidget { return ListTile( key: Key('chat-row-$id'), leading: Icon(sessionMaterialIcon(session)), - title: ChatSessionRowTitle( - title: chatSessionTitle(session), - time: time, - timeStyle: timeStyle, + // As on the web: the title with the unread/closed word trailing, then + // the muted `recency · directory · model` line. + title: ChatSessionRowMeta( + meta: chatSessionTitle(session), + status: status, + metaStyle: const TextStyle(), + statusStyle: statusStyle, ), - subtitle: meta.isEmpty && status == null + subtitle: meta.isEmpty ? null - : ChatSessionRowMeta( - meta: meta, - status: status, - metaStyle: TextStyle(color: secondary), - statusStyle: statusStyle, + : Text( + meta, + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: TextStyle(color: secondary), ), onTap: () => onOpen(session), trailing: Row( diff --git a/app/lib/features/chat/ui/sessions/session_row_content.dart b/app/lib/features/chat/ui/sessions/session_row_content.dart index 002f7ef6..795575c9 100644 --- a/app/lib/features/chat/ui/sessions/session_row_content.dart +++ b/app/lib/features/chat/ui/sessions/session_row_content.dart @@ -1,55 +1,7 @@ import 'package:flutter/material.dart'; -/// The title line of a chat session row: the session's name, with its relative -/// recency at the trailing edge. Shared by the Material and Cupertino rows so -/// both hosts arrange the same facts the same way. -/// -/// The recency takes at most 45% of the text column and ellipsises there, so a -/// long title keeps the larger share and a short row never overflows. The -/// recency is supplementary: at very large text scales it is the part that -/// gives way, while the session's name and state word stay whole. -class ChatSessionRowTitle extends StatelessWidget { - const ChatSessionRowTitle({ - super.key, - required this.title, - required this.time, - required this.timeStyle, - }); - - final String title; - final String time; - final TextStyle timeStyle; - - @override - Widget build(BuildContext context) { - return LayoutBuilder( - builder: (context, constraints) => Row( - children: [ - Expanded( - child: Text(title, maxLines: 1, overflow: TextOverflow.ellipsis), - ), - if (time.isNotEmpty) ...[ - const SizedBox(width: 8), - ConstrainedBox( - constraints: BoxConstraints( - maxWidth: constraints.maxWidth * 0.45, - ), - child: Text( - time, - maxLines: 1, - overflow: TextOverflow.ellipsis, - style: timeStyle, - ), - ), - ], - ], - ), - ); - } -} - -/// The muted second line of a chat session row: the recorded directory and -/// model, with the unread/closed word at the trailing edge. +/// A chat session row line with the unread/closed word at its trailing edge: +/// the row's title line, as on the web. /// /// The directory/model is the part that ellipsises; the state word is the row's /// only unread marker, so it keeps its intrinsic width and the metadata shrinks diff --git a/app/lib/features/chat/ui/sessions/session_row_style.dart b/app/lib/features/chat/ui/sessions/session_row_style.dart index 98e94fdc..5755ea99 100644 --- a/app/lib/features/chat/ui/sessions/session_row_style.dart +++ b/app/lib/features/chat/ui/sessions/session_row_style.dart @@ -50,6 +50,13 @@ String chatSessionMeta(JsonMap session) => [ '${session['model'] ?? ''}'.trim(), ].where((part) => part.isNotEmpty).join(' · '); +/// The row's muted second line as the web words it: recency first, then the +/// directory and model (`1 day ago · /srv/probe · model-a`). +String chatSessionRowMetaLine(JsonMap session, {DateTime? now}) => [ + relativeChatSessionTime(session['updated_at'], now: now), + chatSessionMeta(session), +].where((part) => part.isNotEmpty).join(' · '); + /// The word on the row's trailing edge while the session has news or a state: /// `Closed` from the row, otherwise `New`. A streaming session deliberately /// says nothing, as on the web, where the row's activity logo carries it. diff --git a/app/test/features/chat/ui/sessions/chat_session_row_layout_test.dart b/app/test/features/chat/ui/sessions/chat_session_row_layout_test.dart index 04c69c4a..0a1602b6 100644 --- a/app/test/features/chat/ui/sessions/chat_session_row_layout_test.dart +++ b/app/test/features/chat/ui/sessions/chat_session_row_layout_test.dart @@ -154,22 +154,27 @@ void main() { isUnseen: (session) => session['id'] == 's1', ); - // The unread word trails the muted meta line; the recency trails the title. + // As on the web: the unread word trails the title; the muted meta line + // leads with the recency. expect(find.text('Starred chat'), findsOneWidget); - expect(find.text('/work · model-a'), findsOneWidget); - expect(find.text('5 min ago'), findsOneWidget); + expect(find.text('5 min ago · /work · model-a'), findsOneWidget); expect(find.text('New'), findsOneWidget); - expect(find.text('/work'), findsOneWidget); - expect(find.text('2 hr ago'), findsOneWidget); + expect(find.text('2 hr ago · /work'), findsOneWidget); + expect( + (tester.getCenter(find.text('Starred chat')).dy - + tester.getCenter(find.text('New')).dy) + .abs(), + lessThan(4), + ); // The meta line keeps `CupertinoListTile`'s native 12pt subtitle style; it // must not be rendered at the title's body size. The colour-only style the // row passes merges with the tile's own `DefaultTextStyle`. final titleStyle = _styleOf(tester, 'Starred chat'); - final metaStyle = _styleOf(tester, '/work · model-a'); + final metaStyle = _styleOf(tester, '5 min ago · /work · model-a'); expect(metaStyle.fontSize, lessThan(titleStyle.fontSize!)); expect(metaStyle.fontSize, 12.0); - expect(_styleOf(tester, 'New').fontSize, metaStyle.fontSize); + expect(_styleOf(tester, 'New').fontSize, titleStyle.fontSize); // Each session is still its own native tile with its own actions, so the // inset group draws the separator between them. @@ -210,7 +215,7 @@ void main() { expect(tester.takeException(), isNull); const title = 'A conversation title long enough to need an ellipsis'; const meta = - '/a/very/long/directory/that/must/ellipsise · ' + '3 days ago · /a/very/long/directory/that/must/ellipsise · ' 'provider/an-extremely-long-recorded-model-id'; final titleParagraph = tester.renderObject( find.text(title), @@ -239,16 +244,10 @@ void main() { ); } - // The recency is supplementary, so it is the part that ellipsises here; it - // still keeps its single line at the trailing edge of the title line. - final recency = tester.renderObject( - find.text('3 days ago'), - ); - expect(recency.maxLines, 1); - expect(recency.didExceedMaxLines, isTrue); + // The word shares the title's line, as on the web. expect( (tester.getCenter(find.text(title)).dy - - tester.getCenter(find.text('3 days ago')).dy) + tester.getCenter(find.text('New')).dy) .abs(), lessThan(20), ); diff --git a/app/test/features/chat/ui/sessions/chat_session_row_material_test.dart b/app/test/features/chat/ui/sessions/chat_session_row_material_test.dart index 7424d22a..eeb951ff 100644 --- a/app/test/features/chat/ui/sessions/chat_session_row_material_test.dart +++ b/app/test/features/chat/ui/sessions/chat_session_row_material_test.dart @@ -73,15 +73,20 @@ void main() { ], isUnseen: (session) => session['id'] == 's1'); expect(find.text('Starred chat'), findsOneWidget); - expect(find.text('/work · model-a'), findsOneWidget); - expect(find.text('5 min ago'), findsOneWidget); + expect(find.text('5 min ago · /work · model-a'), findsOneWidget); expect(find.text('New'), findsOneWidget); - expect(find.text('/work'), findsOneWidget); - expect(find.text('2 hr ago'), findsOneWidget); + expect(find.text('2 hr ago · /work'), findsOneWidget); + // As on the web, the unread word shares the title's line. + expect( + (tester.getCenter(find.text('Starred chat')).dy - + tester.getCenter(find.text('New')).dy) + .abs(), + lessThan(4), + ); // The meta line is the theme's muted colour, not the title colour. - final meta = tester.widget(find.text('/work · model-a')); - final context = tester.element(find.text('/work · model-a')); + final meta = tester.widget(find.text('5 min ago · /work · model-a')); + final context = tester.element(find.text('5 min ago · /work · model-a')); expect(meta.style?.color, Theme.of(context).colorScheme.onSurfaceVariant); // Native Material separators sit between rows, not around the group. @@ -145,7 +150,7 @@ void main() { expect(tester.takeException(), isNull); const title = 'A conversation title long enough to need an ellipsis'; const meta = - '/a/very/long/directory/that/must/ellipsise · ' + '3 days ago · /a/very/long/directory/that/must/ellipsise · ' 'provider/an-extremely-long-recorded-model-id'; final titleParagraph = tester.renderObject( find.text(title), @@ -173,7 +178,7 @@ void main() { ); } - // Two lines: the title/recency line, then the muted meta line. + // Two lines: the title/word line, then the muted recency/meta line. expect( tester.getCenter(find.text(meta)).dy, greaterThan(tester.getCenter(find.text(title)).dy),