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
This commit is contained in:
blumia committed 2026-11-27 13:36:11 +08:00
1 parent 83e09e8e25
commit 8ac36b1fb1
6 files changed
+56 -12

No files matched your search

+19
View File
@@ -76,12 +76,31 @@ class _ArchivedSessionsScreenState extends State<ArchivedSessionsScreen> {
Future<void> _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<ProjectInfo> _archiveProjects() {
final byPath = <String, ProjectInfo>{};
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<void> _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);
+20 -10
View File
@@ -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<ProjectChoice?> showProjectPicker(
BuildContext context, {
required AppState app,
required String selected,
bool includeAll = false,
bool includeChat = true,
List<ProjectInfo>? onlyProjects,
}) {
return showModalBottomSheet<ProjectChoice>(
context: context,
@@ -56,6 +59,7 @@ Future<ProjectChoice?> 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<ProjectInfo>? 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'),
),
],
),
),