From 8ac36b1fb16e6a61e1a0dc2253ed5c4e0724255d Mon Sep 17 00:00:00 2001 From: Wang Zichong Date: Fri, 27 Nov 2026 13:36:11 +0800 Subject: [PATCH] feat: the archive picker offers only projects that hold archived sessions - the archive page passes its project set to the shared picker, built from the archived sessions' directories (deduped and sorted by name), so the sheet no longer lists every server project - the restricted picker hides the add-project action: the archive page never archives anything, so adding a project there would be pointless - the picker gained an optional onlyProjects argument; chat archives remain reachable through the Chat row - version 0.6.2+602 --- PLAN.md | 9 +++++++ README.md | 2 +- lib/screens/archived_sessions_screen.dart | 19 ++++++++++++++ lib/widgets/project_picker.dart | 30 +++++++++++++++-------- pubspec.yaml | 2 +- test/archived_sessions_test.dart | 6 +++++ 6 files changed, 56 insertions(+), 12 deletions(-) diff --git a/PLAN.md b/PLAN.md index 2fb4781..03667a6 100644 --- a/PLAN.md +++ b/PLAN.md @@ -5,6 +5,15 @@ --- +## 0.6.2 归档选择器只列有归档的项目(分支 `flutter`) + +| 项 | 结果 | +| --- | --- | +| 筛选范围 | 归档页打开的项目选择器只列出**实际有已归档会话**的项目(按名字排序),不再显示全部项目;同时隐藏「添加项目」按钮(归档页不会新增归档,添加项目在此无意义)。聊天归档仍通过「聊天」行进入 | +| 版本 | **0.6.2(code 602)** | + +--- + ## 0.6.1 归档筛选改用共享项目选择器(分支 `flutter`) | 项 | 结果 | diff --git a/README.md b/README.md index d98549d..a52929d 100644 --- a/README.md +++ b/README.md @@ -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.1 — servers (passwordless / password login, HTTP/HTTPS and +Status: 0.6.2 — 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 diff --git a/lib/screens/archived_sessions_screen.dart b/lib/screens/archived_sessions_screen.dart index 008aea9..6bae071 100644 --- a/lib/screens/archived_sessions_screen.dart +++ b/lib/screens/archived_sessions_screen.dart @@ -76,12 +76,31 @@ class _ArchivedSessionsScreenState extends State { Future _refresh() => _app.refreshArchived(); + /// The projects the picker offers here: only checkouts that actually hold + /// archived sessions. This page never archives anything, so a project + /// without an archive would only get in the way. + List _archiveProjects() { + final byPath = {}; + for (final session in _app.archivedSessions) { + final directory = session.directory; + if (directory.isEmpty || _app.isChatDirectory(directory)) continue; + final project = _app.projectFor(directory) ?? + ProjectInfo(id: '', canonical: directory, name: pathLeaf(directory)); + final key = slashPath(project.canonical).toLowerCase(); + byPath.putIfAbsent(key, () => project); + } + final projects = byPath.values.toList() + ..sort((a, b) => a.label.toLowerCase().compareTo(b.label.toLowerCase())); + return projects; + } + Future _pickProject() async { final choice = await showProjectPicker( context, app: _app, selected: _bucket ?? allProjectsTarget, includeAll: true, + onlyProjects: _archiveProjects(), ); if (choice == null || !mounted) return; setState(() => _bucket = choice.isAll ? null : choice.canonical); diff --git a/lib/widgets/project_picker.dart b/lib/widgets/project_picker.dart index de4de90..d9b832a 100644 --- a/lib/widgets/project_picker.dart +++ b/lib/widgets/project_picker.dart @@ -36,13 +36,16 @@ class ProjectChoice { /// Opens the project sheet and returns the chosen target, or null when the /// person dismissed it. [selected] is a checkout path, or [AppState.chatTarget] -/// for the Chat row. +/// for the Chat row. [onlyProjects] limits the list to exactly those projects +/// (the archive page offers only projects that hold archived sessions, since +/// it never archives anything itself); null lists every selectable checkout. Future showProjectPicker( BuildContext context, { required AppState app, required String selected, bool includeAll = false, bool includeChat = true, + List? onlyProjects, }) { return showModalBottomSheet( context: context, @@ -56,6 +59,7 @@ Future showProjectPicker( selected: selected, includeAll: includeAll, includeChat: includeChat, + projects: onlyProjects, controller: controller, ), ), @@ -84,6 +88,10 @@ class _ProjectPickerSheet extends StatefulWidget { final String selected; final bool includeAll; final bool includeChat; + + /// Null offers every selectable checkout; a list limits the picker to it + /// (the archive page) and hides the add-project action. + final List? projects; final ScrollController controller; const _ProjectPickerSheet({ @@ -91,6 +99,7 @@ class _ProjectPickerSheet extends StatefulWidget { required this.selected, required this.includeAll, required this.includeChat, + required this.projects, required this.controller, }); @@ -140,7 +149,7 @@ class _ProjectPickerSheetState extends State<_ProjectPickerSheet> { Widget build(BuildContext context) { 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 projects = widget.projects ?? selectableProjects(widget.app); final query = _filter.trim().toLowerCase(); final visible = query.isEmpty ? projects @@ -162,14 +171,15 @@ class _ProjectPickerSheetState extends State<_ProjectPickerSheet> { style: TextStyle(fontSize: 17, fontWeight: FontWeight.w600)), ), - TextButton.icon( - onPressed: _addProject, - style: TextButton.styleFrom( - visualDensity: VisualDensity.compact, - padding: const EdgeInsets.symmetric(horizontal: 8)), - icon: const Icon(Icons.create_new_folder_outlined, size: 18), - label: const AppText('Add project'), - ), + if (widget.projects == null) + TextButton.icon( + onPressed: _addProject, + style: TextButton.styleFrom( + visualDensity: VisualDensity.compact, + padding: const EdgeInsets.symmetric(horizontal: 8)), + icon: const Icon(Icons.create_new_folder_outlined, size: 18), + label: const AppText('Add project'), + ), ], ), ), diff --git a/pubspec.yaml b/pubspec.yaml index 355cd81..8564069 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: openchamber description: "A lightweight OpenChamber client for phones." publish_to: 'none' -version: 0.6.1+601 +version: 0.6.2+602 environment: sdk: ^3.14.0 diff --git a/test/archived_sessions_test.dart b/test/archived_sessions_test.dart index df5bf5f..3f81821 100644 --- a/test/archived_sessions_test.dart +++ b/test/archived_sessions_test.dart @@ -23,6 +23,8 @@ class _FakeTransport implements Transport { body = [ {'id': 'p1', 'canonical': '/home/me/alpha', 'vcs': 'git'}, {'id': 'p2', 'canonical': '/home/me/beta', 'vcs': 'git'}, + // A project with no archived sessions must not be offered. + {'id': 'p3', 'canonical': '/home/me/gamma', 'vcs': 'git'}, ]; } else if (r.path == '/api/config/settings') { body = {'projects': []}; @@ -92,6 +94,9 @@ void main() { // back. await tester.tap(find.text('All projects')); await tester.pumpAndSettle(); + // Only projects with archived sessions are offered; no add-project here. + expect(find.text('Add project'), findsNothing); + expect(find.text('/home/me/gamma'), findsNothing); await tester.tap(find.text('/home/me/alpha')); await tester.pumpAndSettle(); expect(find.text('Old alpha'), findsOneWidget); @@ -132,6 +137,7 @@ void main() { await tester.tap(find.text('All projects')); await tester.pumpAndSettle(); + expect(find.text('/home/me/gamma'), findsNothing); await tester.tap(find.text('/home/me/beta')); await tester.pumpAndSettle(); expect(find.text('Old beta'), findsOneWidget);