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 buildSubscriptionsPage( Uri url, { required MewsDatabase db, required Strings strings, }) async { final query = url.queryParameters['q'] ?? ''; final tag = url.queryParameters['tag']; final sites = await db.allSubscriptions(query: query, tag: tag); final tags = await db.tagsOfMany( TagKind.subscription, sites.map((s) => s.url).toList()); final unread = await db.unreadCounts(); final title = strings.t('subscriptions-title'); return internalPage( url: url, title: title, body: [ ...chrome(title: title, current: url, strings: strings), textForm( action: MewsUrls.subscriptions, label: strings.t('subscriptions-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('subscriptions-show-all'))]), const MewsText(actionSeparator), ], MewsLink(MewsUrls.tags, [MewsText(strings.t('nav-tags'))]), ]), if (tag != null && tag.isNotEmpty) ParagraphBlock([ MewsEmphasis(EmphasisStyle.emphasis, [MewsText(strings.t('subscriptions-tagged', {'tag': tag}))]), ]), if (sites.isEmpty) ParagraphBlock([ MewsText(strings.t(query.isEmpty ? 'subscriptions-empty' : 'subscriptions-no-matches')), ]) else itemList([ for (final site in sites) itemRow( href: site.url, label: site.title ?? site.url, note: _checkedNote(strings, site, unread[site.url] ?? 0), chips: [ for (final tag in tags[site.url] ?? const []) action(MewsUrls.page(url, {'tag': tag, 'q': null}), tag), ], actions: [ action( MewsUrls.action('refresh-subscription', {'url': site.url}), strings.t('action-refresh')), action(MewsUrls.action('unsubscribe', {'url': site.url}), strings.t('action-unsubscribe')), action(tagsOfItemUrl(TagKind.subscription, site.url), strings.t('action-edit-tags')), ], ), ]), ], ); } /// What the reader needs to know about a site: what is waiting, or when it was /// last looked at. Each is a whole message of its own. String _checkedNote(Strings strings, Subscription site, int unread) { if (unread > 0) { return countText(strings, unread, none: 'count-unread-none', one: 'count-unread-one', many: 'count-unread-many'); } final checkedAt = site.lastCheckedAt; if (checkedAt == null) return strings.t('subscriptions-never-checked'); return strings.t('subscriptions-checked', {'date': dayText(checkedAt)}); }