mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-14 08:25:16 +00:00

* feat: add riverpod based favorite album provider * feat: add album is saved, new releases and tracks providers * feat: add artist related providers * feat: add all categories providers * feat: add lyrics provider * feat: add playlist related providers * feat: add search provider * feat: add view and spotify friends provider * feat: add playlist create and update and favorite handlers * feat: use providers in home screen * chore: fix dart lint issues * feat: use new providers for playlist and albums screen * feat: use providers in artist page * feat: use providers on library page * feat: use provider for playlist and album card and heart button * feat: use provider in search page * feat: use providers in generate playlist * feat: use provider in lyrics screen * feat: use provider for create playlist * feat: use provider in add track dialog * feat: use providers in remaining pages and remove fl_query * fix: remove direct access to provider.value * fix: glitching when loading * fix: user album loading next page indicator * feat: make many provider autoDispose after 5 minutes of no usage * fix: ignore episodes in tracks
57 lines
1.7 KiB
Dart
57 lines
1.7 KiB
Dart
part of '../../spotify.dart';
|
|
|
|
mixin CursorPaginatedAsyncNotifierMixin<K, T extends CursorPaginatedState<K>>
|
|
// ignore: invalid_use_of_internal_member
|
|
on AsyncNotifierBase<T> {
|
|
Future<(List<K> items, String nextCursor)> fetch(String? offset, int limit);
|
|
|
|
Future<void> fetchMore() async {
|
|
if (state.value == null || !state.value!.hasMore) return;
|
|
|
|
state = AsyncLoadingNext(state.asData!.value);
|
|
|
|
state = await AsyncValue.guard(
|
|
() async {
|
|
final items = await fetch(state.value!.offset, state.value!.limit);
|
|
return state.value!.copyWith(
|
|
hasMore: items.$1.length == state.value!.limit,
|
|
items: [
|
|
...state.value!.items,
|
|
...items.$1,
|
|
],
|
|
offset: items.$2,
|
|
) as T;
|
|
},
|
|
);
|
|
}
|
|
|
|
Future<List<K>> fetchAll() async {
|
|
if (state.value == null) return [];
|
|
if (!state.value!.hasMore) return state.value!.items;
|
|
|
|
bool hasMore = true;
|
|
while (hasMore) {
|
|
await update((state) async {
|
|
final items = await fetch(state.offset, state.limit);
|
|
|
|
hasMore = items.$1.length == state.limit;
|
|
return state.copyWith(
|
|
items: [...state.items, ...items.$1],
|
|
offset: items.$2,
|
|
hasMore: hasMore,
|
|
) as T;
|
|
});
|
|
}
|
|
|
|
return state.value!.items;
|
|
}
|
|
}
|
|
|
|
abstract class CursorPaginatedAsyncNotifier<K,
|
|
T extends CursorPaginatedState<K>> extends AsyncNotifier<T>
|
|
with CursorPaginatedAsyncNotifierMixin<K, T>, SpotifyMixin<T> {}
|
|
|
|
abstract class AutoDisposeCursorPaginatedAsyncNotifier<K,
|
|
T extends CursorPaginatedState<K>> extends AutoDisposeAsyncNotifier<T>
|
|
with CursorPaginatedAsyncNotifierMixin<K, T>, SpotifyMixin<T> {}
|