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 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, ), ...linkLine([ if (query.isNotEmpty) action(MewsUrls.page(url, {'q': null}), strings.t('action-clear-search')), if (tag != null && tag.isNotEmpty) action(MewsUrls.page(url, {'tag': null}), 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 []) 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')), ], ), ]), ], ); }