Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added spinning indicator when creating or editing posts #934

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 28 additions & 20 deletions lib/community/pages/create_post_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -329,26 +329,34 @@ class _CreatePostPageState extends State<CreatePostPage> {
toolbarHeight: 70.0,
centerTitle: false,
actions: [
IconButton(
onPressed: isSubmitButtonDisabled
? null
: () {
draftPost.saveAsDraft = false;
context.read<CreatePostCubit>().createOrEditPost(
communityId: communityId!,
name: _titleTextController.text,
body: _bodyTextController.text,
nsfw: isNSFW,
url: url,
postIdBeingEdited: widget.postView?.post.id,
languageId: languageId,
);
},
icon: Icon(
widget.postView != null ? Icons.edit_rounded : Icons.send_rounded,
semanticLabel: widget.postView != null ? l10n.editPost : l10n.createPost,
),
),
state.status == CreatePostStatus.submitting
? const Padding(
padding: EdgeInsets.only(right: 20.0),
child: SizedBox(width: 20, height: 20, child: CircularProgressIndicator()),
)
: Padding(
padding: const EdgeInsets.only(right: 8.0),
child: IconButton(
onPressed: isSubmitButtonDisabled
? null
: () {
draftPost.saveAsDraft = false;
context.read<CreatePostCubit>().createOrEditPost(
communityId: communityId!,
name: _titleTextController.text,
body: _bodyTextController.text,
nsfw: isNSFW,
url: url,
postIdBeingEdited: widget.postView?.post.id,
languageId: languageId,
);
},
icon: Icon(
widget.postView != null ? Icons.edit_rounded : Icons.send_rounded,
semanticLabel: widget.postView != null ? l10n.editPost : l10n.createPost,
),
),
),
],
),
body: SafeArea(
Expand Down
2 changes: 1 addition & 1 deletion lib/post/cubit/create_post_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CreatePostCubit extends Cubit<CreatePostState> {

/// Creates or edits a post. When successful, it returns the newly created/updated post in the form of a [PostViewMedia]
Future<void> createOrEditPost({required int communityId, required String name, String? body, String? url, bool? nsfw, int? postIdBeingEdited, int? languageId}) async {
emit(state.copyWith(status: CreatePostStatus.loading));
emit(state.copyWith(status: CreatePostStatus.submitting));

try {
PostView postView = await createPost(
Expand Down
1 change: 1 addition & 0 deletions lib/post/cubit/create_post_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ part of 'create_post_cubit.dart';
enum CreatePostStatus {
initial,
loading,
submitting,
error,
success,
postImageUploadInProgress,
Expand Down
Loading