♻️ Rebuilt fetching state machine
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
// Post Categories Notifier
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:island/models/post_category.dart';
|
||||
import 'package:island/models/post_tag.dart';
|
||||
@@ -8,11 +10,25 @@ import 'package:island/pods/paging.dart';
|
||||
final postCategoriesProvider =
|
||||
AsyncNotifierProvider.autoDispose<
|
||||
PostCategoriesNotifier,
|
||||
List<SnPostCategory>
|
||||
PaginationState<SnPostCategory>
|
||||
>(PostCategoriesNotifier.new);
|
||||
|
||||
class PostCategoriesNotifier extends AsyncNotifier<List<SnPostCategory>>
|
||||
class PostCategoriesNotifier
|
||||
extends AsyncNotifier<PaginationState<SnPostCategory>>
|
||||
with AsyncPaginationController<SnPostCategory> {
|
||||
@override
|
||||
FutureOr<PaginationState<SnPostCategory>> build() async {
|
||||
final items = await fetch();
|
||||
return PaginationState(
|
||||
items: items,
|
||||
isLoading: false,
|
||||
isReloading: false,
|
||||
totalCount: totalCount,
|
||||
hasMore: hasMore,
|
||||
cursor: cursor,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<SnPostCategory>> fetch() async {
|
||||
final client = ref.read(apiClientProvider);
|
||||
@@ -30,12 +46,26 @@ class PostCategoriesNotifier extends AsyncNotifier<List<SnPostCategory>>
|
||||
|
||||
// Post Tags Notifier
|
||||
final postTagsProvider =
|
||||
AsyncNotifierProvider.autoDispose<PostTagsNotifier, List<SnPostTag>>(
|
||||
PostTagsNotifier.new,
|
||||
);
|
||||
AsyncNotifierProvider.autoDispose<
|
||||
PostTagsNotifier,
|
||||
PaginationState<SnPostTag>
|
||||
>(PostTagsNotifier.new);
|
||||
|
||||
class PostTagsNotifier extends AsyncNotifier<List<SnPostTag>>
|
||||
class PostTagsNotifier extends AsyncNotifier<PaginationState<SnPostTag>>
|
||||
with AsyncPaginationController<SnPostTag> {
|
||||
@override
|
||||
FutureOr<PaginationState<SnPostTag>> build() async {
|
||||
final items = await fetch();
|
||||
return PaginationState(
|
||||
items: items,
|
||||
isLoading: false,
|
||||
isReloading: false,
|
||||
totalCount: totalCount,
|
||||
hasMore: hasMore,
|
||||
cursor: cursor,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<SnPostTag>> fetch() async {
|
||||
final client = ref.read(apiClientProvider);
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:island/models/post.dart';
|
||||
@@ -39,7 +41,7 @@ final postListProvider = AsyncNotifierProvider.autoDispose.family(
|
||||
PostListNotifier.new,
|
||||
);
|
||||
|
||||
class PostListNotifier extends AsyncNotifier<List<SnPost>>
|
||||
class PostListNotifier extends AsyncNotifier<PaginationState<SnPost>>
|
||||
with
|
||||
AsyncPaginationController<SnPost>,
|
||||
AsyncPaginationFilter<PostListQuery, SnPost> {
|
||||
@@ -53,9 +55,17 @@ class PostListNotifier extends AsyncNotifier<List<SnPost>>
|
||||
late PostListQuery currentFilter;
|
||||
|
||||
@override
|
||||
Future<List<SnPost>> build() async {
|
||||
FutureOr<PaginationState<SnPost>> build() async {
|
||||
currentFilter = config.initialFilter;
|
||||
return fetch();
|
||||
final items = await fetch();
|
||||
return PaginationState(
|
||||
items: items,
|
||||
isLoading: false,
|
||||
isReloading: false,
|
||||
totalCount: totalCount,
|
||||
hasMore: hasMore,
|
||||
cursor: cursor,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user