Skip to content

Commit

Permalink
fixed reporting UI issue
Browse files Browse the repository at this point in the history
  • Loading branch information
clragon committed Dec 14, 2021
1 parent bf966d4 commit 6b80f38
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
9 changes: 9 additions & 0 deletions lib/client/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -727,3 +727,12 @@ Future<bool> validateCall(Future<void> Function() call) async {
return false;
}
}

Future<bool> validateRawCall(Future<void> Function() call) async {
try {
await call();
return true;
} on DioError catch (e) {
return e.response?.statusCode == 302;
}
}
2 changes: 1 addition & 1 deletion lib/ticket/widgets/comment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CommentReportScreen extends StatelessWidget {
Widget build(BuildContext context) {
return ReasonReportScreen(
title: Text('Comment #${comment.id}'),
onReport: (reason) => validateCall(
onReport: (reason) => validateRawCall(
() => client.reportComment(
comment.id,
reason,
Expand Down
18 changes: 10 additions & 8 deletions lib/ticket/widgets/post.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,20 @@ class _PostReportScreenState extends State<PostReportScreen> {
duration: defaultAnimationDuration,
curve: Curves.easeInOut,
);
try {
await client.reportPost(
if (await validateRawCall(
() => client.reportPost(
widget.post.id,
reportIds[type!]!,
reasonController.text.trim(),
);
),
)) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
duration: Duration(seconds: 1),
content: Text('Reported post #${widget.post.id}'),
behavior: SnackBarBehavior.floating,
));
Navigator.maybePop(context);
} on DioError {
} else {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
duration: Duration(seconds: 1),
content:
Expand Down Expand Up @@ -200,19 +201,20 @@ class _PostFlagScreenState extends State<PostFlagScreen> {
duration: defaultAnimationDuration,
curve: Curves.easeInOut,
);
try {
await client.flagPost(
if (await validateRawCall(
() => client.flagPost(
widget.post.id,
flagName[type]!,
parent: int.tryParse(parentController.text),
);
),
)) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
duration: Duration(seconds: 1),
content: Text('Flagged post #${widget.post.id}'),
behavior: SnackBarBehavior.floating,
));
Navigator.maybePop(context);
} on DioError {
} else {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
duration: Duration(seconds: 1),
content:
Expand Down
2 changes: 1 addition & 1 deletion lib/ticket/widgets/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class UserReportScreen extends StatelessWidget {
Widget build(BuildContext context) {
return ReasonReportScreen(
title: Text('User #${user.id}'),
onReport: (reason) => validateCall(
onReport: (reason) => validateRawCall(
() => client.reportUser(
user.id,
reason,
Expand Down

0 comments on commit 6b80f38

Please sign in to comment.