71 lines
2.3 KiB
Dart
71 lines
2.3 KiB
Dart
import '../../database/database.dart';
|
|
import '../../l10n/strings.dart';
|
|
import '../../mews/document.dart';
|
|
import 'mews_urls.dart';
|
|
import 'page_blocks.dart';
|
|
|
|
Future<MewsPage> buildSubscriptionsPage(
|
|
Uri url, {
|
|
required MewsDatabase db,
|
|
required Strings strings,
|
|
}) async {
|
|
final query = url.queryParameters['q'] ?? '';
|
|
final sites = await db.allSubscriptions(query: query);
|
|
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),
|
|
searchForm(
|
|
action: MewsUrls.subscriptions,
|
|
label: strings.t('subscriptions-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 (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),
|
|
actions: [
|
|
action(
|
|
MewsUrls.action('refresh-subscription', {'url': site.url}),
|
|
strings.t('action-refresh')),
|
|
action(MewsUrls.action('unsubscribe', {'url': site.url}),
|
|
strings.t('action-unsubscribe')),
|
|
],
|
|
),
|
|
]),
|
|
],
|
|
);
|
|
}
|
|
|
|
/// 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)});
|
|
}
|