Merge branch 'master' into modlog

This commit is contained in:
Marcin Wojnarowski 2021-02-20 17:07:59 +01:00 committed by GitHub
commit 869f674880
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 17 deletions

View File

@ -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(

View File

@ -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<int> communityDropDownItem(CommunityView e) =>
DropdownMenuItem(
value: e.community.id,
child: Text(e.community.local
? e.community.name
: '${e.community.originInstanceHost}/${e.community.name}'),
);
List<DropdownMenuItem<int>> 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(),
),
),
);