feat: search, filter and act on items from the library pages

This commit is contained in:
randogoth 2026-10-11 13:25:57 +03:00
parent 1b426ccd8b
commit 5cd053c8a9
11 changed files with 401 additions and 43 deletions

View file

@ -1,6 +1,7 @@
import '../../database/database.dart';
import '../../l10n/strings.dart';
import '../../mews/document.dart';
import 'mews_urls.dart';
import 'page_blocks.dart';
Future<MewsPage> buildHistoryPage(
@ -8,7 +9,9 @@ Future<MewsPage> buildHistoryPage(
required MewsDatabase db,
required Strings strings,
}) async {
final visits = await db.recentVisits();
final query = url.queryParameters['q'] ?? '';
final confirming = url.queryParameters['confirm'] == 'clear';
final pages = await db.recentPages(query: query);
final title = strings.t('history-title');
return internalPage(
@ -16,15 +19,49 @@ Future<MewsPage> buildHistoryPage(
title: title,
body: [
...chrome(title: title, current: url, strings: strings),
if (visits.isEmpty)
ParagraphBlock([MewsText(strings.t('history-empty'))])
searchForm(
action: MewsUrls.history,
label: strings.t('history-search-label'),
submitLabel: strings.t('action-search'),
query: query,
),
// Clearing history cannot be undone, so it takes a second step rather
// than a dialog: another page the reader can simply leave.
if (confirming) ...[
ParagraphBlock([MewsText(strings.t('history-clear-confirm'))]),
ParagraphBlock([
MewsLink(MewsUrls.action('clear-history'),
[MewsText(strings.t('history-clear-yes'))]),
const MewsText(actionSeparator),
MewsLink(MewsUrls.history, [MewsText(strings.t('history-clear-no'))]),
]),
] else
ParagraphBlock([
if (query.isNotEmpty) ...[
MewsLink(MewsUrls.page(url, {'q': null}),
[MewsText(strings.t('action-clear-search'))]),
const MewsText(actionSeparator),
],
if (pages.isNotEmpty)
MewsLink(MewsUrls.page(url, {'confirm': 'clear'}),
[MewsText(strings.t('history-clear'))]),
]),
if (pages.isEmpty)
ParagraphBlock([
MewsText(strings
.t(query.isEmpty ? 'history-empty' : 'history-no-matches')),
])
else
itemList([
for (final visit in visits)
for (final page in pages)
itemRow(
href: visit.url,
label: visit.title ?? visit.url,
date: dayTimeText(visit.visitedAt),
href: page.url,
label: page.title ?? page.url,
date: dayTimeText(page.visitedAt),
actions: [
action(MewsUrls.action('forget-page', {'url': page.url}),
strings.t('history-forget')),
],
),
]),
],