From 7fbd3decf9bd04566af6e0c9647eba05910ca47a Mon Sep 17 00:00:00 2001 From: Hamlet Jiang Su Date: Thu, 30 Nov 2023 09:02:36 -0800 Subject: [PATCH] added spinning indicator when creating or editing posts --- lib/community/pages/create_post_page.dart | 48 +++++++++++++---------- lib/post/cubit/create_post_cubit.dart | 2 +- lib/post/cubit/create_post_state.dart | 1 + 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/lib/community/pages/create_post_page.dart b/lib/community/pages/create_post_page.dart index ac30f886c..b30de6710 100644 --- a/lib/community/pages/create_post_page.dart +++ b/lib/community/pages/create_post_page.dart @@ -329,26 +329,34 @@ class _CreatePostPageState extends State { toolbarHeight: 70.0, centerTitle: false, actions: [ - IconButton( - onPressed: isSubmitButtonDisabled - ? null - : () { - draftPost.saveAsDraft = false; - context.read().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().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( diff --git a/lib/post/cubit/create_post_cubit.dart b/lib/post/cubit/create_post_cubit.dart index 241ec74ae..45f12933c 100644 --- a/lib/post/cubit/create_post_cubit.dart +++ b/lib/post/cubit/create_post_cubit.dart @@ -40,7 +40,7 @@ class CreatePostCubit extends Cubit { /// Creates or edits a post. When successful, it returns the newly created/updated post in the form of a [PostViewMedia] Future 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( diff --git a/lib/post/cubit/create_post_state.dart b/lib/post/cubit/create_post_state.dart index 3d3dcaace..8efb8e6e7 100644 --- a/lib/post/cubit/create_post_state.dart +++ b/lib/post/cubit/create_post_state.dart @@ -3,6 +3,7 @@ part of 'create_post_cubit.dart'; enum CreatePostStatus { initial, loading, + submitting, error, success, postImageUploadInProgress,