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
@@ -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});
|
||||
}
|
||||
Reference in new issue
Block a user