Files
Docwell/Phone-App/lib/screens/widgets.dart
T
tajniak81andClaude Opus 5.5 0640004895
CI / go (Server) (push) Failing after 4m38s
CI / go (Web-App) (push) Successful in 12m18s
Docs / build (push) Canceled after 0s
Docs / deploy (push) Canceled after 0s
CI / frontend (push) Failing after 7m49s
CI / desktop (ubuntu-latest) (push) Successful in 1h25m30s
CI / mobile (push) Failing after 5m14s
CI / docker (push) Successful in 39m26s
CI / desktop (macos-latest) (push) Canceled after 0s
CI / desktop (windows-latest) (push) Canceled after 0s
Add database relations and rollups, full-page records, and translate the admin panel and phone app
Databases (ADR-13 follow-ups):
- Relation properties link records to another database, on the same page
  or on any page the reader can open (read live and read-only, like synced
  pages). Cells list the linked titles; clicking one opens the record.
- Rollup properties work out counts, sums, averages, medians, min/max,
  ranges, earliest/latest dates and checked counts over related records.
  Neither is stored: views compute them before drawing (linked.ts), so they
  follow both databases live, and rollups sort and filter as numbers.
- Exports (Markdown, HTML, PDF, Word) resolve them for same-page databases.
- A record opens as a full page at /p/<page>/r/<database>/<record>, with
  "Open as full page" on the side panel and "Back to the page".

Edgeless mode (ADR-14 follow-ups):
- History previews show a version's canvas and count canvas changes.
- Comments can be anchored to canvas elements (anchor {element}); elements
  with open threads show a badge that opens the thread.
- Workspaces choose how new pages open (workspaces.default_page_mode); the
  per-device choice now defaults to following the workspace.
- Phones edit the canvas once a page is opened for editing; the page note
  shows the page title.

Languages:
- The admin panel speaks English, Polish, German, French and Spanish, with
  a picker sharing the web app's setting and a key parity test.
- The phone app speaks the same five, follows the phone's language (and
  Android's per-app language setting), and has its own parity test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 17:11:47 +01:00

116 lines
3.0 KiB
Dart

// SPDX-License-Identifier: AGPL-3.0-or-later
import 'dart:io';
import 'package:flutter/material.dart';
import '../api/docwell_api.dart';
import '../l10n.dart';
/// A short, human explanation of a failed request.
String describeError(Object e) {
if (e is DocwellApiException) {
if (e.status == 404) return tr('errNotFound');
if (e.status == 403) return tr('errForbidden');
return e.message.isNotEmpty
? e.message
: tr('errRefused', {'code': e.code});
}
if (e is SocketException || e is HttpException) {
return tr('errOfflineNew');
}
return tr('errOffline');
}
class OfflineBanner extends StatelessWidget {
const OfflineBanner({super.key});
@override
Widget build(BuildContext context) => MaterialBanner(
key: const Key('offline'),
leading: const Icon(Icons.cloud_off_outlined),
content: Text(tr('offlineBanner')),
actions: const [SizedBox.shrink()],
);
}
class ErrorTile extends StatelessWidget {
const ErrorTile({super.key, required this.message, required this.onRetry});
final String message;
final VoidCallback onRetry;
@override
Widget build(BuildContext context) => Padding(
padding: const EdgeInsets.all(24),
child: Column(
children: [
Text(message, textAlign: TextAlign.center),
const SizedBox(height: 12),
FilledButton(onPressed: onRetry, child: Text(tr('retry'))),
],
),
);
}
class SectionTitle extends StatelessWidget {
const SectionTitle(this.text, {super.key});
final String text;
@override
Widget build(BuildContext context) => Padding(
padding: const EdgeInsets.fromLTRB(16, 20, 16, 4),
child: Text(
text.toUpperCase(),
style: Theme.of(context).textTheme.labelSmall?.copyWith(
letterSpacing: 0.8,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
);
}
/// A page's emoji icon, or a generic page icon.
class PageIcon extends StatelessWidget {
const PageIcon(this.icon, {super.key});
final String icon;
@override
Widget build(BuildContext context) => SizedBox(
width: 28,
child: Center(
child: icon.isEmpty
? const Icon(Icons.description_outlined)
: Text(icon, style: const TextStyle(fontSize: 20)),
),
);
}
/// PocketBase dates look like "2026-10-30 21:05:00.000Z".
String shortDate(String s) {
final d = DateTime.tryParse(s.replaceFirst(' ', 'T'))?.toLocal();
if (d == null) return '';
final now = DateTime.now();
final hm =
'${d.hour.toString().padLeft(2, '0')}:${d.minute.toString().padLeft(2, '0')}';
if (d.year == now.year && d.month == now.month && d.day == now.day) {
return hm;
}
return '${d.day}.${d.month.toString().padLeft(2, '0')}.${d.year} $hm';
}
/// A stable colour for a user id, as the web editor's carets use.
String userColor(String id) {
const hues = [
'#2f7d6d', '#7c5cc4', '#c2571a', '#2f6fbf', //
'#b8327a', '#5f8a1f', '#a0761c', '#1f8a9a',
];
var h = 0;
for (final c in id.codeUnits) {
h = (h * 31 + c) & 0xffffffff;
}
return hues[h % hues.length];
}