Post list now supports initial filter to prevent some mismatch

This commit is contained in:
2025-12-06 18:47:50 +08:00
parent 16c7b7e764
commit dff84dde58
5 changed files with 328 additions and 19 deletions

View File

@@ -43,17 +43,26 @@ class SliverPostList extends HookConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final provider = postListProvider(queryKey);
final notifier = provider.notifier;
final provider = postListProvider(
PostListQueryConfig(
id: queryKey,
initialFilter: query ?? PostListQuery(),
),
);
final notifier = ref.watch(provider.notifier);
final currentFilter = useState(query ?? PostListQuery());
useEffect(() {
ref.read(notifier).applyFilter(query!);
if (currentFilter.value != query) {
notifier.applyFilter(query ?? PostListQuery());
}
return null;
}, [query]);
}, [query, queryKey]);
return PaginationList(
provider: provider,
notifier: notifier,
notifier: provider.notifier,
isRefreshable: false,
isSliver: true,
footerSkeletonChild: const PostItemSkeleton(),

View File

@@ -17,15 +17,16 @@ class PostShuffleScreen extends HookConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
const query = PostListQuery(shuffle: true);
final postListState = ref.watch(postListProvider(kShufflePostListId));
final postListNotifier = ref.watch(
postListProvider(kShufflePostListId).notifier,
final cfg = PostListQueryConfig(
id: kShufflePostListId,
initialFilter: query,
);
final postListState = ref.watch(postListProvider(cfg));
final postListNotifier = ref.watch(postListProvider(cfg).notifier);
final cardSwiperController = useMemoized(() => CardSwiperController(), []);
useEffect(() {
postListNotifier.applyFilter(query);
return cardSwiperController.dispose;
}, []);