Compare commits
No commits in common. "fa3ba0e18873df055c33fa65eea8b8f6f4904d34" and "6d92a16a626a6e0f29d81c6992c3432ff3f27535" have entirely different histories.
fa3ba0e188
...
6d92a16a62
@ -9,7 +9,7 @@ class PostProvider extends GetConnect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<Response> listRecommendations(int page,
|
Future<Response> listRecommendations(int page,
|
||||||
{int? realm, String? tag, category, String? channel}) async {
|
{int? realm, String? tag, category}) async {
|
||||||
final queries = [
|
final queries = [
|
||||||
'take=${10}',
|
'take=${10}',
|
||||||
'offset=$page',
|
'offset=$page',
|
||||||
@ -17,11 +17,7 @@ class PostProvider extends GetConnect {
|
|||||||
if (category != null) 'category=$category',
|
if (category != null) 'category=$category',
|
||||||
if (realm != null) 'realmId=$realm',
|
if (realm != null) 'realmId=$realm',
|
||||||
];
|
];
|
||||||
final resp = await get(
|
final resp = await get('/recommendations?${queries.join('&')}');
|
||||||
channel == null
|
|
||||||
? '/recommendations?${queries.join('&')}'
|
|
||||||
: '/recommendations/$channel?${queries.join('&')}',
|
|
||||||
);
|
|
||||||
if (resp.statusCode != 200) {
|
if (resp.statusCode != 200) {
|
||||||
throw Exception(resp.body);
|
throw Exception(resp.body);
|
||||||
}
|
}
|
||||||
@ -38,7 +34,7 @@ class PostProvider extends GetConnect {
|
|||||||
'offset=$page',
|
'offset=$page',
|
||||||
];
|
];
|
||||||
final client = auth.configureClient('interactive');
|
final client = auth.configureClient('interactive');
|
||||||
final resp = await client.get('/posts/drafts?${queries.join('&')}');
|
final resp = await client.get('/drafts?${queries.join('&')}');
|
||||||
if (resp.statusCode != 200) {
|
if (resp.statusCode != 200) {
|
||||||
throw Exception(resp.body);
|
throw Exception(resp.body);
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
|
|||||||
import 'package:solian/models/pagination.dart';
|
import 'package:solian/models/pagination.dart';
|
||||||
import 'package:solian/models/post.dart';
|
import 'package:solian/models/post.dart';
|
||||||
import 'package:solian/providers/content/posts.dart';
|
import 'package:solian/providers/content/posts.dart';
|
||||||
|
import 'package:solian/screens/home.dart';
|
||||||
import 'package:solian/theme.dart';
|
import 'package:solian/theme.dart';
|
||||||
import 'package:solian/widgets/app_bar_leading.dart';
|
import 'package:solian/widgets/app_bar_leading.dart';
|
||||||
import 'package:solian/widgets/app_bar_title.dart';
|
import 'package:solian/widgets/app_bar_title.dart';
|
||||||
@ -63,6 +64,10 @@ class _DraftBoxScreenState extends State<DraftBoxScreen> {
|
|||||||
centerTitle: false,
|
centerTitle: false,
|
||||||
toolbarHeight: SolianTheme.toolbarHeight(context),
|
toolbarHeight: SolianTheme.toolbarHeight(context),
|
||||||
actions: [
|
actions: [
|
||||||
|
FeedCreationButton(
|
||||||
|
hideDraftBox: true,
|
||||||
|
onCreated: () {},
|
||||||
|
),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
width: SolianTheme.isLargeScreen(context) ? 8 : 16,
|
width: SolianTheme.isLargeScreen(context) ? 8 : 16,
|
||||||
),
|
),
|
||||||
|
@ -20,24 +20,16 @@ class HomeScreen extends StatefulWidget {
|
|||||||
State<HomeScreen> createState() => _HomeScreenState();
|
State<HomeScreen> createState() => _HomeScreenState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _HomeScreenState extends State<HomeScreen>
|
class _HomeScreenState extends State<HomeScreen> {
|
||||||
with SingleTickerProviderStateMixin {
|
|
||||||
final PagingController<int, Post> _pagingController =
|
final PagingController<int, Post> _pagingController =
|
||||||
PagingController(firstPageKey: 0);
|
PagingController(firstPageKey: 0);
|
||||||
|
|
||||||
late final TabController _tabController;
|
|
||||||
|
|
||||||
int mode = 0;
|
|
||||||
|
|
||||||
getPosts(int pageKey) async {
|
getPosts(int pageKey) async {
|
||||||
final PostProvider provider = Get.find();
|
final PostProvider provider = Get.find();
|
||||||
|
|
||||||
Response resp;
|
Response resp;
|
||||||
try {
|
try {
|
||||||
resp = await provider.listRecommendations(
|
resp = await provider.listRecommendations(pageKey);
|
||||||
pageKey,
|
|
||||||
channel: mode == 0 ? null : 'shuffle',
|
|
||||||
);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_pagingController.error = e;
|
_pagingController.error = e;
|
||||||
return;
|
return;
|
||||||
@ -56,40 +48,17 @@ class _HomeScreenState extends State<HomeScreen>
|
|||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_pagingController.addPageRequestListener(getPosts);
|
_pagingController.addPageRequestListener(getPosts);
|
||||||
_tabController = TabController(length: 2, vsync: this);
|
|
||||||
_tabController.addListener(() {
|
|
||||||
switch (_tabController.index) {
|
|
||||||
case 0:
|
|
||||||
case 1:
|
|
||||||
if (mode == _tabController.index) break;
|
|
||||||
mode = _tabController.index;
|
|
||||||
_pagingController.refresh();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Material(
|
return Scaffold(
|
||||||
|
body: Material(
|
||||||
color: Theme.of(context).colorScheme.surface,
|
color: Theme.of(context).colorScheme.surface,
|
||||||
child: Scaffold(
|
child: RefreshIndicator(
|
||||||
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()),
|
onRefresh: () => Future.sync(() => _pagingController.refresh()),
|
||||||
child: NestedScrollView(
|
child: CustomScrollView(
|
||||||
headerSliverBuilder:
|
slivers: [
|
||||||
(BuildContext context, bool innerBoxIsScrolled) {
|
|
||||||
return [
|
|
||||||
SliverAppBar(
|
SliverAppBar(
|
||||||
title: AppBarTitle('home'.tr),
|
title: AppBarTitle('home'.tr),
|
||||||
centerTitle: false,
|
centerTitle: false,
|
||||||
@ -99,34 +68,21 @@ class _HomeScreenState extends State<HomeScreen>
|
|||||||
actions: [
|
actions: [
|
||||||
const BackgroundStateWidget(),
|
const BackgroundStateWidget(),
|
||||||
const NotificationButton(),
|
const NotificationButton(),
|
||||||
|
FeedCreationButton(
|
||||||
|
onCreated: () {
|
||||||
|
_pagingController.refresh();
|
||||||
|
},
|
||||||
|
),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
width: SolianTheme.isLargeScreen(context) ? 8 : 16,
|
width: SolianTheme.isLargeScreen(context) ? 8 : 16,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
bottom: TabBar(
|
|
||||||
controller: _tabController,
|
|
||||||
tabs: [
|
|
||||||
Tab(text: 'postListNews'.tr),
|
|
||||||
Tab(text: 'postListShuffle'.tr),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
)
|
|
||||||
];
|
|
||||||
},
|
|
||||||
body: TabBarView(
|
|
||||||
controller: _tabController,
|
|
||||||
children: [
|
|
||||||
CustomScrollView(slivers: [
|
|
||||||
FeedListWidget(controller: _pagingController),
|
FeedListWidget(controller: _pagingController),
|
||||||
]),
|
|
||||||
CustomScrollView(slivers: [
|
|
||||||
FeedListWidget(controller: _pagingController),
|
|
||||||
]),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,11 +93,11 @@ class _HomeScreenState extends State<HomeScreen>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PostCreatePopup extends StatelessWidget {
|
class FeedCreationButton extends StatelessWidget {
|
||||||
final bool hideDraftBox;
|
final bool hideDraftBox;
|
||||||
final Function? onCreated;
|
final Function? onCreated;
|
||||||
|
|
||||||
const PostCreatePopup({
|
const FeedCreationButton({
|
||||||
super.key,
|
super.key,
|
||||||
this.hideDraftBox = false,
|
this.hideDraftBox = false,
|
||||||
this.onCreated,
|
this.onCreated,
|
||||||
@ -155,62 +111,35 @@ class PostCreatePopup extends StatelessWidget {
|
|||||||
return const SizedBox();
|
return const SizedBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<dynamic> actionList = [
|
return PopupMenuButton(
|
||||||
(
|
|
||||||
icon: const Icon(Icons.edit_square),
|
icon: const Icon(Icons.edit_square),
|
||||||
label: 'postEditor'.tr,
|
itemBuilder: (BuildContext context) => [
|
||||||
|
PopupMenuItem(
|
||||||
|
child: ListTile(
|
||||||
|
title: Text('postEditor'.tr),
|
||||||
|
leading: const Icon(Icons.article),
|
||||||
|
contentPadding: const EdgeInsets.symmetric(horizontal: 8),
|
||||||
|
),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.pop(context);
|
|
||||||
AppRouter.instance.pushNamed('postEditor').then((val) {
|
AppRouter.instance.pushNamed('postEditor').then((val) {
|
||||||
if (val != null && onCreated != null) onCreated!();
|
if (val != null && onCreated != null) {
|
||||||
|
onCreated!();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
(
|
if (!hideDraftBox)
|
||||||
icon: const Icon(Icons.drafts),
|
PopupMenuItem(
|
||||||
label: 'draftBoxOpen'.tr,
|
child: ListTile(
|
||||||
|
title: Text('draftBoxOpen'.tr),
|
||||||
|
leading: const Icon(Icons.drafts),
|
||||||
|
contentPadding: const EdgeInsets.symmetric(horizontal: 8),
|
||||||
|
),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.pop(context);
|
|
||||||
AppRouter.instance.pushNamed('draftBox');
|
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),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,8 +83,6 @@ const messagesEnglish = {
|
|||||||
'notifyAllRead': 'Mark all as read',
|
'notifyAllRead': 'Mark all as read',
|
||||||
'notifyEmpty': 'All notifications read',
|
'notifyEmpty': 'All notifications read',
|
||||||
'notifyEmptyCaption': 'It seems like nothing happened recently',
|
'notifyEmptyCaption': 'It seems like nothing happened recently',
|
||||||
'postListNews': 'News',
|
|
||||||
'postListShuffle': 'Random',
|
|
||||||
'postEditor': 'Create new post',
|
'postEditor': 'Create new post',
|
||||||
'articleEditor': 'Create new article',
|
'articleEditor': 'Create new article',
|
||||||
'articleDetail': 'Article details',
|
'articleDetail': 'Article details',
|
||||||
|
@ -81,8 +81,6 @@ const simplifiedChineseMessages = {
|
|||||||
'articleEditor': '撰写文章',
|
'articleEditor': '撰写文章',
|
||||||
'articleDetail': '文章详情',
|
'articleDetail': '文章详情',
|
||||||
'draftBoxOpen': '打开草稿箱',
|
'draftBoxOpen': '打开草稿箱',
|
||||||
'postListNews': '新鲜事',
|
|
||||||
'postListShuffle': '打乱看',
|
|
||||||
'postNew': '创建新帖子',
|
'postNew': '创建新帖子',
|
||||||
'postNewInRealmHint': '在领域 @realm 里发表新帖子',
|
'postNewInRealmHint': '在领域 @realm 里发表新帖子',
|
||||||
'postAction': '发表',
|
'postAction': '发表',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user