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

75 lines
2.4 KiB
Dart
Raw Normal View History

import '../../database/database.dart';
import '../../l10n/strings.dart';
import '../../mews/document.dart';
import 'mews_urls.dart';
import 'page_blocks.dart';
import 'tags_page.dart';
Future<MewsPage> buildBookmarksPage(
Uri url, {
required MewsDatabase db,
required Strings strings,
}) async {
final query = url.queryParameters['q'] ?? '';
final tag = url.queryParameters['tag'];
final bookmarks = await db.bookmarksByDate(query: query, tag: tag);
final tags = await db.tagsOfMany(
TagKind.bookmark, bookmarks.map((b) => b.url).toList());
final title = strings.t('bookmarks-title');
return internalPage(
url: url,
title: title,
body: [
...chrome(title: title, current: url, strings: strings),
textForm(
action: MewsUrls.bookmarks,
label: strings.t('bookmarks-search-label'),
submitLabel: strings.t('action-search'),
field: 'q',
value: query,
),
ParagraphBlock([
if (query.isNotEmpty) ...[
MewsLink(MewsUrls.page(url, {'q': null}),
[MewsText(strings.t('action-clear-search'))]),
const MewsText(actionSeparator),
],
if (tag != null && tag.isNotEmpty)
MewsLink(MewsUrls.page(url, {'tag': null}),
[MewsText(strings.t('bookmarks-show-all'))]),
]),
if (tag != null && tag.isNotEmpty)
ParagraphBlock([
MewsEmphasis(EmphasisStyle.emphasis,
[MewsText(strings.t('bookmarks-tagged', {'tag': tag}))]),
]),
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),
chips: [
for (final tag in tags[bookmark.url] ?? const <String>[])
action(MewsUrls.page(url, {'tag': tag, 'q': null}), tag),
],
actions: [
action(
MewsUrls.action('remove-bookmark', {'url': bookmark.url}),
strings.t('action-remove-bookmark')),
action(tagsOfItemUrl(TagKind.bookmark, bookmark.url),
strings.t('action-edit-tags')),
],
),
]),
],
);
}