✨ Shuffle post
This commit is contained in:
parent
25550ba197
commit
d654c162e3
@ -771,5 +771,6 @@
|
||||
"messageUnablePreviewEncrypted": "Unable preview encrypted message",
|
||||
"postViewInGlobalDescription": "Do not view the post in the specific realm.",
|
||||
"postDraftSaved": "The draft has been saved.",
|
||||
"postDraftBox": "Draft Box"
|
||||
"postDraftBox": "Draft Box",
|
||||
"postShuffle": "Read Randomly"
|
||||
}
|
||||
|
@ -769,5 +769,6 @@
|
||||
"messageUnablePreviewEncrypted": "无法预览加密消息",
|
||||
"postViewInGlobalDescription": "不查看特定领域的帖子。",
|
||||
"postDraftSaved": "已保存为草稿。",
|
||||
"postDraftBox": "草稿箱"
|
||||
"postDraftBox": "草稿箱",
|
||||
"postShuffle": "随便看看"
|
||||
}
|
||||
|
@ -769,5 +769,6 @@
|
||||
"messageUnablePreviewEncrypted": "無法預覽加密消息",
|
||||
"postViewInGlobalDescription": "不查看特定領域的帖子。",
|
||||
"postDraftSaved": "已保存為草稿。",
|
||||
"postDraftBox": "草稿箱"
|
||||
"postDraftBox": "草稿箱",
|
||||
"postShuffle": "隨便看看"
|
||||
}
|
||||
|
@ -769,5 +769,6 @@
|
||||
"messageUnablePreviewEncrypted": "無法預覽加密消息",
|
||||
"postViewInGlobalDescription": "不查看特定領域的帖子。",
|
||||
"postDraftSaved": "已保存為草稿。",
|
||||
"postDraftBox": "草稿箱"
|
||||
"postDraftBox": "草稿箱",
|
||||
"postShuffle": "隨便看看"
|
||||
}
|
||||
|
@ -155,9 +155,12 @@ class SnPostContentProvider {
|
||||
String? realm,
|
||||
String? channel,
|
||||
bool isDraft = false,
|
||||
bool isShuffle = false,
|
||||
}) async {
|
||||
final resp = await _sn.client.get(
|
||||
'/cgi/co/posts${isDraft ? '/drafts' : ''}',
|
||||
isShuffle
|
||||
? '/cgi/co/recommendations/shuffle'
|
||||
: '/cgi/co/posts${isDraft ? '/drafts' : ''}',
|
||||
queryParameters: {
|
||||
'take': take,
|
||||
'offset': offset,
|
||||
|
@ -30,6 +30,7 @@ import 'package:surface/screens/notification.dart';
|
||||
import 'package:surface/screens/post/post_detail.dart';
|
||||
import 'package:surface/screens/post/post_draft.dart';
|
||||
import 'package:surface/screens/post/post_editor.dart';
|
||||
import 'package:surface/screens/post/post_shuffle.dart';
|
||||
import 'package:surface/screens/post/publisher_page.dart';
|
||||
import 'package:surface/screens/post/post_search.dart';
|
||||
import 'package:surface/screens/realm.dart';
|
||||
@ -88,6 +89,11 @@ final _appRoutes = [
|
||||
extraProps: state.extra as PostEditorExtra?,
|
||||
),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/shuffle',
|
||||
name: 'postShuffle',
|
||||
builder: (context, state) => const PostShuffleScreen(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/search',
|
||||
name: 'postSearch',
|
||||
|
@ -225,7 +225,9 @@ class _ExploreScreenState extends State<ExploreScreen>
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(Symbols.shuffle),
|
||||
onPressed: () {},
|
||||
onPressed: () {
|
||||
GoRouter.of(context).pushNamed('postShuffle');
|
||||
},
|
||||
),
|
||||
Expanded(
|
||||
child: Center(
|
||||
|
132
lib/screens/post/post_shuffle.dart
Normal file
132
lib/screens/post/post_shuffle.dart
Normal file
@ -0,0 +1,132 @@
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_card_swiper/flutter_card_swiper.dart';
|
||||
import 'package:material_symbols_icons/symbols.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:styled_widget/styled_widget.dart';
|
||||
import 'package:surface/providers/post.dart';
|
||||
import 'package:surface/types/post.dart';
|
||||
import 'package:surface/widgets/dialog.dart';
|
||||
import 'package:surface/widgets/navigation/app_scaffold.dart';
|
||||
import 'package:surface/widgets/post/post_item.dart';
|
||||
|
||||
class PostShuffleScreen extends StatefulWidget {
|
||||
const PostShuffleScreen({super.key});
|
||||
|
||||
@override
|
||||
State<PostShuffleScreen> createState() => _PostShuffleScreenState();
|
||||
}
|
||||
|
||||
class _PostShuffleScreenState extends State<PostShuffleScreen> {
|
||||
late final CardSwiperController _cardController = CardSwiperController();
|
||||
|
||||
bool _isBusy = false;
|
||||
final List<SnPost> _posts = List.empty(growable: true);
|
||||
|
||||
Future<void> _fetchPosts() async {
|
||||
_posts.clear();
|
||||
setState(() => _isBusy = true);
|
||||
try {
|
||||
final pt = context.read<SnPostContentProvider>();
|
||||
final result = await pt.listPosts(
|
||||
take: 10,
|
||||
offset: _posts.length,
|
||||
isShuffle: true,
|
||||
);
|
||||
_posts.addAll(result.$1);
|
||||
} catch (err) {
|
||||
if (!mounted) return;
|
||||
context.showErrorDialog(err);
|
||||
} finally {
|
||||
setState(() => _isBusy = false);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_fetchPosts();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
_cardController.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AppScaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('postShuffle').tr(),
|
||||
),
|
||||
body: Stack(
|
||||
children: [
|
||||
Column(
|
||||
children: [
|
||||
if (_isBusy || _posts.isEmpty)
|
||||
const Expanded(
|
||||
child: Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
)
|
||||
else
|
||||
Expanded(
|
||||
child: CardSwiper(
|
||||
controller: _cardController,
|
||||
isLoop: false,
|
||||
padding: EdgeInsets.zero,
|
||||
cardsCount: _posts.length,
|
||||
cardBuilder: (context, idx, _, __) {
|
||||
final ele = _posts[idx];
|
||||
return SingleChildScrollView(
|
||||
child: Center(
|
||||
child: OpenablePostItem(
|
||||
key: ValueKey(ele),
|
||||
data: ele,
|
||||
maxWidth: 640,
|
||||
onChanged: (ele) {
|
||||
_posts[idx] = ele;
|
||||
setState(() {});
|
||||
},
|
||||
onDeleted: () {
|
||||
_fetchPosts();
|
||||
},
|
||||
).padding(
|
||||
all: 24,
|
||||
bottom:
|
||||
MediaQuery.of(context).padding.bottom + 16 + 50,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
onEnd: () {
|
||||
_fetchPosts();
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (!_isBusy && _posts.isNotEmpty)
|
||||
Positioned(
|
||||
bottom: MediaQuery.of(context).padding.bottom + 16,
|
||||
left: 16,
|
||||
right: 16,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
IconButton.filled(
|
||||
icon: const Icon(Symbols.next_plan),
|
||||
color: Theme.of(context).colorScheme.onPrimary,
|
||||
onPressed: () {
|
||||
_cardController.swipe(CardSwiperDirection.right);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user