small fixes & tweaks
* commenting uses mobx instead of hooks * SavePostButton works with fullPost * `is AsyncStateX` -> .errorTerm & .isLoading * save post button better looking spinner
This commit is contained in:
parent
a78edcd54b
commit
399c0bdb83
|
@ -8,7 +8,6 @@ import 'package:lemmy_api_client/v3.dart';
|
|||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../hooks/logged_in_action.dart';
|
||||
import '../../util/async_store.dart';
|
||||
import '../../util/async_store_listener.dart';
|
||||
import '../../util/extensions/api.dart';
|
||||
import '../../util/icons.dart';
|
||||
|
@ -20,6 +19,7 @@ import '../../widgets/post/full_post_store.dart';
|
|||
import '../../widgets/post/post.dart';
|
||||
import '../../widgets/post/post_more_menu.dart';
|
||||
import '../../widgets/post/post_store.dart';
|
||||
import '../../widgets/post/save_post_button.dart';
|
||||
import '../../widgets/reveal_after_scroll.dart';
|
||||
import '../../widgets/write_comment.dart';
|
||||
|
||||
|
@ -57,7 +57,6 @@ class _FullPostPage extends HookWidget {
|
|||
|
||||
final loggedInAction = useLoggedInAction(
|
||||
context.select<FullPostStore, String>((store) => store.instanceHost));
|
||||
final newComments = useState(const <CommentView>[]);
|
||||
|
||||
return ObserverBuilder<FullPostStore>(
|
||||
builder: (context, store) {
|
||||
|
@ -97,8 +96,9 @@ class _FullPostPage extends HookWidget {
|
|||
context: context,
|
||||
builder: (_) => WriteComment.toPost(post.post),
|
||||
);
|
||||
|
||||
if (newComment != null) {
|
||||
newComments.value = [...newComments.value, newComment];
|
||||
store.addComment(newComment);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -115,7 +115,10 @@ class _FullPostPage extends HookWidget {
|
|||
),
|
||||
actions: [
|
||||
IconButton(icon: const Icon(Icons.share), onPressed: sharePost),
|
||||
// const SavePostButton(),
|
||||
Provider<PostStore>(
|
||||
create: (context) => store.postStore!,
|
||||
child: const SavePostButton(),
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(moreIcon),
|
||||
onPressed: () => showPostMoreMenu(
|
||||
|
@ -160,7 +163,7 @@ class _Comments extends StatelessWidget {
|
|||
if (fullPost != null) {
|
||||
return CommentSection(store.comments!,
|
||||
postCreatorId: fullPost.postView.creator.id);
|
||||
} else if (store.fullPostState is AsyncStateError) {
|
||||
} else if (store.fullPostState.errorTerm != null) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 30),
|
||||
child: Column(
|
||||
|
|
|
@ -5,7 +5,6 @@ import 'package:provider/provider.dart';
|
|||
|
||||
import '../../hooks/logged_in_action.dart';
|
||||
import '../../hooks/stores.dart';
|
||||
import '../../util/async_store.dart';
|
||||
import '../../util/intl.dart';
|
||||
import '../../util/observer_consumers.dart';
|
||||
import 'post_store.dart';
|
||||
|
@ -33,7 +32,7 @@ class PostVoting extends HookWidget {
|
|||
),
|
||||
onPressed: loggedInAction(store.upVote),
|
||||
),
|
||||
if (store.votingState is AsyncStateLoading)
|
||||
if (store.votingState.isLoading)
|
||||
const SizedBox(
|
||||
width: 20, height: 20, child: CircularProgressIndicator())
|
||||
else if (showScores)
|
||||
|
|
|
@ -3,7 +3,6 @@ import 'package:flutter_hooks/flutter_hooks.dart';
|
|||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../hooks/logged_in_action.dart';
|
||||
import '../../util/async_store.dart';
|
||||
import '../../util/observer_consumers.dart';
|
||||
import 'post_store.dart';
|
||||
|
||||
|
@ -19,25 +18,14 @@ class SavePostButton extends HookWidget {
|
|||
|
||||
return ObserverBuilder<PostStore>(
|
||||
builder: (context, store) {
|
||||
if (store.savingState is AsyncStateLoading) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 5),
|
||||
child: SizedBox(
|
||||
width: 30,
|
||||
height: 30,
|
||||
child: CircularProgressIndicator(
|
||||
backgroundColor: Theme.of(context).iconTheme.color,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
final savedIcon =
|
||||
store.postView.saved ? Icons.bookmark : Icons.bookmark_border;
|
||||
|
||||
return IconButton(
|
||||
tooltip: 'Save post',
|
||||
icon: Icon(savedIcon),
|
||||
icon: store.savingState.isLoading
|
||||
? const CircularProgressIndicator.adaptive()
|
||||
: Icon(savedIcon),
|
||||
onPressed: loggedInAction(store.save),
|
||||
);
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue