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:
1 parent
a7e4ed8dd7
commit
83e09e8e25
7 files changed
+156
-109
No files matched your search
@@ -5,6 +5,16 @@
|
||||
|
||||
---
|
||||
|
||||
## 0.6.1 归档筛选改用共享项目选择器(分支 `flutter`)
|
||||
|
||||
| 项 | 结果 |
|
||||
| --- | --- |
|
||||
| 项目筛选 | 归档页顶部原来的横向项目 chips 改为与新建会话 / 计划任务 / 统计一致的项目选择行:点击打开共享项目 bottomsheet(含「所有项目」「聊天」与全部项目、图标、路径、当前选中标记),选完立即筛选归档列表;项目很多时不会再横向挤在一起 |
|
||||
| 选择器搜索 | 共享项目 bottomsheet 新增搜索框,按项目名或路径过滤,项目很多时也能快速定位;无匹配时显示「没有匹配的项目」 |
|
||||
| 版本 | **0.6.1(code 601)** |
|
||||
|
||||
---
|
||||
|
||||
## 0.6.0 归档页面(分支 `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
|
||||
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
|
||||
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
|
||||
|
||||
@@ -618,7 +618,9 @@ const Map<String, String> chineseStrings = {
|
||||
'1 archived session': '1 个已归档会话',
|
||||
'{0} archived sessions': '{0} 个已归档会话',
|
||||
'Search archived sessions': '搜索已归档会话',
|
||||
'Search projects': '搜索项目',
|
||||
'No matching archived sessions': '没有匹配的已归档会话',
|
||||
'No matching projects': '没有匹配的项目',
|
||||
'Browse archived sessions and restore them': '浏览已归档的会话并恢复',
|
||||
'Session restored': '会话已恢复',
|
||||
};
|
||||
@@ -8,6 +8,8 @@ import 'package:flutter/services.dart';
|
||||
import '../api/models.dart';
|
||||
import '../l10n.dart';
|
||||
import '../state.dart';
|
||||
import '../widgets/project_icon.dart';
|
||||
import '../widgets/project_picker.dart';
|
||||
|
||||
class ArchivedSessionsScreen extends StatefulWidget {
|
||||
final AppState app;
|
||||
@@ -40,52 +42,89 @@ class _ArchivedSessionsScreenState extends State<ArchivedSessionsScreen> {
|
||||
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 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;
|
||||
return [
|
||||
for (final session in _app.archivedSessions)
|
||||
if (_matches(session.directory) &&
|
||||
(query.isEmpty ||
|
||||
session.title.toLowerCase().contains(query) ||
|
||||
session.id.toLowerCase().contains(query) ||
|
||||
_app
|
||||
.projectLabelFor(session.directory)
|
||||
.toLowerCase()
|
||||
.contains(query)))
|
||||
session,
|
||||
]..sort((a, b) => _time(b).compareTo(_time(a)));
|
||||
}
|
||||
|
||||
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> _pickProject() async {
|
||||
final choice = await showProjectPicker(
|
||||
context,
|
||||
app: _app,
|
||||
selected: _bucket ?? allProjectsTarget,
|
||||
includeAll: true,
|
||||
);
|
||||
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 {
|
||||
await _app.setArchived(session, false);
|
||||
@@ -224,16 +263,8 @@ class _ArchivedSessionsScreenState extends State<ArchivedSessionsScreen> {
|
||||
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 shown = _filtered();
|
||||
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]);
|
||||
@@ -253,29 +284,7 @@ class _ArchivedSessionsScreenState extends State<ArchivedSessionsScreen> {
|
||||
),
|
||||
),
|
||||
),
|
||||
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),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
_scopeRow(theme),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 6, 16, 2),
|
||||
child: Align(
|
||||
@@ -317,7 +326,7 @@ class _ArchivedSessionsScreenState extends State<ArchivedSessionsScreen> {
|
||||
children: [
|
||||
for (final session in shown)
|
||||
_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});
|
||||
}
|
||||
@@ -103,12 +103,21 @@ class _ProjectPickerSheetState extends State<_ProjectPickerSheet> {
|
||||
/// already up by then; only its body shows the spinner.
|
||||
bool _refreshing = true;
|
||||
|
||||
final TextEditingController _searchCtrl = TextEditingController();
|
||||
String _filter = '';
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_refresh();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_searchCtrl.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _refresh() async {
|
||||
await Future.wait([
|
||||
widget.app.refreshProjects(),
|
||||
@@ -132,6 +141,15 @@ class _ProjectPickerSheetState extends State<_ProjectPickerSheet> {
|
||||
final chat = widget.selected == AppState.chatTarget;
|
||||
// A cached list is shown at once; the refresh updates it in place.
|
||||
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;
|
||||
return Column(
|
||||
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(
|
||||
child: loading
|
||||
? const Center(
|
||||
@@ -207,7 +239,7 @@ class _ProjectPickerSheetState extends State<_ProjectPickerSheet> {
|
||||
onTap: () =>
|
||||
Navigator.pop(context, const ProjectChoice.chat()),
|
||||
),
|
||||
for (final project in projects)
|
||||
for (final project in visible)
|
||||
ListTile(
|
||||
dense: true,
|
||||
leading: ProjectIcon(
|
||||
@@ -224,10 +256,13 @@ class _ProjectPickerSheetState extends State<_ProjectPickerSheet> {
|
||||
onTap: () => Navigator.pop(
|
||||
context, ProjectChoice.project(project)),
|
||||
),
|
||||
if (!_refreshing && projects.isEmpty)
|
||||
const Padding(
|
||||
padding: EdgeInsets.all(24),
|
||||
child: AppText('No projects available',
|
||||
if (!_refreshing && visible.isEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: AppText(
|
||||
query.isEmpty
|
||||
? 'No projects available'
|
||||
: 'No matching projects',
|
||||
textAlign: TextAlign.center),
|
||||
),
|
||||
],
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ name: openchamber
|
||||
description: "A lightweight OpenChamber client for phones."
|
||||
publish_to: 'none'
|
||||
|
||||
version: 0.6.0+600
|
||||
version: 0.6.1+601
|
||||
|
||||
environment:
|
||||
sdk: ^3.14.0
|
||||
|
||||
@@ -19,6 +19,15 @@ class _FakeTransport implements Transport {
|
||||
Object? body;
|
||||
if (r.path == '/api/session') {
|
||||
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') {
|
||||
archived.removeWhere((s) => s['id'] == r.path.split('/').last);
|
||||
body = {'data': <String, dynamic>{}};
|
||||
@@ -77,16 +86,20 @@ void main() {
|
||||
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);
|
||||
expect(find.text('All projects'), findsOneWidget);
|
||||
|
||||
// A project chip narrows the list; "All" brings both back.
|
||||
await tester.tap(find.text('alpha (1)'));
|
||||
// The shared project sheet narrows the archive; "All projects" brings both
|
||||
// back.
|
||||
await tester.tap(find.text('All projects'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('/home/me/alpha'));
|
||||
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.tap(find.text('alpha'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('All projects'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Old beta'), findsOneWidget);
|
||||
|
||||
@@ -105,7 +118,7 @@ void main() {
|
||||
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();
|
||||
addTearDown(app.dispose);
|
||||
final transport = _FakeTransport([
|
||||
@@ -117,7 +130,9 @@ void main() {
|
||||
await tester.pumpWidget(MaterialApp(home: ArchivedSessionsScreen(app: app)));
|
||||
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();
|
||||
expect(find.text('Old beta'), findsOneWidget);
|
||||
expect(find.text('Old alpha'), findsNothing);
|
||||
|
||||
Reference in new issue
Block a user