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