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

91 lines
3 KiB
Dart

import '../../database/database.dart';
import '../../l10n/strings.dart';
import '../../mews/document.dart';
import '../controllers/subscriptions_controller.dart';
import 'mews_urls.dart';
import 'page_blocks.dart';
/// The hub names every page the client provides and says what each one holds,
/// so the reader has somewhere to start. Its menu is the navigation, so it
/// carries no strip of its own.
Future<MewsPage> buildHubPage(
Uri url, {
required MewsDatabase db,
required SubscriptionsController subscriptions,
required Strings strings,
}) async {
final bookmarks = await db.countBookmarks();
final sites = await db.countSubscriptions();
final visits = await db.countHistory();
final unread = await db.unreadCount();
final quotations = await db.countQuotations();
final tags = await db.tagCounts();
return internalPage(
url: url,
title: strings.t('hub-title'),
strings: strings,
body: [
HeadingBlock(1, [MewsText(strings.t('hub-title'))]),
itemList([
itemRow(
href: MewsUrls.posts,
label: strings.t('nav-posts'),
note: countText(strings, unread,
none: 'count-unread-none',
one: 'count-unread-one',
many: 'count-unread-many'),
),
itemRow(
href: MewsUrls.quotations,
label: strings.t('nav-quotations'),
note: countText(strings, quotations,
none: 'count-quotations-none',
one: 'count-quotations-one',
many: 'count-quotations-many'),
),
itemRow(
href: MewsUrls.bookmarks,
label: strings.t('nav-bookmarks'),
note: countText(strings, bookmarks,
none: 'count-bookmarks-none',
one: 'count-bookmarks-one',
many: 'count-bookmarks-many'),
),
itemRow(
href: MewsUrls.subscriptions,
label: strings.t('nav-subscriptions'),
note: countText(strings, sites,
none: 'count-sites-none',
one: 'count-sites-one',
many: 'count-sites-many'),
),
itemRow(
href: MewsUrls.history,
label: strings.t('nav-history'),
note: countText(strings, visits,
none: 'count-pages-none',
one: 'count-pages-one',
many: 'count-pages-many'),
),
itemRow(
href: MewsUrls.tags,
label: strings.t('nav-tags'),
note: countText(strings, tags.length,
none: 'count-tags-none',
one: 'count-tags-one',
many: 'count-tags-many'),
),
itemRow(href: MewsUrls.settings, label: strings.t('nav-settings')),
]),
ParagraphBlock([
if (subscriptions.refreshing.value)
MewsEmphasis(EmphasisStyle.emphasis,
[MewsText(strings.t('posts-checking'))])
else
MewsLink(MewsUrls.action('refresh-subscriptions'),
[MewsText(strings.t('action-refresh'))]),
]),
],
);
}