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

90 lines
3.1 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> 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,
),
...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('subscriptions-show-all')),
]),
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 <String>[])
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)});
}