From 02c28533dbc08d07b1fb527a1abcedf0a8cece9f Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Thu, 25 Jul 2024 01:43:50 +0800 Subject: [PATCH] :lipstick: Optimized post create popup --- lib/providers/content/posts.dart | 2 +- lib/screens/feed/draft_box.dart | 5 -- lib/screens/home.dart | 111 ++++++++++++++++++++----------- 3 files changed, 73 insertions(+), 45 deletions(-) diff --git a/lib/providers/content/posts.dart b/lib/providers/content/posts.dart index d177db9..cd8f99a 100644 --- a/lib/providers/content/posts.dart +++ b/lib/providers/content/posts.dart @@ -34,7 +34,7 @@ class PostProvider extends GetConnect { 'offset=$page', ]; final client = auth.configureClient('interactive'); - final resp = await client.get('/drafts?${queries.join('&')}'); + final resp = await client.get('/posts/drafts?${queries.join('&')}'); if (resp.statusCode != 200) { throw Exception(resp.body); } diff --git a/lib/screens/feed/draft_box.dart b/lib/screens/feed/draft_box.dart index 0738378..b8c7081 100644 --- a/lib/screens/feed/draft_box.dart +++ b/lib/screens/feed/draft_box.dart @@ -4,7 +4,6 @@ import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart'; import 'package:solian/models/pagination.dart'; import 'package:solian/models/post.dart'; import 'package:solian/providers/content/posts.dart'; -import 'package:solian/screens/home.dart'; import 'package:solian/theme.dart'; import 'package:solian/widgets/app_bar_leading.dart'; import 'package:solian/widgets/app_bar_title.dart'; @@ -64,10 +63,6 @@ class _DraftBoxScreenState extends State { centerTitle: false, toolbarHeight: SolianTheme.toolbarHeight(context), actions: [ - FeedCreationButton( - hideDraftBox: true, - onCreated: () {}, - ), SizedBox( width: SolianTheme.isLargeScreen(context) ? 8 : 16, ), diff --git a/lib/screens/home.dart b/lib/screens/home.dart index ce9b86b..68c045c 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -52,10 +52,21 @@ class _HomeScreenState extends State { @override Widget build(BuildContext context) { - return Scaffold( - body: Material( - color: Theme.of(context).colorScheme.surface, - child: RefreshIndicator( + return Material( + color: Theme.of(context).colorScheme.surface, + child: Scaffold( + floatingActionButton: FloatingActionButton( + child: const Icon(Icons.add), + onPressed: () { + showModalBottomSheet( + useRootNavigator: true, + isScrollControlled: true, + context: context, + builder: (context) => const PostCreatePopup(), + ); + }, + ), + body: RefreshIndicator( onRefresh: () => Future.sync(() => _pagingController.refresh()), child: CustomScrollView( slivers: [ @@ -68,11 +79,6 @@ class _HomeScreenState extends State { actions: [ const BackgroundStateWidget(), const NotificationButton(), - FeedCreationButton( - onCreated: () { - _pagingController.refresh(); - }, - ), SizedBox( width: SolianTheme.isLargeScreen(context) ? 8 : 16, ), @@ -93,11 +99,11 @@ class _HomeScreenState extends State { } } -class FeedCreationButton extends StatelessWidget { +class PostCreatePopup extends StatelessWidget { final bool hideDraftBox; final Function? onCreated; - const FeedCreationButton({ + const PostCreatePopup({ super.key, this.hideDraftBox = false, this.onCreated, @@ -111,35 +117,62 @@ class FeedCreationButton extends StatelessWidget { return const SizedBox(); } - return PopupMenuButton( - icon: const Icon(Icons.edit_square), - itemBuilder: (BuildContext context) => [ - PopupMenuItem( - child: ListTile( - title: Text('postEditor'.tr), - leading: const Icon(Icons.article), - contentPadding: const EdgeInsets.symmetric(horizontal: 8), + final List actionList = [ + ( + icon: const Icon(Icons.edit_square), + label: 'postEditor'.tr, + onTap: () { + Navigator.pop(context); + AppRouter.instance.pushNamed('postEditor').then((val) { + if (val != null && onCreated != null) onCreated!(); + }); + }, + ), + ( + icon: const Icon(Icons.drafts), + label: 'draftBoxOpen'.tr, + onTap: () { + Navigator.pop(context); + AppRouter.instance.pushNamed('draftBox'); + }, + ), + ]; + + return SizedBox( + height: MediaQuery.of(context).size.height * 0.35, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + 'postNew'.tr, + style: Theme.of(context).textTheme.headlineSmall, + ).paddingOnly(left: 24, right: 24, top: 32, bottom: 16), + Expanded( + child: GridView.count( + physics: const NeverScrollableScrollPhysics(), + crossAxisCount: 3, + children: actionList + .map((x) => Card( + color: Theme.of(context).colorScheme.surfaceContainer, + child: InkWell( + borderRadius: + const BorderRadius.all(Radius.circular(8)), + onTap: x.onTap, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + x.icon, + const SizedBox(height: 8), + Text(x.label), + ], + ).paddingAll(18), + ), + )) + .toList(), + ).paddingSymmetric(horizontal: 20), ), - onTap: () { - AppRouter.instance.pushNamed('postEditor').then((val) { - if (val != null && onCreated != null) { - onCreated!(); - } - }); - }, - ), - if (!hideDraftBox) - PopupMenuItem( - child: ListTile( - title: Text('draftBoxOpen'.tr), - leading: const Icon(Icons.drafts), - contentPadding: const EdgeInsets.symmetric(horizontal: 8), - ), - onTap: () { - AppRouter.instance.pushNamed('draftBox'); - }, - ), - ], + ], + ), ); } }