Skip to content

Commit

Permalink
Prevent opening create post page when not logged in
Browse files Browse the repository at this point in the history
  • Loading branch information
coslu committed Aug 15, 2023
1 parent 63ff08a commit 716f8fe
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 45 deletions.
14 changes: 8 additions & 6 deletions lib/community/pages/create_post_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,17 @@ class _CreatePostPageState extends State<CreatePostPage> {
uploadImage(imageBloc, postImage: true);
}
},
icon: postImageUploading ? const SizedBox(
width: 20,
height: 20,
child: Center(
child: SizedBox(
icon: postImageUploading
? const SizedBox(
width: 20,
height: 20,
child: Center(
child: SizedBox(
width: 18,
height: 18,
child: CircularProgressIndicator(),
))) : Icon(Icons.image, semanticLabel: AppLocalizations.of(context)!.uploadImage))),
)))
: Icon(Icons.image, semanticLabel: AppLocalizations.of(context)!.uploadImage))),
),
const SizedBox(
height: 10,
Expand Down
37 changes: 21 additions & 16 deletions lib/core/enums/fab_action.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:thunder/community/bloc/community_bloc.dart';
import 'package:thunder/community/pages/community_page.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:thunder/community/pages/create_post_page.dart';
import 'package:thunder/core/auth/bloc/auth_bloc.dart';
import 'package:thunder/thunder/bloc/thunder_bloc.dart';

enum FeedFabAction {
Expand Down Expand Up @@ -109,22 +110,26 @@ enum FeedFabAction {
context.read<ThunderBloc>().add(const OnDismissEvent(true));
case FeedFabAction.newPost:
if (bloc != null) {
ThunderBloc thunderBloc = context.read<ThunderBloc>();
AccountBloc accountBloc = context.read<AccountBloc>();
Navigator.of(context).push(
SwipeablePageRoute(
builder: (context) {
return MultiBlocProvider(
providers: [
BlocProvider<CommunityBloc>.value(value: bloc),
BlocProvider<ThunderBloc>.value(value: thunderBloc),
BlocProvider<AccountBloc>.value(value: accountBloc),
],
child: CreatePostPage(communityId: state.communityId!, communityInfo: state.communityInfo),
);
},
),
);
if (!context.read<AuthBloc>().state.isLoggedIn) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(AppLocalizations.of(context)!.mustBeLoggedInPost)));
} else {
ThunderBloc thunderBloc = context.read<ThunderBloc>();
AccountBloc accountBloc = context.read<AccountBloc>();
Navigator.of(context).push(
SwipeablePageRoute(
builder: (context) {
return MultiBlocProvider(
providers: [
BlocProvider<CommunityBloc>.value(value: bloc),
BlocProvider<ThunderBloc>.value(value: thunderBloc),
BlocProvider<AccountBloc>.value(value: accountBloc),
],
child: CreatePostPage(communityId: state.communityId!, communityInfo: state.communityInfo),
);
},
),
);
}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,7 @@
"replyingTo": "Replying to {author}",
"unexpectedError": "Unexpected Error",
"fetchAccountError": "Could not determine account",
"retry": "Retry"
"retry": "Retry",
"mustBeLoggedInPost": "You need to be logged in to create a post",
"mustBeLoggedInComment": "You need to be logged in to comment"
}
4 changes: 3 additions & 1 deletion lib/l10n/app_es.arb
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,7 @@
"replyingTo": "Replying to {author}",
"unexpectedError": "Unexpected Error",
"fetchAccountError": "Could not determine account",
"retry": "Retry"
"retry": "Retry",
"mustBeLoggedInPost": "You need to be logged in to create a post",
"mustBeLoggedInComment": "You need to be logged in to comment"
}
4 changes: 3 additions & 1 deletion lib/l10n/app_fi.arb
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,7 @@
"replyingTo": "Replying to {author}",
"unexpectedError": "Unexpected Error",
"fetchAccountError": "Could not determine account",
"retry": "Retry"
"retry": "Retry",
"mustBeLoggedInPost": "You need to be logged in to create a post",
"mustBeLoggedInComment": "You need to be logged in to comment"
}
4 changes: 3 additions & 1 deletion lib/l10n/app_sv.arb
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,7 @@
"replyingTo": "Replying to {author}",
"unexpectedError": "Unexpected Error",
"fetchAccountError": "Could not determine account",
"retry": "Retry"
"retry": "Retry",
"mustBeLoggedInPost": "You need to be logged in to create a post",
"mustBeLoggedInComment": "You need to be logged in to comment"
}
16 changes: 6 additions & 10 deletions lib/post/pages/post_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -426,20 +426,16 @@ class _PostPageState extends State<PostPage> {
AccountBloc accountBloc = context.read<AccountBloc>();

if (!authBloc.state.isLoggedIn) {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text("Not logged in")));
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(AppLocalizations.of(context)!.mustBeLoggedInComment)));
} else {
Navigator.of(context).push(
SwipeablePageRoute(
builder: (context) {
return MultiBlocProvider(
providers: [
BlocProvider<PostBloc>.value(value: postBloc),
BlocProvider<ThunderBloc>.value(value: thunderBloc),
BlocProvider<AccountBloc>.value(value: accountBloc),
],
child: CreateCommentPage(
postView: widget.postView
));
return MultiBlocProvider(providers: [
BlocProvider<PostBloc>.value(value: postBloc),
BlocProvider<ThunderBloc>.value(value: thunderBloc),
BlocProvider<AccountBloc>.value(value: accountBloc),
], child: CreateCommentPage(postView: widget.postView));
},
),
);
Expand Down
23 changes: 14 additions & 9 deletions lib/user/widgets/user_indicator.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
Expand All @@ -19,7 +18,6 @@ class _UserIndicatorState extends State<UserIndicator> {
bool accountError = false;
PersonSafe? person;


@override
void initState() {
super.initState();
Expand All @@ -38,15 +36,21 @@ class _UserIndicatorState extends State<UserIndicator> {
setState(() => accountError = true);
}
},
child: SizedBox(height: 40,
child: SizedBox(
height: 40,
child: accountError
? Row(crossAxisAlignment: CrossAxisAlignment.center,
? Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Icon(Icons.warning_rounded),
const SizedBox(
width: 8.0,
),
Expanded(child: Text(AppLocalizations.of(context)!.fetchAccountError,overflow: TextOverflow.ellipsis,)),
Expanded(
child: Text(
AppLocalizations.of(context)!.fetchAccountError,
overflow: TextOverflow.ellipsis,
)),
TextButton.icon(
onPressed: () {
context.read<AccountBloc>().add(GetAccountInformation());
Expand All @@ -60,10 +64,11 @@ class _UserIndicatorState extends State<UserIndicator> {
? Row(
children: [
CircleAvatar(
foregroundImage: person!.avatar != null ? CachedNetworkImageProvider(person!.avatar!, errorListener: () {
setState (() => accountError = true);
print("Error");
}) : null,
foregroundImage: person!.avatar != null
? CachedNetworkImageProvider(person!.avatar!, errorListener: () {
setState(() => accountError = true);
})
: null,
maxRadius: 16,
),
const SizedBox(
Expand Down

0 comments on commit 716f8fe

Please sign in to comment.