the-mews/app/lib/application/pages/bookmarks_page.dart

53 lines
1.5 KiB
Dart

import '../../database/database.dart';
import '../../l10n/strings.dart';
import '../../mews/document.dart';
import 'mews_urls.dart';
import 'page_blocks.dart';
Future<MewsPage> buildBookmarksPage(
Uri url, {
required MewsDatabase db,
required Strings strings,
}) async {
final query = url.queryParameters['q'] ?? '';
final bookmarks = await db.bookmarksByDate(query: query);
final title = strings.t('bookmarks-title');
return internalPage(
url: url,
title: title,
body: [
...chrome(title: title, current: url, strings: strings),
searchForm(
action: MewsUrls.bookmarks,
label: strings.t('bookmarks-search-label'),
submitLabel: strings.t('action-search'),
query: query,
),
if (query.isNotEmpty)
ParagraphBlock([
MewsLink(MewsUrls.page(url, {'q': null}),
[MewsText(strings.t('action-clear-search'))]),
]),
if (bookmarks.isEmpty)
ParagraphBlock([
MewsText(strings.t(
query.isEmpty ? 'bookmarks-empty' : 'bookmarks-no-matches')),
])
else
itemList([
for (final bookmark in bookmarks)
itemRow(
href: bookmark.url,
label: bookmark.title ?? bookmark.url,
date: dayText(bookmark.createdAt),
actions: [
action(
MewsUrls.action('remove-bookmark', {'url': bookmark.url}),
strings.t('action-remove-bookmark')),
],
),
]),
],
);
}