diff --git a/lib/pages/community.dart b/lib/pages/community.dart index b77749c..f8df039 100644 --- a/lib/pages/community.dart +++ b/lib/pages/community.dart @@ -22,6 +22,7 @@ import '../widgets/info_table_popup.dart'; import '../widgets/markdown_text.dart'; import '../widgets/sortable_infinite_list.dart'; import 'modlog_page.dart'; +import 'create_post.dart'; /// Displays posts, comments, and general info about the given community class CommunityPage extends HookWidget { @@ -138,6 +139,7 @@ class CommunityPage extends HookWidget { } return Scaffold( + floatingActionButton: CreatePostFab(community: community), body: DefaultTabController( length: 3, child: NestedScrollView( diff --git a/lib/pages/create_post.dart b/lib/pages/create_post.dart index cbc494c..09f6eab 100644 --- a/lib/pages/create_post.dart +++ b/lib/pages/create_post.dart @@ -21,7 +21,9 @@ import 'full_post.dart'; /// Fab that triggers the [CreatePost] modal class CreatePostFab extends HookWidget { - const CreatePostFab(); + final CommunityView community; + + const CreatePostFab({this.community}); @override Widget build(BuildContext context) { @@ -29,7 +31,8 @@ class CreatePostFab extends HookWidget { return FloatingActionButton( onPressed: loggedInAction((_) => showCupertinoModalPopup( - context: context, builder: (_) => CreatePostPage())), + context: context, + builder: (_) => CreatePostPage.toCommunity(community))), child: const Icon(Icons.add), ); } @@ -127,6 +130,31 @@ class CreatePostPage extends HookWidget { ), ); + DropdownMenuItem communityDropDownItem(CommunityView e) => + DropdownMenuItem( + value: e.community.id, + child: Text(e.community.local + ? e.community.name + : '${e.community.originInstanceHost}/${e.community.name}'), + ); + + List> communitiesList() { + if (allCommunitiesSnap.hasData) { + return allCommunitiesSnap.data.map(communityDropDownItem).toList(); + } else { + if (selectedCommunity.value != null) { + return [communityDropDownItem(selectedCommunity.value)]; + } else { + return const [ + DropdownMenuItem( + value: -1, + child: CircularProgressIndicator(), + ) + ]; + } + } + } + // TODO: use lazy autocomplete final communitiesDropdown = InputDecorator( decoration: const InputDecoration( @@ -140,21 +168,7 @@ class CreatePostPage extends HookWidget { onChanged: (communityId) => selectedCommunity.value = allCommunitiesSnap.data ?.firstWhere((e) => e.community.id == communityId), - items: allCommunitiesSnap.hasData - ? allCommunitiesSnap.data - .map((e) => DropdownMenuItem( - value: e.community.id, - child: Text(e.community.local - ? e.community.name - : '${e.community.originInstanceHost}/${e.community.name}'), - )) - .toList() - : const [ - DropdownMenuItem( - value: -1, - child: CircularProgressIndicator(), - ) - ], + items: communitiesList(), ), ), );