Files
Docwell/Phone-App/lib/screens/comments_screen.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

262 lines
8.2 KiB
Dart

// SPDX-License-Identifier: AGPL-3.0-or-later
import 'package:flutter/material.dart' hide Notification, Page;
import '../api/docwell_api.dart';
import '../app.dart';
import 'widgets.dart';
import '../l10n.dart';
/// A page's comment threads with their replies. People who may comment can
/// start a thread, reply and resolve.
class CommentsScreen extends StatefulWidget {
const CommentsScreen({
super.key,
required this.session,
required this.page,
this.highlight,
});
final AppSession session;
final Page page;
/// A comment to scroll to and mark (from a notification).
final String? highlight;
@override
State<CommentsScreen> createState() => _CommentsScreenState();
}
class _CommentsScreenState extends State<CommentsScreen> {
DocwellApi get _api => widget.session.api;
List<Comment>? _comments;
String? _error;
bool _showResolved = false;
final _text = TextEditingController();
Comment? _replyTo;
bool _busy = false;
bool get _canComment => widget.page.role.canComment && !widget.page.inTrash;
@override
void initState() {
super.initState();
_load();
}
Future<void> _load() async {
try {
final list = await _api.comments(widget.page.id);
if (mounted) {
setState(() {
_comments = list;
_error = null;
});
}
} catch (e) {
if (mounted) setState(() => _error = describeError(e));
}
}
Future<void> _send() async {
final body = _text.text.trim();
if (body.isEmpty) return;
setState(() => _busy = true);
try {
await _api.addComment(widget.page.id, body, parent: _replyTo?.id ?? '');
_text.clear();
_replyTo = null;
await _load();
} catch (e) {
if (mounted) {
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text(describeError(e))));
}
} finally {
if (mounted) setState(() => _busy = false);
}
}
Future<void> _resolve(Comment c) async {
try {
await _api.resolveComment(c.id, c.resolvedAt.isEmpty);
await _load();
} catch (e) {
if (mounted) {
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text(describeError(e))));
}
}
}
Widget _comment(Comment c, {bool reply = false}) {
final marked = c.id == widget.highlight;
final theme = Theme.of(context);
return Container(
color: marked ? theme.colorScheme.secondaryContainer : null,
padding: EdgeInsets.fromLTRB(reply ? 40 : 16, 8, 16, 8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (c.quote.isNotEmpty)
Container(
margin: const EdgeInsets.only(bottom: 6),
padding: const EdgeInsets.only(left: 8),
decoration: BoxDecoration(
border: Border(
left: BorderSide(color: theme.colorScheme.outline, width: 3),
),
),
child: Text(
c.quote,
maxLines: 3,
overflow: TextOverflow.ellipsis,
style: theme.textTheme.bodySmall,
),
),
Text.rich(
TextSpan(
children: [
TextSpan(
text: c.author.name.isEmpty ? c.author.email : c.author.name,
style: const TextStyle(fontWeight: FontWeight.w600),
),
TextSpan(
text: ' ${shortDate(c.created)}',
style: theme.textTheme.bodySmall,
),
],
),
),
const SizedBox(height: 2),
Text(c.body),
],
),
);
}
@override
Widget build(BuildContext context) {
final all = _comments;
final threads = (all ?? [])
.where(
(c) => c.parent.isEmpty && (_showResolved || c.resolvedAt.isEmpty),
)
.toList();
final resolved = (all ?? [])
.where((c) => c.parent.isEmpty && c.resolvedAt.isNotEmpty)
.length;
return Scaffold(
appBar: AppBar(
title: Text(tr('comments')),
actions: [
if (resolved > 0)
TextButton(
onPressed: () => setState(() => _showResolved = !_showResolved),
child: Text(
_showResolved
? tr('hideResolved')
: tr('showResolved', {'n': resolved}),
),
),
],
),
body: Column(
children: [
Expanded(
child: RefreshIndicator(
onRefresh: _load,
child: ListView(
children: [
if (_error != null)
ErrorTile(message: _error!, onRetry: _load)
else if (all == null)
const Padding(
padding: EdgeInsets.all(32),
child: Center(child: CircularProgressIndicator()),
)
else if (threads.isEmpty)
ListTile(title: Text(tr('noComments'))),
for (final t in threads)
Card(
margin: const EdgeInsets.fromLTRB(12, 8, 12, 0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_comment(t),
for (final r in all!.where((c) => c.parent == t.id))
_comment(r, reply: true),
OverflowBar(
alignment: MainAxisAlignment.end,
children: [
if (t.canResolve)
TextButton(
onPressed: () => _resolve(t),
child: Text(
t.resolvedAt.isEmpty
? tr('resolve')
: tr('reopen'),
),
),
if (_canComment && t.resolvedAt.isEmpty)
TextButton(
onPressed: () => setState(() => _replyTo = t),
child: Text(tr('reply')),
),
],
),
],
),
),
],
),
),
),
if (_canComment)
SafeArea(
top: false,
child: Padding(
padding: const EdgeInsets.fromLTRB(12, 8, 8, 8),
child: Row(
children: [
Expanded(
child: TextField(
key: const Key('comment-text'),
controller: _text,
minLines: 1,
maxLines: 5,
decoration: InputDecoration(
hintText: _replyTo == null
? tr('commentOnPage')
: tr('replyTo', {'name': _replyTo!.author.name}),
border: const OutlineInputBorder(),
isDense: true,
suffixIcon: _replyTo == null
? null
: IconButton(
tooltip: tr('cancelReply'),
icon: const Icon(Icons.close),
onPressed: () =>
setState(() => _replyTo = null),
),
),
),
),
IconButton(
key: const Key('comment-send'),
tooltip: tr('send'),
icon: const Icon(Icons.send),
onPressed: _busy ? null : _send,
),
],
),
),
),
],
),
);
}
}