feat: an archive page, and the sidebar drops archived sessions

- 全部功能 gains an 归档 entry: the new page lists every archived session
  with a count, search over title / id / project, project chips (all plus
  each project with its count), and a row that opens the chat; each row
  restores the session or opens a menu to open, restore, copy the id or
  delete it
- the sidebar's 显示已归档 button and archived list are gone; the sidebar
  now lists only active sessions, while the archive page owns the archived
  ones (matching OpenChamber's archive page)
- version 0.6.0+600
- tests cover the archive list, project chips, search and restore
This commit is contained in:
blumia committed 2026-11-27 11:10:51 +08:00
1 parent c6b5a870c6
commit a7e4ed8dd7
8 files changed
+553 -103

No files matched your search

+40 -101
View File
@@ -32,7 +32,6 @@ class _SessionListPaneState extends State<SessionListPane> {
Timer? _timer;
late final TextEditingController _searchCtrl;
final Set<String> _collapsed = {};
bool _showArchived = false;
/// Parents whose subagents are expanded. Collapsed is the default; the
/// parent of the open child expands once so its child is visible.
@@ -251,17 +250,14 @@ class _SessionListPaneState extends State<SessionListPane> {
);
}
return RefreshIndicator(
onRefresh: () async {
await app.refreshSessions();
if (app.archivedLoaded) await app.refreshArchived();
},
onRefresh: app.refreshSessions,
child: ListView(
padding: const EdgeInsets.only(bottom: 16),
children: [
if (draft != null) _draftRow(draft),
if (pinned.isNotEmpty) ..._pinnedSection(pinned),
for (final group in _groups(unpinned)) ..._groupSection(group),
_footer(scheme),
_footer(),
],
),
);
@@ -514,19 +510,18 @@ class _SessionListPaneState extends State<SessionListPane> {
/// The session's worker sessions (subagents). The API lists them among the
/// sessions, so they are drawn nested right below their parent.
List<Session> _childrenOf(Session parent, {bool archived = false}) {
final source = archived ? _app.archivedSessions : _app.sessions;
List<Session> _childrenOf(Session parent) {
return [
for (final session in source)
for (final session in _app.sessions)
if (session.parentID == parent.id) session,
]..sort((a, b) => a.created.compareTo(b.created));
}
List<Widget> _rowsWithChildren(Session session, {bool archived = false}) {
final rows = <Widget>[_row(session, archived: archived)];
List<Widget> _rowsWithChildren(Session session) {
final rows = <Widget>[_row(session)];
if (!_expandedChildren.contains(session.id)) return rows;
final theme = Theme.of(context);
for (final child in _childrenOf(session, archived: archived)) {
for (final child in _childrenOf(session)) {
rows.add(Container(
margin: const EdgeInsets.only(left: 24),
decoration: BoxDecoration(
@@ -534,7 +529,7 @@ class _SessionListPaneState extends State<SessionListPane> {
left: BorderSide(color: theme.dividerColor, width: 1),
),
),
child: _row(child, archived: archived, child: true),
child: _row(child, child: true),
));
}
return rows;
@@ -550,33 +545,31 @@ class _SessionListPaneState extends State<SessionListPane> {
if (parent != null) _expandedChildren.add(parent);
}
Widget _row(Session session,
{bool archived = false, bool child = false}) {
Widget _row(Session session, {bool child = false}) {
final theme = Theme.of(context);
final scheme = theme.colorScheme;
final running = _isActive(session);
final selected =
!_app.draftOpen && _app.chat?.session.id == session.id;
final children = child ? const <Session>[] : _childrenOf(session, archived: archived);
final children = child ? const <Session>[] : _childrenOf(session);
final expanded = _expandedChildren.contains(session.id);
return Slidable(
key: ValueKey('${archived ? 'a' : 's'}-${session.id}'),
key: ValueKey('s-${session.id}'),
endActionPane: ActionPane(
motion: const DrawerMotion(),
extentRatio: 0.62,
children: [
if (!archived)
SlidableAction(
onPressed: (_) => _app.togglePin(session),
icon: Icons.push_pin_outlined,
label: session.isPinned ? tr('Unpin') : tr('Pin'),
backgroundColor: scheme.secondaryContainer,
foregroundColor: scheme.onSecondaryContainer,
),
SlidableAction(
onPressed: (_) => _archive(session, archived),
icon: archived ? Icons.unarchive_outlined : Icons.archive_outlined,
label: archived ? tr('Unarchive') : tr('Archive'),
onPressed: (_) => _app.togglePin(session),
icon: Icons.push_pin_outlined,
label: session.isPinned ? tr('Unpin') : tr('Pin'),
backgroundColor: scheme.secondaryContainer,
foregroundColor: scheme.onSecondaryContainer,
),
SlidableAction(
onPressed: (_) => _archive(session),
icon: Icons.archive_outlined,
label: tr('Archive'),
backgroundColor: scheme.surfaceContainerHighest,
foregroundColor: scheme.onSurface,
),
@@ -661,7 +654,7 @@ class _SessionListPaneState extends State<SessionListPane> {
strokeWidth: 1.8, color: scheme.primary),
),
),
_menu(session, archived: archived),
_menu(session),
],
),
onTap: () {
@@ -672,7 +665,7 @@ class _SessionListPaneState extends State<SessionListPane> {
);
}
Widget _menu(Session session, {required bool archived}) {
Widget _menu(Session session) {
// The same 48 slot as the project header's +, so the keys line up.
return SizedBox(
width: 48,
@@ -688,7 +681,7 @@ class _SessionListPaneState extends State<SessionListPane> {
_app.togglePin(session);
break;
case 'archive':
_archive(session, archived);
_archive(session);
break;
case 'delete':
_confirmDelete(session);
@@ -701,15 +694,11 @@ class _SessionListPaneState extends State<SessionListPane> {
}
},
itemBuilder: (_) => [
if (!archived) ...[
const PopupMenuItem(value: 'rename', child: AppText('Rename')),
PopupMenuItem(
value: 'pin',
child: AppText(session.isPinned ? 'Unpin' : 'Pin')),
],
const PopupMenuItem(value: 'rename', child: AppText('Rename')),
PopupMenuItem(
value: 'archive',
child: AppText(archived ? 'Unarchive' : 'Archive')),
value: 'pin',
child: AppText(session.isPinned ? 'Unpin' : 'Pin')),
const PopupMenuItem(value: 'archive', child: AppText('Archive')),
const PopupMenuItem(value: 'delete', child: AppText('Delete')),
const PopupMenuItem(value: 'copy', child: AppText('Copy session ID')),
],
@@ -717,70 +706,20 @@ class _SessionListPaneState extends State<SessionListPane> {
);
}
Widget _footer(ColorScheme scheme) {
Widget _footer() {
final app = _app;
final archivedCount =
app.archivedLoaded ? app.archivedSessions.length : null;
return Column(
children: [
if (app.hasMoreSessions)
TextButton(
onPressed: app.loadingMoreSessions ? null : app.loadMoreSessions,
child: app.loadingMoreSessions
? const SizedBox(
width: 16,
height: 16,
child: CircularProgressIndicator(strokeWidth: 2))
: const AppText('Load more'),
),
TextButton.icon(
icon: Icon(
_showArchived
? Icons.expand_less
: Icons.archive_outlined,
size: 16),
label: AppText(
_showArchived
? 'Hide archived'
: archivedCount == null
? 'Show archived'
: trArgs('Show archived ({0})', [archivedCount]),
style: const TextStyle(fontSize: 12.5),
),
onPressed: app.archivedLoading ? null : _toggleArchived,
),
if (app.archivedLoading)
const Padding(
padding: EdgeInsets.only(bottom: 8),
child: SizedBox(
width: 16,
height: 16,
child: CircularProgressIndicator(strokeWidth: 2)),
),
if (_showArchived)
for (final session in app.archivedSessions)
_row(session, archived: true, child: session.isChild),
if (_showArchived &&
app.archivedLoaded &&
app.archivedSessions.isEmpty)
Padding(
padding: const EdgeInsets.only(bottom: 8),
child: AppText('No archived sessions',
style: TextStyle(fontSize: 12, color: scheme.outline)),
),
],
if (!app.hasMoreSessions) return const SizedBox.shrink();
return TextButton(
onPressed: app.loadingMoreSessions ? null : app.loadMoreSessions,
child: app.loadingMoreSessions
? const SizedBox(
width: 16,
height: 16,
child: CircularProgressIndicator(strokeWidth: 2))
: const AppText('Load more'),
);
}
Future<void> _toggleArchived() async {
if (_showArchived) {
setState(() => _showArchived = false);
return;
}
if (!_app.archivedLoaded) await _app.refreshArchived();
if (mounted) setState(() => _showArchived = true);
}
String _subtitle(Session s) {
final parts = <String>[];
if (s.agent.isNotEmpty) parts.add(s.agent);
@@ -803,8 +742,8 @@ class _SessionListPaneState extends State<SessionListPane> {
widget.onOpened?.call();
}
Future<void> _archive(Session session, bool archived) async {
await _app.setArchived(session, !archived);
Future<void> _archive(Session session) async {
await _app.setArchived(session, true);
}
void _rename(Session s) {