fix: add post deletion in the timeline userstory

This commit is contained in:
Freek van de Ven 2024-05-23 11:54:43 +02:00
parent 25264ba44b
commit 013e82e61d
4 changed files with 18 additions and 43 deletions

View file

@ -15,6 +15,7 @@
- fix the avatar size to match the new design
- Add the iconbutton for image uploading back to the ReactionBottom
- Fix category key is correctly used for saving timeline posts and category title is shown everywhere
- Fix when clicking on post delete in the post screen of the userstory it will now navigate back to the timeline and delete the post
## 3.0.1

View file

@ -154,7 +154,13 @@ List<GoRoute> getTimelineStoryRoutes({
options: config.optionsBuilder(context),
service: service,
post: post!,
onPostDelete: () => config.onPostDelete?.call(context, post),
onPostDelete: () async =>
config.onPostDelete?.call(context, post) ??
() async {
await service.postService.deletePost(post);
if (!context.mounted) return;
context.go(TimelineUserStoryRoutes.timelineHome);
}.call(),
onUserTap: (user) => config.onUserTap?.call(context, user),
);

View file

@ -132,7 +132,12 @@ Widget _postDetailScreenRoute({
post: post,
onPostDelete: () async =>
config.onPostDelete?.call(context, post) ??
await config.service.postService.deletePost(post),
() async {
await config.service.postService.deletePost(post);
if (context.mounted) {
Navigator.of(context).pop();
}
}.call(),
onUserTap: (user) => config.onUserTap?.call(context, user),
);

View file

@ -15,7 +15,7 @@ import 'package:flutter_timeline_view/src/widgets/reaction_bottom.dart';
import 'package:flutter_timeline_view/src/widgets/tappable_image.dart';
import 'package:intl/intl.dart';
class TimelinePostScreen extends StatelessWidget {
class TimelinePostScreen extends StatefulWidget {
const TimelinePostScreen({
required this.userId,
required this.service,
@ -47,47 +47,10 @@ class TimelinePostScreen extends StatelessWidget {
final bool? isOverviewScreen;
@override
Widget build(BuildContext context) => _TimelinePostScreen(
userId: userId,
service: service,
options: options,
post: post,
onPostDelete: onPostDelete,
onUserTap: onUserTap,
isOverviewScreen: isOverviewScreen,
);
State<TimelinePostScreen> createState() => _TimelinePostScreenState();
}
class _TimelinePostScreen extends StatefulWidget {
const _TimelinePostScreen({
required this.userId,
required this.service,
required this.options,
required this.post,
required this.onPostDelete,
this.onUserTap,
this.isOverviewScreen,
});
final String userId;
final TimelineService service;
final TimelineOptions options;
final TimelinePost post;
final Function(String userId)? onUserTap;
final VoidCallback onPostDelete;
final bool? isOverviewScreen;
@override
State<_TimelinePostScreen> createState() => _TimelinePostScreenState();
}
class _TimelinePostScreenState extends State<_TimelinePostScreen> {
class _TimelinePostScreenState extends State<TimelinePostScreen> {
TimelinePost? post;
bool isLoading = true;
@ -231,7 +194,7 @@ class _TimelinePostScreenState extends State<_TimelinePostScreen> {
if (widget.options.allowAllDeletion ||
post.creator?.userId == widget.userId)
PopupMenuButton(
onSelected: (value) => widget.onPostDelete(),
onSelected: (value) => widget.onPostDelete.call(),
itemBuilder: (BuildContext context) =>
<PopupMenuEntry<String>>[
PopupMenuItem<String>(