fix(player): 评论总数含回复并改用相对时间
This commit is contained in:
1 parent
22cb74ded4
commit
2659c29501
14 files changed
+212
-9
No files matched your search
@@ -3,7 +3,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/data/models/comment.dart';
|
||||
import '../../../core/formatting/localized_date_time.dart';
|
||||
import '../../../core/formatting/relative_date_time.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_dimens.dart';
|
||||
import '../../../core/widgets/remote_image.dart';
|
||||
@@ -164,7 +164,7 @@ class CommentTile extends StatelessWidget {
|
||||
children: [
|
||||
if (createdAt != null)
|
||||
Text(
|
||||
formatLocalizedDateTime(context, createdAt),
|
||||
formatRelativeDateTime(createdAt, l10n),
|
||||
style: const TextStyle(color: AppColors.subtle, fontSize: 12),
|
||||
),
|
||||
if (createdAt != null && !isReply) ...[
|
||||
|
||||
@@ -43,18 +43,23 @@ class DramaCommentsSheet extends StatefulWidget {
|
||||
class _DramaCommentsSheetState extends State<DramaCommentsSheet> {
|
||||
final _input = TextEditingController();
|
||||
final _inputFocus = FocusNode();
|
||||
late final CommentRepository _comments;
|
||||
late final CommentController _controller;
|
||||
DramaComment? _replyTo;
|
||||
int? _serverCount;
|
||||
int _countRequest = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_comments = context.read<CommentRepository>();
|
||||
_controller = CommentController(
|
||||
comments: context.read<CommentRepository>(),
|
||||
comments: _comments,
|
||||
interactions: context.read<InteractionRepository>(),
|
||||
dramaId: widget.drama.id,
|
||||
);
|
||||
unawaited(_controller.load());
|
||||
unawaited(_refreshCount());
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -76,6 +81,7 @@ class _DramaCommentsSheetState extends State<DramaCommentsSheet> {
|
||||
_input.clear();
|
||||
setState(() => _replyTo = null);
|
||||
FocusScope.of(context).unfocus();
|
||||
await _refreshCount();
|
||||
return;
|
||||
}
|
||||
_showMessage(
|
||||
@@ -122,11 +128,26 @@ class _DramaCommentsSheetState extends State<DramaCommentsSheet> {
|
||||
);
|
||||
if (confirmed != true || !mounted) return;
|
||||
final result = await _controller.delete(comment);
|
||||
if (!result.isSuccess && mounted) {
|
||||
if (!result.isSuccess) {
|
||||
if (!mounted) return;
|
||||
_showMessage(
|
||||
result.errorMessage ??
|
||||
AppLocalizations.of(context)!.commentDeleteFailed,
|
||||
);
|
||||
return;
|
||||
}
|
||||
await _refreshCount();
|
||||
}
|
||||
|
||||
Future<void> _refreshCount() async {
|
||||
final request = ++_countRequest;
|
||||
try {
|
||||
final count = await _comments.count(widget.drama.id);
|
||||
if (!mounted || request != _countRequest) return;
|
||||
setState(() => _serverCount = count);
|
||||
} catch (_) {
|
||||
if (!mounted || request != _countRequest) return;
|
||||
setState(() => _serverCount = null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,7 +211,7 @@ class _DramaCommentsSheetState extends State<DramaCommentsSheet> {
|
||||
|
||||
Widget _content(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final count = _controller.exactCount;
|
||||
final count = _serverCount ?? _controller.exactCount;
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
|
||||
Reference in new issue
Block a user