🐛 Bug fixes on edit content truncated post

This commit is contained in:
LittleSheep 2024-10-14 23:04:55 +08:00
parent 063c087089
commit 59c4d667f6
2 changed files with 57 additions and 24 deletions

View File

@ -4,8 +4,13 @@ import 'package:gap/gap.dart';
class LoadingIndicator extends StatefulWidget {
final bool isActive;
final Color? backgroundColor;
const LoadingIndicator({super.key, this.isActive = true});
const LoadingIndicator({
super.key,
this.isActive = true,
this.backgroundColor,
});
@override
State<LoadingIndicator> createState() => _LoadingIndicatorState();
@ -63,7 +68,7 @@ class _LoadingIndicatorState extends State<LoadingIndicator>
axisAlignment: -1, // Align animation from the top
child: Container(
padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 24),
color:
color: widget.backgroundColor ??
Theme.of(context).colorScheme.surfaceContainerLow.withOpacity(0.5),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,

View File

@ -11,6 +11,7 @@ import 'package:solian/exts.dart';
import 'package:solian/models/post.dart';
import 'package:solian/platform.dart';
import 'package:solian/providers/auth.dart';
import 'package:solian/providers/content/posts.dart';
import 'package:solian/router.dart';
import 'package:solian/screens/posts/post_editor.dart';
import 'package:solian/widgets/loading_indicator.dart';
@ -28,20 +29,14 @@ class PostAction extends StatefulWidget {
}
class _PostActionState extends State<PostAction> {
bool _isBusy = true;
bool _isBusy = false;
bool _canModifyContent = false;
void _checkAbleToModifyContent() async {
final AuthProvider auth = Get.find();
if (auth.isAuthorized.isFalse) return;
setState(() => _isBusy = true);
setState(() {
_canModifyContent =
auth.userProfile.value!['id'] == widget.item.author.id;
_isBusy = false;
});
_canModifyContent = auth.userProfile.value!['id'] == widget.item.author.id;
}
Future<void> _doShare({bool noUri = false}) async {
@ -94,6 +89,8 @@ class _PostActionState extends State<PostAction> {
: List.empty();
final hasMultipleAttachment = attachments.length > 1;
setState(() => _isBusy = true);
final screenshot = ScreenshotController();
final image = await screenshot.captureFromLongWidget(
MediaQuery(
@ -137,6 +134,21 @@ class _PostActionState extends State<PostAction> {
);
context.showSnackbar('fileSavedAt'.trParams({'path': filepath}));
}
setState(() => _isBusy = false);
}
Future<Post> _getFullPost() async {
final PostProvider posts = Get.find();
try {
final resp = await posts.getPost(widget.item.id.toString());
return Post.fromJson(resp.body);
} catch (e) {
context.showErrorDialog(e).then((_) => Navigator.pop(context));
}
return widget.item;
}
@override
@ -182,7 +194,13 @@ class _PostActionState extends State<PostAction> {
),
],
).paddingOnly(left: 24, right: 24, top: 32, bottom: 16),
LoadingIndicator(isActive: _isBusy),
LoadingIndicator(
isActive: _isBusy,
backgroundColor: Theme.of(context)
.colorScheme
.surfaceContainerHigh
.withOpacity(0.5),
),
Expanded(
child: ListView(
children: [
@ -205,7 +223,9 @@ class _PostActionState extends State<PostAction> {
IconButton(
icon: const Icon(Icons.image),
tooltip: 'shareImage'.tr,
onPressed: () async {
onPressed: _isBusy
? null
: () async {
await _shareImage();
Navigator.pop(context);
},
@ -288,14 +308,22 @@ class _PostActionState extends State<PostAction> {
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
leading: const Icon(Icons.edit),
title: Text('edit'.tr),
onTap: () async {
onTap: _isBusy
? null
: () async {
setState(() => _isBusy = true);
var item = widget.item;
if (item.body?['content_truncated'] == true) {
item = await _getFullPost();
}
Navigator.pop(
context,
AppRouter.instance.pushNamed(
'postEditor',
extra: PostPublishArguments(edit: widget.item),
extra: PostPublishArguments(edit: item),
),
);
if (mounted) setState(() => _isBusy = false);
},
),
if (_canModifyContent)