🐛 Bug fixes on edit content truncated post
This commit is contained in:
parent
063c087089
commit
59c4d667f6
@ -4,8 +4,13 @@ import 'package:gap/gap.dart';
|
|||||||
|
|
||||||
class LoadingIndicator extends StatefulWidget {
|
class LoadingIndicator extends StatefulWidget {
|
||||||
final bool isActive;
|
final bool isActive;
|
||||||
|
final Color? backgroundColor;
|
||||||
|
|
||||||
const LoadingIndicator({super.key, this.isActive = true});
|
const LoadingIndicator({
|
||||||
|
super.key,
|
||||||
|
this.isActive = true,
|
||||||
|
this.backgroundColor,
|
||||||
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<LoadingIndicator> createState() => _LoadingIndicatorState();
|
State<LoadingIndicator> createState() => _LoadingIndicatorState();
|
||||||
@ -63,7 +68,7 @@ class _LoadingIndicatorState extends State<LoadingIndicator>
|
|||||||
axisAlignment: -1, // Align animation from the top
|
axisAlignment: -1, // Align animation from the top
|
||||||
child: Container(
|
child: Container(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 24),
|
padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 24),
|
||||||
color:
|
color: widget.backgroundColor ??
|
||||||
Theme.of(context).colorScheme.surfaceContainerLow.withOpacity(0.5),
|
Theme.of(context).colorScheme.surfaceContainerLow.withOpacity(0.5),
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
@ -11,6 +11,7 @@ import 'package:solian/exts.dart';
|
|||||||
import 'package:solian/models/post.dart';
|
import 'package:solian/models/post.dart';
|
||||||
import 'package:solian/platform.dart';
|
import 'package:solian/platform.dart';
|
||||||
import 'package:solian/providers/auth.dart';
|
import 'package:solian/providers/auth.dart';
|
||||||
|
import 'package:solian/providers/content/posts.dart';
|
||||||
import 'package:solian/router.dart';
|
import 'package:solian/router.dart';
|
||||||
import 'package:solian/screens/posts/post_editor.dart';
|
import 'package:solian/screens/posts/post_editor.dart';
|
||||||
import 'package:solian/widgets/loading_indicator.dart';
|
import 'package:solian/widgets/loading_indicator.dart';
|
||||||
@ -28,20 +29,14 @@ class PostAction extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _PostActionState extends State<PostAction> {
|
class _PostActionState extends State<PostAction> {
|
||||||
bool _isBusy = true;
|
bool _isBusy = false;
|
||||||
bool _canModifyContent = false;
|
bool _canModifyContent = false;
|
||||||
|
|
||||||
void _checkAbleToModifyContent() async {
|
void _checkAbleToModifyContent() async {
|
||||||
final AuthProvider auth = Get.find();
|
final AuthProvider auth = Get.find();
|
||||||
if (auth.isAuthorized.isFalse) return;
|
if (auth.isAuthorized.isFalse) return;
|
||||||
|
|
||||||
setState(() => _isBusy = true);
|
_canModifyContent = auth.userProfile.value!['id'] == widget.item.author.id;
|
||||||
|
|
||||||
setState(() {
|
|
||||||
_canModifyContent =
|
|
||||||
auth.userProfile.value!['id'] == widget.item.author.id;
|
|
||||||
_isBusy = false;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _doShare({bool noUri = false}) async {
|
Future<void> _doShare({bool noUri = false}) async {
|
||||||
@ -94,6 +89,8 @@ class _PostActionState extends State<PostAction> {
|
|||||||
: List.empty();
|
: List.empty();
|
||||||
final hasMultipleAttachment = attachments.length > 1;
|
final hasMultipleAttachment = attachments.length > 1;
|
||||||
|
|
||||||
|
setState(() => _isBusy = true);
|
||||||
|
|
||||||
final screenshot = ScreenshotController();
|
final screenshot = ScreenshotController();
|
||||||
final image = await screenshot.captureFromLongWidget(
|
final image = await screenshot.captureFromLongWidget(
|
||||||
MediaQuery(
|
MediaQuery(
|
||||||
@ -137,6 +134,21 @@ class _PostActionState extends State<PostAction> {
|
|||||||
);
|
);
|
||||||
context.showSnackbar('fileSavedAt'.trParams({'path': filepath}));
|
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
|
@override
|
||||||
@ -182,7 +194,13 @@ class _PostActionState extends State<PostAction> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
).paddingOnly(left: 24, right: 24, top: 32, bottom: 16),
|
).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(
|
Expanded(
|
||||||
child: ListView(
|
child: ListView(
|
||||||
children: [
|
children: [
|
||||||
@ -205,7 +223,9 @@ class _PostActionState extends State<PostAction> {
|
|||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.image),
|
icon: const Icon(Icons.image),
|
||||||
tooltip: 'shareImage'.tr,
|
tooltip: 'shareImage'.tr,
|
||||||
onPressed: () async {
|
onPressed: _isBusy
|
||||||
|
? null
|
||||||
|
: () async {
|
||||||
await _shareImage();
|
await _shareImage();
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
},
|
},
|
||||||
@ -288,14 +308,22 @@ class _PostActionState extends State<PostAction> {
|
|||||||
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
||||||
leading: const Icon(Icons.edit),
|
leading: const Icon(Icons.edit),
|
||||||
title: Text('edit'.tr),
|
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(
|
Navigator.pop(
|
||||||
context,
|
context,
|
||||||
AppRouter.instance.pushNamed(
|
AppRouter.instance.pushNamed(
|
||||||
'postEditor',
|
'postEditor',
|
||||||
extra: PostPublishArguments(edit: widget.item),
|
extra: PostPublishArguments(edit: item),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
if (mounted) setState(() => _isBusy = false);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
if (_canModifyContent)
|
if (_canModifyContent)
|
||||||
|
Loading…
Reference in New Issue
Block a user