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:
1 parent
c6b5a870c6
commit
a7e4ed8dd7
8 files changed
+536
-86
No files matched your search
@@ -5,6 +5,17 @@
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## 0.6.0 归档页面(分支 `flutter`)
|
||||||
|
|
||||||
|
| 项 | 结果 |
|
||||||
|
| --- | --- |
|
||||||
|
| 归档页面 | 全部功能新增【归档】:标题下显示已归档会话数量,支持按标题 / 会话 ID / 项目名搜索,顶部按项目分组的 chips 可筛选(全部 + 各项目及数量),点击行打开会话,行尾可取消归档(恢复)或打开菜单(打开 / 取消归档 / 复制会话 ID / 删除)。页面参考 OpenChamber 手机端归档页 |
|
||||||
|
| 侧栏 | 去掉【显示已归档】按钮和侧栏里的归档列表;侧栏只保留活动会话,归档统一从【全部功能 → 归档】进入 |
|
||||||
|
| 列表 | 归档会话按归档时间(缺失时按更新时间)倒序;项目分组按最近归档时间排序;取消归档后该行从归档页移回侧栏的活动列表 |
|
||||||
|
| 版本 | **0.6.0(code 600)** |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## 0.5.7 添加项目与上下文环回退(分支 `flutter`)
|
## 0.5.7 添加项目与上下文环回退(分支 `flutter`)
|
||||||
|
|
||||||
| 项 | 结果 |
|
| 项 | 结果 |
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ Android first. This branch (`flutter`) is a framework evaluation: the same
|
|||||||
feature set as the earlier Asuka/Go and MyGo attempts, reimplemented in
|
feature set as the earlier Asuka/Go and MyGo attempts, reimplemented in
|
||||||
Flutter to compare mobile UI maturity.
|
Flutter to compare mobile UI maturity.
|
||||||
|
|
||||||
Status: 0.5.7 — servers (passwordless / password login, HTTP/HTTPS and
|
Status: 0.6.0 — servers (passwordless / password login, HTTP/HTTPS and
|
||||||
SOCKS5/socks5h proxy, self-signed certificates and pinning, or a pairing link
|
SOCKS5/socks5h proxy, self-signed certificates and pinning, or a pairing link
|
||||||
over the OpenChamber private relay with end-to-end encryption; the pairing
|
over the OpenChamber private relay with end-to-end encryption; the pairing
|
||||||
link is pasted or scanned with the camera), session list with search and live
|
link is pasted or scanned with the camera), session list with search and live
|
||||||
|
|||||||
@@ -611,4 +611,14 @@ const Map<String, String> chineseStrings = {
|
|||||||
'calls: {0} · median: {1}': '调用 {0} · 中位耗时 {1}',
|
'calls: {0} · median: {1}': '调用 {0} · 中位耗时 {1}',
|
||||||
'calls: {0}': '调用 {0}',
|
'calls: {0}': '调用 {0}',
|
||||||
'OpenChamber mobile client': 'OpenChamber 移动客户端',
|
'OpenChamber mobile client': 'OpenChamber 移动客户端',
|
||||||
|
|
||||||
|
// archive
|
||||||
|
'All': '全部',
|
||||||
|
'Open': '打开',
|
||||||
|
'1 archived session': '1 个已归档会话',
|
||||||
|
'{0} archived sessions': '{0} 个已归档会话',
|
||||||
|
'Search archived sessions': '搜索已归档会话',
|
||||||
|
'No matching archived sessions': '没有匹配的已归档会话',
|
||||||
|
'Browse archived sessions and restore them': '浏览已归档的会话并恢复',
|
||||||
|
'Session restored': '会话已恢复',
|
||||||
};
|
};
|
||||||
@@ -0,0 +1,356 @@
|
|||||||
|
// 归档: every archived session in one place, grouped by project and searchable.
|
||||||
|
// Archived sessions are no longer mixed into the sidebar; this page is the
|
||||||
|
// only list of them, mirroring OpenChamber's archive page (title, count,
|
||||||
|
// search, project chips, restore and delete).
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
|
import '../api/models.dart';
|
||||||
|
import '../l10n.dart';
|
||||||
|
import '../state.dart';
|
||||||
|
|
||||||
|
class ArchivedSessionsScreen extends StatefulWidget {
|
||||||
|
final AppState app;
|
||||||
|
|
||||||
|
const ArchivedSessionsScreen({super.key, required this.app});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<ArchivedSessionsScreen> createState() => _ArchivedSessionsScreenState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ArchivedSessionsScreenState extends State<ArchivedSessionsScreen> {
|
||||||
|
final TextEditingController _searchCtrl = TextEditingController();
|
||||||
|
String _query = '';
|
||||||
|
|
||||||
|
/// The selected project bucket key; null is "all projects".
|
||||||
|
String? _bucket;
|
||||||
|
|
||||||
|
AppState get _app => widget.app;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
// The sidebar no longer fetches the archive; this page owns it.
|
||||||
|
if (!_app.archivedLoaded) _app.refreshArchived();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_searchCtrl.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<_ArchiveBucket> _buckets() {
|
||||||
|
final query = _query.trim().toLowerCase();
|
||||||
|
final byKey = <String, _ArchiveBucket>{};
|
||||||
|
for (final session in _app.archivedSessions) {
|
||||||
|
final label = _app.projectLabelFor(session.directory);
|
||||||
|
if (query.isNotEmpty &&
|
||||||
|
!session.title.toLowerCase().contains(query) &&
|
||||||
|
!session.id.toLowerCase().contains(query) &&
|
||||||
|
!label.toLowerCase().contains(query)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
final key = session.directory.isEmpty
|
||||||
|
? AppState.chatTarget
|
||||||
|
: slashPath(session.directory);
|
||||||
|
final bucket = byKey.putIfAbsent(
|
||||||
|
key,
|
||||||
|
() => _ArchiveBucket(
|
||||||
|
key: key, label: label.isEmpty ? tr('Chat') : label),
|
||||||
|
);
|
||||||
|
bucket.sessions.add(session);
|
||||||
|
}
|
||||||
|
final buckets = byKey.values.toList();
|
||||||
|
for (final bucket in buckets) {
|
||||||
|
bucket.sessions.sort((a, b) => _time(b).compareTo(_time(a)));
|
||||||
|
}
|
||||||
|
buckets.sort((a, b) =>
|
||||||
|
_time(b.sessions.first).compareTo(_time(a.sessions.first)));
|
||||||
|
return buckets;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int _time(Session session) =>
|
||||||
|
session.archived > 0 ? session.archived : session.updated;
|
||||||
|
|
||||||
|
List<Session> _shown(List<_ArchiveBucket> buckets, String? selected) {
|
||||||
|
if (selected == null) {
|
||||||
|
return [
|
||||||
|
for (final bucket in buckets) ...bucket.sessions,
|
||||||
|
]..sort((a, b) => _time(b).compareTo(_time(a)));
|
||||||
|
}
|
||||||
|
for (final bucket in buckets) {
|
||||||
|
if (bucket.key == selected) return bucket.sessions;
|
||||||
|
}
|
||||||
|
return const [];
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _refresh() => _app.refreshArchived();
|
||||||
|
|
||||||
|
Future<void> _unarchive(Session session) async {
|
||||||
|
await _app.setArchived(session, false);
|
||||||
|
if (!mounted) return;
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: AppText(tr('Session restored'))));
|
||||||
|
}
|
||||||
|
|
||||||
|
void _copy(Session session) {
|
||||||
|
Clipboard.setData(ClipboardData(text: session.id));
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: AppText(tr('Session ID copied'))));
|
||||||
|
}
|
||||||
|
|
||||||
|
void _confirmDelete(Session session) {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) => AlertDialog(
|
||||||
|
title: const AppText('Delete session?'),
|
||||||
|
content: AppText(trArgs(
|
||||||
|
'“{0}” and its subagent sessions will be deleted permanently.',
|
||||||
|
[session.title])),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.pop(context),
|
||||||
|
child: const AppText('Cancel')),
|
||||||
|
FilledButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
_app.client?.deleteSession(session.id);
|
||||||
|
_app.sessions.removeWhere((s) => s.id == session.id);
|
||||||
|
_app.archivedSessions.removeWhere((s) => s.id == session.id);
|
||||||
|
_app.touch();
|
||||||
|
},
|
||||||
|
child: const AppText('Delete'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _open(Session session) {
|
||||||
|
_app.openChat(session);
|
||||||
|
// The archive page sits above the all-features page and the shell; the
|
||||||
|
// chat opens on the shell.
|
||||||
|
Navigator.of(context).popUntil((route) => route.isFirst);
|
||||||
|
}
|
||||||
|
|
||||||
|
String _subtitle(Session session, {required bool showProject}) {
|
||||||
|
final parts = <String>[];
|
||||||
|
if (showProject) parts.add(_app.projectLabelFor(session.directory));
|
||||||
|
if (session.isChild) parts.add(tr('Subagent'));
|
||||||
|
final time = _time(session);
|
||||||
|
if (time > 0) {
|
||||||
|
final d = DateTime.fromMillisecondsSinceEpoch(time);
|
||||||
|
parts.add('${d.month.toString().padLeft(2, '0')}-'
|
||||||
|
'${d.day.toString().padLeft(2, '0')} '
|
||||||
|
'${d.hour.toString().padLeft(2, '0')}:'
|
||||||
|
'${d.minute.toString().padLeft(2, '0')}');
|
||||||
|
}
|
||||||
|
return parts.join(' · ');
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _row(Session session, {required bool showProject}) {
|
||||||
|
return ListTile(
|
||||||
|
// Compact like the sidebar's session rows.
|
||||||
|
dense: true,
|
||||||
|
minTileHeight: 56,
|
||||||
|
contentPadding: const EdgeInsets.only(left: 16, right: 4),
|
||||||
|
title: Text(
|
||||||
|
session.title.isEmpty ? tr('(Untitled session)') : session.title,
|
||||||
|
maxLines: 1,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
style: const TextStyle(fontSize: 14),
|
||||||
|
),
|
||||||
|
subtitle: Text(
|
||||||
|
_subtitle(session, showProject: showProject),
|
||||||
|
maxLines: 1,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
trailing: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.unarchive_outlined, size: 20),
|
||||||
|
tooltip: tr('Unarchive'),
|
||||||
|
onPressed: () => _unarchive(session),
|
||||||
|
),
|
||||||
|
PopupMenuButton<String>(
|
||||||
|
icon: const Icon(Icons.more_vert, size: 18),
|
||||||
|
onSelected: (value) {
|
||||||
|
switch (value) {
|
||||||
|
case 'open':
|
||||||
|
_open(session);
|
||||||
|
break;
|
||||||
|
case 'unarchive':
|
||||||
|
_unarchive(session);
|
||||||
|
break;
|
||||||
|
case 'copy':
|
||||||
|
_copy(session);
|
||||||
|
break;
|
||||||
|
case 'delete':
|
||||||
|
_confirmDelete(session);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
itemBuilder: (_) => [
|
||||||
|
const PopupMenuItem(value: 'open', child: AppText('Open')),
|
||||||
|
const PopupMenuItem(
|
||||||
|
value: 'unarchive', child: AppText('Unarchive')),
|
||||||
|
const PopupMenuItem(
|
||||||
|
value: 'copy', child: AppText('Copy session ID')),
|
||||||
|
const PopupMenuItem(value: 'delete', child: AppText('Delete')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
onTap: () => _open(session),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: const AppText('Archive'),
|
||||||
|
actions: [
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.refresh),
|
||||||
|
tooltip: tr('Refresh'),
|
||||||
|
onPressed: _app.archivedLoading ? null : _refresh,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
body: ListenableBuilder(
|
||||||
|
listenable: _app,
|
||||||
|
builder: (context, _) {
|
||||||
|
final buckets = _buckets();
|
||||||
|
// A restored session can remove the selected bucket; fall back to
|
||||||
|
// "all projects" instead of showing an empty list.
|
||||||
|
final selected = buckets.any((bucket) => bucket.key == _bucket)
|
||||||
|
? _bucket
|
||||||
|
: null;
|
||||||
|
final shown = _shown(buckets, selected);
|
||||||
|
final all = _app.archivedSessions.length;
|
||||||
|
final total =
|
||||||
|
buckets.fold<int>(0, (sum, bucket) => sum + bucket.sessions.length);
|
||||||
|
final count = shown.length == 1
|
||||||
|
? tr('1 archived session')
|
||||||
|
: trArgs('{0} archived sessions', [shown.length]);
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(16, 8, 16, 6),
|
||||||
|
child: TextField(
|
||||||
|
controller: _searchCtrl,
|
||||||
|
onChanged: (value) => setState(() => _query = value),
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: tr('Search archived sessions'),
|
||||||
|
prefixIcon: const Icon(Icons.search),
|
||||||
|
isDense: true,
|
||||||
|
border: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(10)),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (buckets.isNotEmpty)
|
||||||
|
SizedBox(
|
||||||
|
height: 42,
|
||||||
|
child: ListView(
|
||||||
|
scrollDirection: Axis.horizontal,
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||||
|
children: [
|
||||||
|
_chip(
|
||||||
|
label: tr('All'),
|
||||||
|
count: total,
|
||||||
|
selected: selected == null,
|
||||||
|
onTap: () => setState(() => _bucket = null),
|
||||||
|
),
|
||||||
|
for (final bucket in buckets)
|
||||||
|
_chip(
|
||||||
|
label: bucket.label,
|
||||||
|
count: bucket.sessions.length,
|
||||||
|
selected: selected == bucket.key,
|
||||||
|
onTap: () => setState(() => _bucket = bucket.key),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(16, 6, 16, 2),
|
||||||
|
child: Align(
|
||||||
|
alignment: Alignment.centerLeft,
|
||||||
|
child: AppText(
|
||||||
|
count,
|
||||||
|
style:
|
||||||
|
TextStyle(fontSize: 12, color: theme.hintColor),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: _app.archivedLoading && all == 0
|
||||||
|
? const Center(child: CircularProgressIndicator())
|
||||||
|
: RefreshIndicator(
|
||||||
|
onRefresh: _refresh,
|
||||||
|
child: shown.isEmpty
|
||||||
|
? ListView(
|
||||||
|
// Keep pull-to-refresh working on an empty
|
||||||
|
// archive.
|
||||||
|
physics:
|
||||||
|
const AlwaysScrollableScrollPhysics(),
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(32),
|
||||||
|
child: AppText(
|
||||||
|
all == 0
|
||||||
|
? 'No archived sessions'
|
||||||
|
: 'No matching archived sessions',
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
: ListView(
|
||||||
|
physics:
|
||||||
|
const AlwaysScrollableScrollPhysics(),
|
||||||
|
padding: const EdgeInsets.only(bottom: 24),
|
||||||
|
children: [
|
||||||
|
for (final session in shown)
|
||||||
|
_row(session,
|
||||||
|
showProject: selected == null),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _chip({
|
||||||
|
required String label,
|
||||||
|
required int count,
|
||||||
|
required bool selected,
|
||||||
|
required VoidCallback onTap,
|
||||||
|
}) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.only(right: 8),
|
||||||
|
child: ChoiceChip(
|
||||||
|
selected: selected,
|
||||||
|
onSelected: (_) => onTap(),
|
||||||
|
label: Text('$label ($count)',
|
||||||
|
maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ArchiveBucket {
|
||||||
|
final String key;
|
||||||
|
final String label;
|
||||||
|
final List<Session> sessions = [];
|
||||||
|
|
||||||
|
_ArchiveBucket({required this.key, required this.label});
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../state.dart';
|
import '../state.dart';
|
||||||
|
import 'archived_sessions_screen.dart';
|
||||||
import 'scheduled_tasks_screen.dart';
|
import 'scheduled_tasks_screen.dart';
|
||||||
import 'stats_screen.dart';
|
import 'stats_screen.dart';
|
||||||
import '../l10n.dart';
|
import '../l10n.dart';
|
||||||
@@ -46,6 +47,14 @@ class FeaturesScreen extends StatelessWidget {
|
|||||||
builder: (_) => StatsScreen(app: app),
|
builder: (_) => StatsScreen(app: app),
|
||||||
)),
|
)),
|
||||||
),
|
),
|
||||||
|
_FeatureTile(
|
||||||
|
icon: Icons.archive_outlined,
|
||||||
|
title: 'Archive',
|
||||||
|
caption: 'Browse archived sessions and restore them',
|
||||||
|
onTap: () => Navigator.of(context).push(MaterialPageRoute(
|
||||||
|
builder: (_) => ArchivedSessionsScreen(app: app),
|
||||||
|
)),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ class _SessionListPaneState extends State<SessionListPane> {
|
|||||||
Timer? _timer;
|
Timer? _timer;
|
||||||
late final TextEditingController _searchCtrl;
|
late final TextEditingController _searchCtrl;
|
||||||
final Set<String> _collapsed = {};
|
final Set<String> _collapsed = {};
|
||||||
bool _showArchived = false;
|
|
||||||
|
|
||||||
/// Parents whose subagents are expanded. Collapsed is the default; the
|
/// Parents whose subagents are expanded. Collapsed is the default; the
|
||||||
/// parent of the open child expands once so its child is visible.
|
/// parent of the open child expands once so its child is visible.
|
||||||
@@ -251,17 +250,14 @@ class _SessionListPaneState extends State<SessionListPane> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
return RefreshIndicator(
|
return RefreshIndicator(
|
||||||
onRefresh: () async {
|
onRefresh: app.refreshSessions,
|
||||||
await app.refreshSessions();
|
|
||||||
if (app.archivedLoaded) await app.refreshArchived();
|
|
||||||
},
|
|
||||||
child: ListView(
|
child: ListView(
|
||||||
padding: const EdgeInsets.only(bottom: 16),
|
padding: const EdgeInsets.only(bottom: 16),
|
||||||
children: [
|
children: [
|
||||||
if (draft != null) _draftRow(draft),
|
if (draft != null) _draftRow(draft),
|
||||||
if (pinned.isNotEmpty) ..._pinnedSection(pinned),
|
if (pinned.isNotEmpty) ..._pinnedSection(pinned),
|
||||||
for (final group in _groups(unpinned)) ..._groupSection(group),
|
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
|
/// The session's worker sessions (subagents). The API lists them among the
|
||||||
/// sessions, so they are drawn nested right below their parent.
|
/// sessions, so they are drawn nested right below their parent.
|
||||||
List<Session> _childrenOf(Session parent, {bool archived = false}) {
|
List<Session> _childrenOf(Session parent) {
|
||||||
final source = archived ? _app.archivedSessions : _app.sessions;
|
|
||||||
return [
|
return [
|
||||||
for (final session in source)
|
for (final session in _app.sessions)
|
||||||
if (session.parentID == parent.id) session,
|
if (session.parentID == parent.id) session,
|
||||||
]..sort((a, b) => a.created.compareTo(b.created));
|
]..sort((a, b) => a.created.compareTo(b.created));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Widget> _rowsWithChildren(Session session, {bool archived = false}) {
|
List<Widget> _rowsWithChildren(Session session) {
|
||||||
final rows = <Widget>[_row(session, archived: archived)];
|
final rows = <Widget>[_row(session)];
|
||||||
if (!_expandedChildren.contains(session.id)) return rows;
|
if (!_expandedChildren.contains(session.id)) return rows;
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
for (final child in _childrenOf(session, archived: archived)) {
|
for (final child in _childrenOf(session)) {
|
||||||
rows.add(Container(
|
rows.add(Container(
|
||||||
margin: const EdgeInsets.only(left: 24),
|
margin: const EdgeInsets.only(left: 24),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
@@ -534,7 +529,7 @@ class _SessionListPaneState extends State<SessionListPane> {
|
|||||||
left: BorderSide(color: theme.dividerColor, width: 1),
|
left: BorderSide(color: theme.dividerColor, width: 1),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: _row(child, archived: archived, child: true),
|
child: _row(child, child: true),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return rows;
|
return rows;
|
||||||
@@ -550,22 +545,20 @@ class _SessionListPaneState extends State<SessionListPane> {
|
|||||||
if (parent != null) _expandedChildren.add(parent);
|
if (parent != null) _expandedChildren.add(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _row(Session session,
|
Widget _row(Session session, {bool child = false}) {
|
||||||
{bool archived = false, bool child = false}) {
|
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
final scheme = theme.colorScheme;
|
final scheme = theme.colorScheme;
|
||||||
final running = _isActive(session);
|
final running = _isActive(session);
|
||||||
final selected =
|
final selected =
|
||||||
!_app.draftOpen && _app.chat?.session.id == session.id;
|
!_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);
|
final expanded = _expandedChildren.contains(session.id);
|
||||||
return Slidable(
|
return Slidable(
|
||||||
key: ValueKey('${archived ? 'a' : 's'}-${session.id}'),
|
key: ValueKey('s-${session.id}'),
|
||||||
endActionPane: ActionPane(
|
endActionPane: ActionPane(
|
||||||
motion: const DrawerMotion(),
|
motion: const DrawerMotion(),
|
||||||
extentRatio: 0.62,
|
extentRatio: 0.62,
|
||||||
children: [
|
children: [
|
||||||
if (!archived)
|
|
||||||
SlidableAction(
|
SlidableAction(
|
||||||
onPressed: (_) => _app.togglePin(session),
|
onPressed: (_) => _app.togglePin(session),
|
||||||
icon: Icons.push_pin_outlined,
|
icon: Icons.push_pin_outlined,
|
||||||
@@ -574,9 +567,9 @@ class _SessionListPaneState extends State<SessionListPane> {
|
|||||||
foregroundColor: scheme.onSecondaryContainer,
|
foregroundColor: scheme.onSecondaryContainer,
|
||||||
),
|
),
|
||||||
SlidableAction(
|
SlidableAction(
|
||||||
onPressed: (_) => _archive(session, archived),
|
onPressed: (_) => _archive(session),
|
||||||
icon: archived ? Icons.unarchive_outlined : Icons.archive_outlined,
|
icon: Icons.archive_outlined,
|
||||||
label: archived ? tr('Unarchive') : tr('Archive'),
|
label: tr('Archive'),
|
||||||
backgroundColor: scheme.surfaceContainerHighest,
|
backgroundColor: scheme.surfaceContainerHighest,
|
||||||
foregroundColor: scheme.onSurface,
|
foregroundColor: scheme.onSurface,
|
||||||
),
|
),
|
||||||
@@ -661,7 +654,7 @@ class _SessionListPaneState extends State<SessionListPane> {
|
|||||||
strokeWidth: 1.8, color: scheme.primary),
|
strokeWidth: 1.8, color: scheme.primary),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
_menu(session, archived: archived),
|
_menu(session),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
onTap: () {
|
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.
|
// The same 48 slot as the project header's +, so the keys line up.
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
width: 48,
|
width: 48,
|
||||||
@@ -688,7 +681,7 @@ class _SessionListPaneState extends State<SessionListPane> {
|
|||||||
_app.togglePin(session);
|
_app.togglePin(session);
|
||||||
break;
|
break;
|
||||||
case 'archive':
|
case 'archive':
|
||||||
_archive(session, archived);
|
_archive(session);
|
||||||
break;
|
break;
|
||||||
case 'delete':
|
case 'delete':
|
||||||
_confirmDelete(session);
|
_confirmDelete(session);
|
||||||
@@ -701,15 +694,11 @@ class _SessionListPaneState extends State<SessionListPane> {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
itemBuilder: (_) => [
|
itemBuilder: (_) => [
|
||||||
if (!archived) ...[
|
|
||||||
const PopupMenuItem(value: 'rename', child: AppText('Rename')),
|
const PopupMenuItem(value: 'rename', child: AppText('Rename')),
|
||||||
PopupMenuItem(
|
PopupMenuItem(
|
||||||
value: 'pin',
|
value: 'pin',
|
||||||
child: AppText(session.isPinned ? 'Unpin' : 'Pin')),
|
child: AppText(session.isPinned ? 'Unpin' : 'Pin')),
|
||||||
],
|
const PopupMenuItem(value: 'archive', child: AppText('Archive')),
|
||||||
PopupMenuItem(
|
|
||||||
value: 'archive',
|
|
||||||
child: AppText(archived ? 'Unarchive' : 'Archive')),
|
|
||||||
const PopupMenuItem(value: 'delete', child: AppText('Delete')),
|
const PopupMenuItem(value: 'delete', child: AppText('Delete')),
|
||||||
const PopupMenuItem(value: 'copy', child: AppText('Copy session ID')),
|
const PopupMenuItem(value: 'copy', child: AppText('Copy session ID')),
|
||||||
],
|
],
|
||||||
@@ -717,14 +706,10 @@ class _SessionListPaneState extends State<SessionListPane> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _footer(ColorScheme scheme) {
|
Widget _footer() {
|
||||||
final app = _app;
|
final app = _app;
|
||||||
final archivedCount =
|
if (!app.hasMoreSessions) return const SizedBox.shrink();
|
||||||
app.archivedLoaded ? app.archivedSessions.length : null;
|
return TextButton(
|
||||||
return Column(
|
|
||||||
children: [
|
|
||||||
if (app.hasMoreSessions)
|
|
||||||
TextButton(
|
|
||||||
onPressed: app.loadingMoreSessions ? null : app.loadMoreSessions,
|
onPressed: app.loadingMoreSessions ? null : app.loadMoreSessions,
|
||||||
child: app.loadingMoreSessions
|
child: app.loadingMoreSessions
|
||||||
? const SizedBox(
|
? const SizedBox(
|
||||||
@@ -732,55 +717,9 @@ class _SessionListPaneState extends State<SessionListPane> {
|
|||||||
height: 16,
|
height: 16,
|
||||||
child: CircularProgressIndicator(strokeWidth: 2))
|
child: CircularProgressIndicator(strokeWidth: 2))
|
||||||
: const AppText('Load more'),
|
: 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)),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
String _subtitle(Session s) {
|
||||||
final parts = <String>[];
|
final parts = <String>[];
|
||||||
if (s.agent.isNotEmpty) parts.add(s.agent);
|
if (s.agent.isNotEmpty) parts.add(s.agent);
|
||||||
@@ -803,8 +742,8 @@ class _SessionListPaneState extends State<SessionListPane> {
|
|||||||
widget.onOpened?.call();
|
widget.onOpened?.call();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _archive(Session session, bool archived) async {
|
Future<void> _archive(Session session) async {
|
||||||
await _app.setArchived(session, !archived);
|
await _app.setArchived(session, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _rename(Session s) {
|
void _rename(Session s) {
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@ name: openchamber
|
|||||||
description: "A lightweight OpenChamber client for phones."
|
description: "A lightweight OpenChamber client for phones."
|
||||||
publish_to: 'none'
|
publish_to: 'none'
|
||||||
|
|
||||||
version: 0.5.7+507
|
version: 0.6.0+600
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.14.0
|
sdk: ^3.14.0
|
||||||
|
|||||||
@@ -0,0 +1,125 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:openchamber/api/client.dart';
|
||||||
|
import 'package:openchamber/api/transport.dart';
|
||||||
|
import 'package:openchamber/l10n.dart';
|
||||||
|
import 'package:openchamber/screens/archived_sessions_screen.dart';
|
||||||
|
import 'package:openchamber/state.dart';
|
||||||
|
|
||||||
|
class _FakeTransport implements Transport {
|
||||||
|
final List<Map<String, dynamic>> archived;
|
||||||
|
|
||||||
|
_FakeTransport(this.archived);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<TransportResponse> send(TransportRequest r) async {
|
||||||
|
Object? body;
|
||||||
|
if (r.path == '/api/session') {
|
||||||
|
body = {'data': archived};
|
||||||
|
} else if (r.method == 'PATCH') {
|
||||||
|
archived.removeWhere((s) => s['id'] == r.path.split('/').last);
|
||||||
|
body = {'data': <String, dynamic>{}};
|
||||||
|
} else if (r.method == 'DELETE') {
|
||||||
|
archived.removeWhere((s) => s['id'] == r.path.split('/').last);
|
||||||
|
body = <String, dynamic>{};
|
||||||
|
} else {
|
||||||
|
body = <String, dynamic>{};
|
||||||
|
}
|
||||||
|
return TransportResponse(
|
||||||
|
200,
|
||||||
|
const {'content-type': 'application/json'},
|
||||||
|
Stream.value(Uint8List.fromList(utf8.encode(jsonEncode(body)))),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<TransportSocket> webSocket(String path,
|
||||||
|
{String? rawQuery, Map<String, String> headers = const {}}) async =>
|
||||||
|
throw UnimplementedError();
|
||||||
|
|
||||||
|
@override
|
||||||
|
void setBearerToken(String? token) {}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void close() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> _session(
|
||||||
|
String id, String title, String directory, int archived) =>
|
||||||
|
{
|
||||||
|
'id': id,
|
||||||
|
'title': title,
|
||||||
|
'time': {'created': archived - 1000, 'updated': archived - 500, 'archived': archived},
|
||||||
|
'location': {'directory': directory},
|
||||||
|
};
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
setUp(() => L10n.instance.apply(AppLanguage.en));
|
||||||
|
tearDown(() => L10n.instance.apply(AppLanguage.zh));
|
||||||
|
|
||||||
|
testWidgets('archived sessions are listed, filtered and restored',
|
||||||
|
(tester) async {
|
||||||
|
final app = AppState();
|
||||||
|
addTearDown(app.dispose);
|
||||||
|
final transport = _FakeTransport([
|
||||||
|
_session('a1', 'Old alpha', '/home/me/alpha', 1000),
|
||||||
|
_session('b1', 'Old beta', '/home/me/beta', 2000),
|
||||||
|
]);
|
||||||
|
app.client = Client(Uri.parse('http://test'), transport: transport);
|
||||||
|
|
||||||
|
await tester.pumpWidget(MaterialApp(home: ArchivedSessionsScreen(app: app)));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.text('Archive'), findsOneWidget);
|
||||||
|
expect(find.text('2 archived sessions'), findsOneWidget);
|
||||||
|
expect(find.text('Old alpha'), findsOneWidget);
|
||||||
|
expect(find.text('Old beta'), findsOneWidget);
|
||||||
|
expect(find.text('All (2)'), findsOneWidget);
|
||||||
|
expect(find.text('alpha (1)'), findsOneWidget);
|
||||||
|
|
||||||
|
// A project chip narrows the list; "All" brings both back.
|
||||||
|
await tester.tap(find.text('alpha (1)'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.text('Old alpha'), findsOneWidget);
|
||||||
|
expect(find.text('Old beta'), findsNothing);
|
||||||
|
expect(find.text('1 archived session'), findsOneWidget);
|
||||||
|
await tester.tap(find.text('All (2)'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.text('Old beta'), findsOneWidget);
|
||||||
|
|
||||||
|
// Search across projects.
|
||||||
|
await tester.enterText(find.byType(TextField), 'beta');
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.text('Old alpha'), findsNothing);
|
||||||
|
expect(find.text('Old beta'), findsOneWidget);
|
||||||
|
expect(find.text('1 archived session'), findsOneWidget);
|
||||||
|
|
||||||
|
// Restoring removes the row from the archive and from the list.
|
||||||
|
await tester.tap(find.byIcon(Icons.unarchive_outlined));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.text('Old beta'), findsNothing);
|
||||||
|
expect(find.text('Session restored'), findsOneWidget);
|
||||||
|
expect(app.archivedSessions.map((s) => s.id), ['a1']);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('a project chip shows only that project', (tester) async {
|
||||||
|
final app = AppState();
|
||||||
|
addTearDown(app.dispose);
|
||||||
|
final transport = _FakeTransport([
|
||||||
|
_session('a1', 'Old alpha', '/home/me/alpha', 1000),
|
||||||
|
_session('b1', 'Old beta', '/home/me/beta', 2000),
|
||||||
|
]);
|
||||||
|
app.client = Client(Uri.parse('http://test'), transport: transport);
|
||||||
|
|
||||||
|
await tester.pumpWidget(MaterialApp(home: ArchivedSessionsScreen(app: app)));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
await tester.tap(find.text('beta (1)'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.text('Old beta'), findsOneWidget);
|
||||||
|
expect(find.text('Old alpha'), findsNothing);
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in new issue
Block a user