feat: archive filter uses the shared project sheet, with search

- the archive page's horizontal project chips become the same project
  scope row as new-session / scheduled tasks / stats: tapping it opens the
  shared project bottomsheet (all projects, chat, every project with its
  icon, path and checkmark) and filters the archive
- the shared project sheet gains a search field over project name and path,
  so a long project list can be narrowed; it shows "no matching projects"
  when nothing matches
- version 0.6.1+601
- archive test covers filtering through the sheet
This commit is contained in:
blumia committed 2026-11-27 12:14:44 +08:00
1 parent a7e4ed8dd7
commit 83e09e8e25
7 files changed
+156 -109

No files matched your search

+10
View File
@@ -5,6 +5,16 @@
--- ---
## 0.6.1 归档筛选改用共享项目选择器(分支 `flutter`)
| 项 | 结果 |
| --- | --- |
| 项目筛选 | 归档页顶部原来的横向项目 chips 改为与新建会话 / 计划任务 / 统计一致的项目选择行:点击打开共享项目 bottomsheet(含「所有项目」「聊天」与全部项目、图标、路径、当前选中标记),选完立即筛选归档列表;项目很多时不会再横向挤在一起 |
| 选择器搜索 | 共享项目 bottomsheet 新增搜索框,按项目名或路径过滤,项目很多时也能快速定位;无匹配时显示「没有匹配的项目」 |
| 版本 | **0.6.1(code 601)** |
---
## 0.6.0 归档页面(分支 `flutter`) ## 0.6.0 归档页面(分支 `flutter`)
| 项 | 结果 | | 项 | 结果 |
+1 -1
View File
@@ -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.6.0 — servers (passwordless / password login, HTTP/HTTPS and Status: 0.6.1 — 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
+2
View File
@@ -618,7 +618,9 @@ const Map<String, String> chineseStrings = {
'1 archived session': '1 个已归档会话', '1 archived session': '1 个已归档会话',
'{0} archived sessions': '{0} 个已归档会话', '{0} archived sessions': '{0} 个已归档会话',
'Search archived sessions': '搜索已归档会话', 'Search archived sessions': '搜索已归档会话',
'Search projects': '搜索项目',
'No matching archived sessions': '没有匹配的已归档会话', 'No matching archived sessions': '没有匹配的已归档会话',
'No matching projects': '没有匹配的项目',
'Browse archived sessions and restore them': '浏览已归档的会话并恢复', 'Browse archived sessions and restore them': '浏览已归档的会话并恢复',
'Session restored': '会话已恢复', 'Session restored': '会话已恢复',
}; };
+80 -95
View File
@@ -8,6 +8,8 @@ import 'package:flutter/services.dart';
import '../api/models.dart'; import '../api/models.dart';
import '../l10n.dart'; import '../l10n.dart';
import '../state.dart'; import '../state.dart';
import '../widgets/project_icon.dart';
import '../widgets/project_picker.dart';
class ArchivedSessionsScreen extends StatefulWidget { class ArchivedSessionsScreen extends StatefulWidget {
final AppState app; final AppState app;
@@ -40,52 +42,89 @@ class _ArchivedSessionsScreenState extends State<ArchivedSessionsScreen> {
super.dispose(); super.dispose();
} }
List<_ArchiveBucket> _buckets() { bool _matches(String directory) {
final selected = _bucket;
if (selected == null) return true;
if (selected == AppState.chatTarget) {
return directory.isEmpty ||
directory == AppState.chatTarget ||
_app.isChatDirectory(directory);
}
return samePath(directory, selected);
}
/// Archived sessions matching the search and the selected project, newest
/// archived first (falling back to updated for old records).
List<Session> _filtered() {
final query = _query.trim().toLowerCase(); final query = _query.trim().toLowerCase();
final byKey = <String, _ArchiveBucket>{}; return [
for (final session in _app.archivedSessions) { for (final session in _app.archivedSessions)
final label = _app.projectLabelFor(session.directory); if (_matches(session.directory) &&
if (query.isNotEmpty && (query.isEmpty ||
!session.title.toLowerCase().contains(query) && session.title.toLowerCase().contains(query) ||
!session.id.toLowerCase().contains(query) && session.id.toLowerCase().contains(query) ||
!label.toLowerCase().contains(query)) { _app
continue; .projectLabelFor(session.directory)
} .toLowerCase()
final key = session.directory.isEmpty .contains(query)))
? AppState.chatTarget session,
: slashPath(session.directory); ]..sort((a, b) => _time(b).compareTo(_time(a)));
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) => static int _time(Session session) =>
session.archived > 0 ? session.archived : session.updated; session.archived > 0 ? session.archived : session.updated;
List<Session> _shown(List<_ArchiveBucket> buckets, String? selected) { Future<void> _refresh() => _app.refreshArchived();
if (selected == null) {
return [ Future<void> _pickProject() async {
for (final bucket in buckets) ...bucket.sessions, final choice = await showProjectPicker(
]..sort((a, b) => _time(b).compareTo(_time(a))); context,
} app: _app,
for (final bucket in buckets) { selected: _bucket ?? allProjectsTarget,
if (bucket.key == selected) return bucket.sessions; includeAll: true,
} );
return const []; if (choice == null || !mounted) return;
setState(() => _bucket = choice.isAll ? null : choice.canonical);
} }
Future<void> _refresh() => _app.refreshArchived(); Widget _scopeRow(ThemeData theme) {
final selected = _bucket;
final isChat = selected != null && _app.isChatDirectory(selected);
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 10),
child: InkWell(
borderRadius: BorderRadius.circular(10),
onTap: _pickProject,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 8),
child: Row(
children: [
if (selected == null)
Icon(Icons.folder_copy_outlined,
size: 18, color: theme.hintColor)
else if (isChat)
ProjectIcon(app: _app, chat: true, size: 18)
else
ProjectIcon(
app: _app, project: _app.projectFor(selected), size: 18),
const SizedBox(width: 8),
Expanded(
child: Text(
selected == null
? tr('All projects')
: _app.projectLabelFor(selected),
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(fontSize: 14),
),
),
Icon(Icons.expand_more, size: 18, color: theme.hintColor),
],
),
),
),
);
}
Future<void> _unarchive(Session session) async { Future<void> _unarchive(Session session) async {
await _app.setArchived(session, false); await _app.setArchived(session, false);
@@ -224,16 +263,8 @@ class _ArchivedSessionsScreenState extends State<ArchivedSessionsScreen> {
body: ListenableBuilder( body: ListenableBuilder(
listenable: _app, listenable: _app,
builder: (context, _) { builder: (context, _) {
final buckets = _buckets(); final shown = _filtered();
// 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 all = _app.archivedSessions.length;
final total =
buckets.fold<int>(0, (sum, bucket) => sum + bucket.sessions.length);
final count = shown.length == 1 final count = shown.length == 1
? tr('1 archived session') ? tr('1 archived session')
: trArgs('{0} archived sessions', [shown.length]); : trArgs('{0} archived sessions', [shown.length]);
@@ -253,29 +284,7 @@ class _ArchivedSessionsScreenState extends State<ArchivedSessionsScreen> {
), ),
), ),
), ),
if (buckets.isNotEmpty) _scopeRow(theme),
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(
padding: const EdgeInsets.fromLTRB(16, 6, 16, 2), padding: const EdgeInsets.fromLTRB(16, 6, 16, 2),
child: Align( child: Align(
@@ -317,7 +326,7 @@ class _ArchivedSessionsScreenState extends State<ArchivedSessionsScreen> {
children: [ children: [
for (final session in shown) for (final session in shown)
_row(session, _row(session,
showProject: selected == null), showProject: _bucket == null),
], ],
), ),
), ),
@@ -329,28 +338,4 @@ class _ArchivedSessionsScreenState extends State<ArchivedSessionsScreen> {
); );
} }
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});
} }
+40 -5
View File
@@ -103,12 +103,21 @@ class _ProjectPickerSheetState extends State<_ProjectPickerSheet> {
/// already up by then; only its body shows the spinner. /// already up by then; only its body shows the spinner.
bool _refreshing = true; bool _refreshing = true;
final TextEditingController _searchCtrl = TextEditingController();
String _filter = '';
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_refresh(); _refresh();
} }
@override
void dispose() {
_searchCtrl.dispose();
super.dispose();
}
Future<void> _refresh() async { Future<void> _refresh() async {
await Future.wait([ await Future.wait([
widget.app.refreshProjects(), widget.app.refreshProjects(),
@@ -132,6 +141,15 @@ class _ProjectPickerSheetState extends State<_ProjectPickerSheet> {
final chat = widget.selected == AppState.chatTarget; final chat = widget.selected == AppState.chatTarget;
// A cached list is shown at once; the refresh updates it in place. // A cached list is shown at once; the refresh updates it in place.
final projects = selectableProjects(widget.app); final projects = selectableProjects(widget.app);
final query = _filter.trim().toLowerCase();
final visible = query.isEmpty
? projects
: [
for (final project in projects)
if (project.label.toLowerCase().contains(query) ||
project.canonical.toLowerCase().contains(query))
project,
];
final loading = _refreshing && projects.isEmpty; final loading = _refreshing && projects.isEmpty;
return Column( return Column(
children: [ children: [
@@ -155,6 +173,20 @@ class _ProjectPickerSheetState extends State<_ProjectPickerSheet> {
], ],
), ),
), ),
Padding(
padding: const EdgeInsets.fromLTRB(12, 2, 12, 6),
child: TextField(
controller: _searchCtrl,
onChanged: (value) => setState(() => _filter = value),
decoration: InputDecoration(
hintText: tr('Search projects'),
prefixIcon: const Icon(Icons.search, size: 18),
isDense: true,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10)),
),
),
),
Expanded( Expanded(
child: loading child: loading
? const Center( ? const Center(
@@ -207,7 +239,7 @@ class _ProjectPickerSheetState extends State<_ProjectPickerSheet> {
onTap: () => onTap: () =>
Navigator.pop(context, const ProjectChoice.chat()), Navigator.pop(context, const ProjectChoice.chat()),
), ),
for (final project in projects) for (final project in visible)
ListTile( ListTile(
dense: true, dense: true,
leading: ProjectIcon( leading: ProjectIcon(
@@ -224,10 +256,13 @@ class _ProjectPickerSheetState extends State<_ProjectPickerSheet> {
onTap: () => Navigator.pop( onTap: () => Navigator.pop(
context, ProjectChoice.project(project)), context, ProjectChoice.project(project)),
), ),
if (!_refreshing && projects.isEmpty) if (!_refreshing && visible.isEmpty)
const Padding( Padding(
padding: EdgeInsets.all(24), padding: const EdgeInsets.all(24),
child: AppText('No projects available', child: AppText(
query.isEmpty
? 'No projects available'
: 'No matching projects',
textAlign: TextAlign.center), textAlign: TextAlign.center),
), ),
], ],
+1 -1
View File
@@ -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.6.0+600 version: 0.6.1+601
environment: environment:
sdk: ^3.14.0 sdk: ^3.14.0
+22 -7
View File
@@ -19,6 +19,15 @@ class _FakeTransport implements Transport {
Object? body; Object? body;
if (r.path == '/api/session') { if (r.path == '/api/session') {
body = {'data': archived}; body = {'data': archived};
} else if (r.path == '/api/project') {
body = [
{'id': 'p1', 'canonical': '/home/me/alpha', 'vcs': 'git'},
{'id': 'p2', 'canonical': '/home/me/beta', 'vcs': 'git'},
];
} else if (r.path == '/api/config/settings') {
body = {'projects': <dynamic>[]};
} else if (r.path == '/api/fs/home') {
body = {'home': '/home/me'};
} else if (r.method == 'PATCH') { } else if (r.method == 'PATCH') {
archived.removeWhere((s) => s['id'] == r.path.split('/').last); archived.removeWhere((s) => s['id'] == r.path.split('/').last);
body = {'data': <String, dynamic>{}}; body = {'data': <String, dynamic>{}};
@@ -77,16 +86,20 @@ void main() {
expect(find.text('2 archived sessions'), findsOneWidget); expect(find.text('2 archived sessions'), findsOneWidget);
expect(find.text('Old alpha'), findsOneWidget); expect(find.text('Old alpha'), findsOneWidget);
expect(find.text('Old beta'), findsOneWidget); expect(find.text('Old beta'), findsOneWidget);
expect(find.text('All (2)'), findsOneWidget); expect(find.text('All projects'), findsOneWidget);
expect(find.text('alpha (1)'), findsOneWidget);
// A project chip narrows the list; "All" brings both back. // The shared project sheet narrows the archive; "All projects" brings both
await tester.tap(find.text('alpha (1)')); // back.
await tester.tap(find.text('All projects'));
await tester.pumpAndSettle();
await tester.tap(find.text('/home/me/alpha'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('Old alpha'), findsOneWidget); expect(find.text('Old alpha'), findsOneWidget);
expect(find.text('Old beta'), findsNothing); expect(find.text('Old beta'), findsNothing);
expect(find.text('1 archived session'), findsOneWidget); expect(find.text('1 archived session'), findsOneWidget);
await tester.tap(find.text('All (2)')); await tester.tap(find.text('alpha'));
await tester.pumpAndSettle();
await tester.tap(find.text('All projects'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('Old beta'), findsOneWidget); expect(find.text('Old beta'), findsOneWidget);
@@ -105,7 +118,7 @@ void main() {
expect(app.archivedSessions.map((s) => s.id), ['a1']); expect(app.archivedSessions.map((s) => s.id), ['a1']);
}); });
testWidgets('a project chip shows only that project', (tester) async { testWidgets('the project sheet filters the archive', (tester) async {
final app = AppState(); final app = AppState();
addTearDown(app.dispose); addTearDown(app.dispose);
final transport = _FakeTransport([ final transport = _FakeTransport([
@@ -117,7 +130,9 @@ void main() {
await tester.pumpWidget(MaterialApp(home: ArchivedSessionsScreen(app: app))); await tester.pumpWidget(MaterialApp(home: ArchivedSessionsScreen(app: app)));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
await tester.tap(find.text('beta (1)')); await tester.tap(find.text('All projects'));
await tester.pumpAndSettle();
await tester.tap(find.text('/home/me/beta'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(find.text('Old beta'), findsOneWidget); expect(find.text('Old beta'), findsOneWidget);
expect(find.text('Old alpha'), findsNothing); expect(find.text('Old alpha'), findsNothing);