feat(chat): contact-list chat rows with avatar, time and unread emphasis
Rows lead with a circular harness avatar, put the time beside the title, collapse metadata into one muted model · folder line and trail the actions menu. Unread chats are bold with an accent time and dot, running chats badge their avatar, and Star moves into the menu.
This commit is contained in:
@@ -6,7 +6,7 @@ import '../../domain/chat_sessions.dart';
|
||||
import 'chat_adaptive.dart';
|
||||
import 'session_row_style.dart';
|
||||
|
||||
enum SessionAction { rename, close, reopen, hide }
|
||||
enum SessionAction { star, rename, close, reopen, hide }
|
||||
|
||||
/// The close confirmation's body, matching the web client's explanation.
|
||||
String closeChatConfirmation(String title) =>
|
||||
@@ -15,39 +15,6 @@ String closeChatConfirmation(String title) =>
|
||||
'Nothing is deleted — the chat and its history are kept, '
|
||||
'and you can reopen it from the list.';
|
||||
|
||||
class SessionStarButton extends StatelessWidget {
|
||||
const SessionStarButton({
|
||||
super.key,
|
||||
required this.session,
|
||||
required this.onPressed,
|
||||
});
|
||||
|
||||
final JsonMap session;
|
||||
final VoidCallback onPressed;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final starred = session['starred'] == true;
|
||||
final label = starred ? 'Unstar chat' : 'Star chat';
|
||||
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
|
||||
return Semantics(
|
||||
label: label,
|
||||
button: true,
|
||||
child: CupertinoButton(
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: onPressed,
|
||||
child: Icon(starred ? CupertinoIcons.star_fill : CupertinoIcons.star),
|
||||
),
|
||||
);
|
||||
}
|
||||
return IconButton(
|
||||
tooltip: label,
|
||||
onPressed: onPressed,
|
||||
icon: Icon(starred ? Icons.star : Icons.star_border),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class SessionActionsButton extends StatelessWidget {
|
||||
const SessionActionsButton({
|
||||
super.key,
|
||||
@@ -64,7 +31,9 @@ class SessionActionsButton extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final label = sessionActionsLabel(session, duplicateTitles);
|
||||
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
|
||||
// Its own node, so the row's merged label never swallows the button.
|
||||
return Semantics(
|
||||
container: true,
|
||||
label: label,
|
||||
button: true,
|
||||
child: CupertinoButton(
|
||||
@@ -111,6 +80,10 @@ List<PopupMenuEntry<SessionAction>> _menuItems(JsonMap session) => [
|
||||
List<({SessionAction action, String label})> _items(JsonMap session) {
|
||||
final isClosed = session['closed_at'] != null;
|
||||
return [
|
||||
(
|
||||
action: SessionAction.star,
|
||||
label: session['starred'] == true ? 'Unstar' : 'Star',
|
||||
),
|
||||
(action: SessionAction.rename, label: 'Rename…'),
|
||||
isClosed
|
||||
? (action: SessionAction.reopen, label: 'Reopen')
|
||||
|
||||
@@ -7,7 +7,6 @@ import '../../domain/chat_sessions.dart';
|
||||
import 'chat_adaptive.dart';
|
||||
import 'chat_sessions_body.dart';
|
||||
import 'session_actions.dart';
|
||||
import 'session_harness_icon.dart';
|
||||
import 'session_row_content.dart';
|
||||
import 'session_row_style.dart';
|
||||
|
||||
@@ -147,67 +146,65 @@ class _CupertinoSessionRow extends StatelessWidget {
|
||||
@override
|
||||
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 state word and the muted meta
|
||||
// go. Each metadata line 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 meta = chatSessionMetaLines(session);
|
||||
final recency = relativeChatSessionTime(session['updated_at']);
|
||||
final status = chatSessionRowStatus(session, unseen: unseen);
|
||||
final statusStyle = theme.textTheme.tabLabelTextStyle.copyWith(
|
||||
color: status == 'Closed' ? secondary : theme.primaryColor,
|
||||
);
|
||||
return Semantics(
|
||||
selected: selected,
|
||||
child: CupertinoListTile(
|
||||
key: Key('chat-row-$id'),
|
||||
backgroundColor: selected
|
||||
? CupertinoColors.tertiarySystemFill.resolveFrom(context)
|
||||
: null,
|
||||
// As on the web: the title with the unread/closed word trailing, then
|
||||
// the muted `recency · directory · model` line.
|
||||
title: ChatSessionRowContent(
|
||||
leading: SessionHarnessIcon(
|
||||
session: session,
|
||||
color: selected ? theme.primaryColor : null,
|
||||
),
|
||||
actions: [
|
||||
SessionStarButton(
|
||||
key: Key('chat-star-$id'),
|
||||
session: session,
|
||||
onPressed: () => onStar(session),
|
||||
final closed = chatSessionRowStatus(session, unseen: false) == 'Closed';
|
||||
// A contact-list row, the same pieces as the Material row. The grouped
|
||||
// list owns the separators and the tile its native text styles; the
|
||||
// leading slot is widened to hold the avatar.
|
||||
// A narrow pane (a wide window's list beside its detail, or its opening
|
||||
// animation) drops the avatar and tightens the tile's insets, so the
|
||||
// menu stays reachable and the title keeps some width.
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final avatar = constraints.maxWidth >= _avatarMinWidth;
|
||||
return Semantics(
|
||||
selected: selected,
|
||||
child: CupertinoListTile(
|
||||
key: Key('chat-row-$id'),
|
||||
backgroundColor: selected
|
||||
? CupertinoColors.tertiarySystemFill.resolveFrom(context)
|
||||
: null,
|
||||
padding: avatar
|
||||
? null
|
||||
: const EdgeInsetsDirectional.only(start: 8, end: 4),
|
||||
leadingSize: avatar ? 40 : 28,
|
||||
leading: avatar
|
||||
? ChatSessionAvatar(
|
||||
session: session,
|
||||
running: session['running'] == true && !unseen,
|
||||
selected: selected,
|
||||
)
|
||||
: null,
|
||||
title: ChatSessionTitleLine(
|
||||
title: chatSessionTitle(session),
|
||||
recency: relativeChatSessionTime(session['updated_at']),
|
||||
unread: unseen && !closed,
|
||||
starred: session['starred'] == true,
|
||||
),
|
||||
SessionActionsButton(
|
||||
subtitle: ChatSessionSubtitleLine(
|
||||
text: chatSessionSubtitle(session),
|
||||
unread: unseen && !closed,
|
||||
closed: closed,
|
||||
),
|
||||
trailing: SessionActionsButton(
|
||||
key: Key('chat-actions-$id'),
|
||||
session: session,
|
||||
duplicateTitles: duplicateTitles,
|
||||
onSelected: _select,
|
||||
),
|
||||
],
|
||||
title: chatSessionTitle(session),
|
||||
status: status,
|
||||
recency: recency.isEmpty ? null : recency,
|
||||
meta: meta,
|
||||
titleStyle: theme.textTheme.textStyle.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
onTap: () => onOpen(session),
|
||||
),
|
||||
metaStyle: theme.textTheme.tabLabelTextStyle.copyWith(
|
||||
color: secondary,
|
||||
),
|
||||
statusStyle: statusStyle,
|
||||
loading: session['running'] == true && !unseen,
|
||||
),
|
||||
subtitle: null,
|
||||
onTap: () => onOpen(session),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// The tile width below which the row is compact: no avatar, tight insets.
|
||||
static const double _avatarMinWidth = 240;
|
||||
|
||||
void _select(SessionAction action) {
|
||||
switch (action) {
|
||||
case SessionAction.star:
|
||||
onStar(session);
|
||||
case SessionAction.rename:
|
||||
onRename(session);
|
||||
case SessionAction.close:
|
||||
|
||||
@@ -7,7 +7,6 @@ import '../../domain/chat_sessions.dart';
|
||||
import 'chat_adaptive.dart';
|
||||
import 'chat_sessions_body.dart';
|
||||
import 'session_actions.dart';
|
||||
import 'session_harness_icon.dart';
|
||||
import 'session_row_content.dart';
|
||||
import 'session_row_style.dart';
|
||||
|
||||
@@ -152,63 +151,63 @@ class _MaterialSessionRow extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final id = '${session['id'] ?? ''}';
|
||||
// The same content as the Cupertino row: title and state, then each
|
||||
// recorded metadata field on its own muted 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 meta = chatSessionMetaLines(session);
|
||||
final recency = relativeChatSessionTime(session['updated_at']);
|
||||
final status = chatSessionRowStatus(session, unseen: unseen);
|
||||
final statusStyle =
|
||||
theme.textTheme.labelSmall?.copyWith(
|
||||
color: status == 'Closed' ? secondary : theme.colorScheme.primary,
|
||||
) ??
|
||||
TextStyle(color: theme.colorScheme.primary);
|
||||
return ListTile(
|
||||
key: Key('chat-row-$id'),
|
||||
selected: selected,
|
||||
selectedTileColor: theme.colorScheme.secondaryContainer,
|
||||
selectedColor: theme.colorScheme.onSecondaryContainer,
|
||||
// As on the web: the title with the unread/closed word trailing, then
|
||||
// the muted `recency · directory · model` line.
|
||||
title: ChatSessionRowContent(
|
||||
leading: SessionHarnessIcon(session: session),
|
||||
actions: [
|
||||
SessionStarButton(
|
||||
key: Key('chat-star-$id'),
|
||||
session: session,
|
||||
onPressed: () => onStar(session),
|
||||
final closed = chatSessionRowStatus(session, unseen: false) == 'Closed';
|
||||
// A contact-list row, the same pieces as the Cupertino row: the harness
|
||||
// avatar, the title with its time, one muted line, and the actions menu.
|
||||
// ListTile asserts when its trailing control leaves the title no width.
|
||||
// A narrow pane (a wide window's list beside its detail, or its opening
|
||||
// animation) drops the avatar and tightens the tile's insets, so the
|
||||
// menu stays reachable and the title keeps some width.
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final narrow = constraints.maxWidth < _avatarMinWidth;
|
||||
return ListTile(
|
||||
key: Key('chat-row-$id'),
|
||||
selected: selected,
|
||||
selectedTileColor: theme.colorScheme.secondaryContainer,
|
||||
selectedColor: theme.colorScheme.onSecondaryContainer,
|
||||
contentPadding: narrow
|
||||
? const EdgeInsetsDirectional.only(start: 8)
|
||||
: null,
|
||||
horizontalTitleGap: narrow ? 4 : null,
|
||||
leading: narrow
|
||||
? null
|
||||
: ChatSessionAvatar(
|
||||
session: session,
|
||||
running: session['running'] == true && !unseen,
|
||||
selected: selected,
|
||||
),
|
||||
title: ChatSessionTitleLine(
|
||||
title: chatSessionTitle(session),
|
||||
recency: relativeChatSessionTime(session['updated_at']),
|
||||
unread: unseen && !closed,
|
||||
starred: session['starred'] == true,
|
||||
),
|
||||
SessionActionsButton(
|
||||
subtitle: ChatSessionSubtitleLine(
|
||||
text: chatSessionSubtitle(session),
|
||||
unread: unseen && !closed,
|
||||
closed: closed,
|
||||
),
|
||||
trailing: SessionActionsButton(
|
||||
key: Key('chat-actions-$id'),
|
||||
session: session,
|
||||
duplicateTitles: duplicateTitles,
|
||||
onSelected: _select,
|
||||
),
|
||||
],
|
||||
title: chatSessionTitle(session),
|
||||
status: status,
|
||||
recency: recency.isEmpty ? null : recency,
|
||||
meta: meta,
|
||||
titleStyle:
|
||||
theme.textTheme.titleSmall ??
|
||||
const TextStyle(fontWeight: FontWeight.w600),
|
||||
metaStyle:
|
||||
theme.textTheme.bodySmall?.copyWith(color: secondary) ??
|
||||
TextStyle(color: secondary),
|
||||
statusStyle: statusStyle,
|
||||
loading: session['running'] == true && !unseen,
|
||||
),
|
||||
subtitle: null,
|
||||
onTap: () => onOpen(session),
|
||||
onTap: () => onOpen(session),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// The tile width below which the row is compact: no avatar, tight insets.
|
||||
static const double _avatarMinWidth = 240;
|
||||
|
||||
void _select(SessionAction action) {
|
||||
switch (action) {
|
||||
case SessionAction.star:
|
||||
onStar(session);
|
||||
case SessionAction.rename:
|
||||
onRename(session);
|
||||
case SessionAction.close:
|
||||
|
||||
@@ -1,182 +1,241 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../core/api_gateway.dart';
|
||||
import 'chat_adaptive.dart';
|
||||
import 'session_harness_icon.dart';
|
||||
|
||||
/// Hierarchical row copy shared by the Material and Cupertino list variants.
|
||||
/// Metadata stays on the left; recency and native actions share its vertical
|
||||
/// space on the right instead of adding full-width rows below it.
|
||||
class ChatSessionRowContent extends StatelessWidget {
|
||||
const ChatSessionRowContent({
|
||||
/// Row pieces shared by the Material and Cupertino chat lists. Each list puts
|
||||
/// them in its native tile's slots: the avatar leads, the title line and the
|
||||
/// subtitle line fill the text column, and the actions menu trails.
|
||||
|
||||
/// The chat's harness mark in a filled circle, like a contact avatar. A
|
||||
/// running chat carries a small activity badge on the avatar's corner instead
|
||||
/// of a line of its own; a selected chat's avatar takes the accent fill.
|
||||
class ChatSessionAvatar extends StatelessWidget {
|
||||
const ChatSessionAvatar({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.status,
|
||||
required this.recency,
|
||||
required this.meta,
|
||||
required this.titleStyle,
|
||||
required this.metaStyle,
|
||||
required this.statusStyle,
|
||||
this.loading = false,
|
||||
this.leading,
|
||||
this.actions = const [],
|
||||
required this.session,
|
||||
this.running = false,
|
||||
this.selected = false,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final String? status;
|
||||
final String? recency;
|
||||
final List<String> meta;
|
||||
final TextStyle titleStyle;
|
||||
final TextStyle metaStyle;
|
||||
final TextStyle statusStyle;
|
||||
final bool loading;
|
||||
final Widget? leading;
|
||||
final List<Widget> actions;
|
||||
final JsonMap session;
|
||||
final bool running;
|
||||
final bool selected;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
final Color fill;
|
||||
final Color mark;
|
||||
if (cupertino) {
|
||||
final primary = CupertinoTheme.of(context).primaryColor;
|
||||
fill = selected
|
||||
? primary.withValues(alpha: 0.2)
|
||||
: CupertinoColors.systemGrey5.resolveFrom(context);
|
||||
mark = selected ? primary : CupertinoColors.label.resolveFrom(context);
|
||||
} else {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
fill = selected
|
||||
? scheme.primaryContainer
|
||||
: scheme.surfaceContainerHighest;
|
||||
mark = selected ? scheme.onPrimaryContainer : scheme.onSurfaceVariant;
|
||||
}
|
||||
final avatar = CircleAvatar(
|
||||
backgroundColor: fill,
|
||||
child: SessionHarnessIcon(session: session, color: mark),
|
||||
);
|
||||
if (!running) return avatar;
|
||||
return Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (leading != null) ...[leading!, const SizedBox(width: 8)],
|
||||
Expanded(
|
||||
child: Text(
|
||||
title,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: titleStyle,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final hasTrailing =
|
||||
actions.isNotEmpty || (recency?.isNotEmpty ?? false);
|
||||
final nativeTarget =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino
|
||||
? kMinInteractiveDimensionCupertino
|
||||
: kMinInteractiveDimension;
|
||||
final trailingWidth = math.min(
|
||||
constraints.maxWidth,
|
||||
math.max(
|
||||
nativeTarget,
|
||||
math.min(
|
||||
constraints.maxWidth * 0.45,
|
||||
nativeTarget * math.max(1, actions.length),
|
||||
),
|
||||
),
|
||||
);
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (status != null)
|
||||
_StatusLabel(status: status!, style: statusStyle),
|
||||
if (status == null && loading)
|
||||
Semantics(
|
||||
label: 'Chat is working',
|
||||
child: const _LoadingStatus(),
|
||||
),
|
||||
for (final line in meta)
|
||||
Text(
|
||||
line,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: metaStyle,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (hasTrailing)
|
||||
SizedBox(
|
||||
width: trailingWidth,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (recency?.isNotEmpty ?? false)
|
||||
Text(
|
||||
recency!,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
textAlign: TextAlign.end,
|
||||
style: metaStyle,
|
||||
),
|
||||
if (actions.isNotEmpty)
|
||||
Wrap(alignment: WrapAlignment.end, children: actions),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
avatar,
|
||||
PositionedDirectional(
|
||||
end: -2,
|
||||
bottom: -2,
|
||||
child: Semantics(
|
||||
key: const Key('chat-row-working'),
|
||||
label: 'Chat is working',
|
||||
child: _WorkingBadge(cupertino: cupertino),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _LoadingStatus extends StatelessWidget {
|
||||
const _LoadingStatus();
|
||||
class _WorkingBadge extends StatelessWidget {
|
||||
const _WorkingBadge({required this.cupertino});
|
||||
|
||||
final bool cupertino;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
|
||||
return const Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: CupertinoActivityIndicator(radius: 7),
|
||||
);
|
||||
}
|
||||
return const Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
final background = cupertino
|
||||
? CupertinoColors.systemBackground.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.surface;
|
||||
return DecoratedBox(
|
||||
decoration: BoxDecoration(color: background, shape: BoxShape.circle),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(2),
|
||||
child: cupertino
|
||||
? const CupertinoActivityIndicator(radius: 6)
|
||||
: const SizedBox.square(
|
||||
dimension: 12,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _StatusLabel extends StatelessWidget {
|
||||
const _StatusLabel({required this.status, required this.style});
|
||||
/// The title with its recency at the trailing edge. An unread chat's title is
|
||||
/// bold and its time takes the accent, so it stands out at a glance; a starred
|
||||
/// chat shows a small star after its title.
|
||||
class ChatSessionTitleLine extends StatelessWidget {
|
||||
const ChatSessionTitleLine({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.recency,
|
||||
this.unread = false,
|
||||
this.starred = false,
|
||||
});
|
||||
|
||||
final String status;
|
||||
final TextStyle style;
|
||||
final String title;
|
||||
final String recency;
|
||||
final bool unread;
|
||||
final bool starred;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (status != 'New') {
|
||||
return Text(
|
||||
status,
|
||||
maxLines: 1,
|
||||
style: style.copyWith(fontWeight: FontWeight.w600),
|
||||
);
|
||||
}
|
||||
final color = style.color ?? Theme.of(context).colorScheme.primary;
|
||||
return DecoratedBox(
|
||||
key: const Key('chat-row-unread'),
|
||||
decoration: ShapeDecoration(color: color, shape: const StadiumBorder()),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 7, vertical: 1),
|
||||
child: Text(
|
||||
status,
|
||||
maxLines: 1,
|
||||
style: style.copyWith(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w700,
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
final accent = cupertino
|
||||
? CupertinoTheme.of(context).primaryColor
|
||||
: Theme.of(context).colorScheme.primary;
|
||||
final secondary = cupertino
|
||||
? CupertinoColors.secondaryLabel.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
final timeStyle =
|
||||
(cupertino
|
||||
? CupertinoTheme.of(context).textTheme.tabLabelTextStyle
|
||||
: Theme.of(context).textTheme.bodySmall)
|
||||
?.copyWith(
|
||||
color: unread ? accent : secondary,
|
||||
fontWeight: unread ? FontWeight.w600 : null,
|
||||
);
|
||||
final star = Icon(
|
||||
cupertino ? CupertinoIcons.star_fill : Icons.star,
|
||||
key: const Key('chat-row-starred'),
|
||||
// As tall as the title's text, so it follows text scaling.
|
||||
size: DefaultTextStyle.of(context).style.fontSize,
|
||||
color: accent,
|
||||
semanticLabel: 'Starred',
|
||||
);
|
||||
// The star rides in the title's own text, so a narrow row ellipsises
|
||||
// them together; the time keeps at most about half the line.
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) => Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text.rich(
|
||||
TextSpan(
|
||||
text: title,
|
||||
children: [
|
||||
if (starred)
|
||||
WidgetSpan(
|
||||
alignment: PlaceholderAlignment.middle,
|
||||
child: Padding(
|
||||
padding: const EdgeInsetsDirectional.only(start: 4),
|
||||
child: star,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontWeight: unread ? FontWeight.w700 : FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (recency.isNotEmpty)
|
||||
ConstrainedBox(
|
||||
constraints: BoxConstraints(maxWidth: constraints.maxWidth / 2),
|
||||
child: Padding(
|
||||
padding: const EdgeInsetsDirectional.only(start: 8),
|
||||
child: Text(
|
||||
recency,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: timeStyle,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// One muted line: `Closed` first when the chat is closed, then the model and
|
||||
/// folder, with an accent dot at the end while the chat has unread content.
|
||||
class ChatSessionSubtitleLine extends StatelessWidget {
|
||||
const ChatSessionSubtitleLine({
|
||||
super.key,
|
||||
required this.text,
|
||||
this.unread = false,
|
||||
this.closed = false,
|
||||
});
|
||||
|
||||
final String text;
|
||||
final bool unread;
|
||||
final bool closed;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
final accent = cupertino
|
||||
? CupertinoTheme.of(context).primaryColor
|
||||
: Theme.of(context).colorScheme.primary;
|
||||
return Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text.rich(
|
||||
TextSpan(
|
||||
children: [
|
||||
if (closed)
|
||||
const TextSpan(
|
||||
text: 'Closed',
|
||||
style: TextStyle(fontWeight: FontWeight.w600),
|
||||
),
|
||||
if (closed && text.isNotEmpty) const TextSpan(text: ' · '),
|
||||
TextSpan(text: text),
|
||||
],
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (unread)
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.only(start: 8),
|
||||
child: Semantics(
|
||||
key: const Key('chat-row-unread'),
|
||||
label: 'New',
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: accent,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const SizedBox.square(dimension: 10),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,27 +40,18 @@ String relativeChatSessionTime(Object? updatedAt, {DateTime? now}) {
|
||||
return '${then.day} ${_shortMonths[then.month - 1]}';
|
||||
}
|
||||
|
||||
/// Recorded session fields rendered independently beneath the title.
|
||||
List<String> chatSessionMetaLines(JsonMap session) {
|
||||
final backend = '${session['backend'] ?? ''}'.trim();
|
||||
return [
|
||||
backend.isEmpty ? 'opencode' : backend,
|
||||
'${session['model'] ?? ''}'.trim(),
|
||||
homeRelativePath('${session['directory'] ?? ''}'.trim()),
|
||||
].where((part) => part.isNotEmpty).toList();
|
||||
}
|
||||
/// 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, '~');
|
||||
|
||||
/// All secondary row information, each as a distinct line.
|
||||
List<String> chatSessionRowMetaLines(JsonMap session, {DateTime? now}) => [
|
||||
relativeChatSessionTime(session['updated_at'], now: now),
|
||||
...chatSessionMetaLines(session),
|
||||
].where((part) => part.isNotEmpty).toList();
|
||||
|
||||
/// 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}) {
|
||||
|
||||
Reference in New Issue
Block a user