import '../../database/database.dart'; import '../../l10n/strings.dart'; import '../../mews/document.dart'; import 'mews_urls.dart'; import 'page_blocks.dart'; Future buildHistoryPage( Uri url, { required MewsDatabase db, required Strings strings, }) async { 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( url: url, title: title, body: [ ...chrome(title: title, current: url, strings: strings), textForm( action: MewsUrls.history, label: strings.t('history-search-label'), submitLabel: strings.t('action-search'), field: 'q', value: 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 ...linkLine([ if (query.isNotEmpty) action(MewsUrls.page(url, {'q': null}), strings.t('action-clear-search')), if (pages.isNotEmpty) action(MewsUrls.page(url, {'confirm': 'clear'}), strings.t('history-clear')), ]), if (pages.isEmpty) ParagraphBlock([ MewsText(strings .t(query.isEmpty ? 'history-empty' : 'history-no-matches')), ]) else itemList([ for (final page in pages) itemRow( 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')), ], ), ]), ], ); }