mirror of
https://github.com/gabehf/Fladder.git
synced 2026-03-14 09:46:01 -07:00
Init repo
This commit is contained in:
commit
764b6034e3
566 changed files with 212335 additions and 0 deletions
42
lib/providers/items/folder_details_provider.dart
Normal file
42
lib/providers/items/folder_details_provider.dart
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
import 'package:chopper/chopper.dart';
|
||||
import 'package:fladder/jellyfin/jellyfin_open_api.swagger.dart';
|
||||
import 'package:fladder/models/items/folder_model.dart';
|
||||
import 'package:fladder/providers/api_provider.dart';
|
||||
import 'package:fladder/providers/service_provider.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
final folderDetailsProvider =
|
||||
StateNotifierProvider.autoDispose.family<FolderDetailsNotifier, FolderModel?, String>((ref, id) {
|
||||
return FolderDetailsNotifier(ref);
|
||||
});
|
||||
|
||||
class FolderDetailsNotifier extends StateNotifier<FolderModel?> {
|
||||
FolderDetailsNotifier(this.ref) : super(null);
|
||||
|
||||
final Ref ref;
|
||||
|
||||
late final JellyService api = ref.read(jellyApiProvider);
|
||||
|
||||
Future<Response?> fetchDetails(String id) async {
|
||||
if (state == null) {
|
||||
final folderItem = await api.usersUserIdItemsItemIdGet(itemId: id);
|
||||
|
||||
if (folderItem.body != null) {
|
||||
state = folderItem.bodyOrThrow as FolderModel;
|
||||
}
|
||||
}
|
||||
|
||||
final response = await api.itemsGet(
|
||||
parentId: id,
|
||||
sortBy: [ItemSortBy.sortname, ItemSortBy.name],
|
||||
sortOrder: [SortOrder.ascending],
|
||||
fields: [
|
||||
ItemFields.primaryimageaspectratio,
|
||||
ItemFields.childcount,
|
||||
],
|
||||
);
|
||||
|
||||
state = state?.copyWith(items: response.body?.items.where((element) => element.childCount != 0).toList());
|
||||
return response;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue