mirror of
https://github.com/austinried/subtracks.git
synced 2025-12-27 09:09:29 +01:00
65 lines
2.0 KiB
Dart
65 lines
2.0 KiB
Dart
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
|
|
|
|
import '../../../database/dao/library_dao.dart';
|
|
import '../../../database/query.dart';
|
|
import '../../hooks/use_on_source.dart';
|
|
import '../../hooks/use_paging_controller.dart';
|
|
import '../../state/database.dart';
|
|
import '../../state/source.dart';
|
|
import 'items.dart';
|
|
|
|
const kPageSize = 30;
|
|
|
|
class ArtistsList extends HookConsumerWidget {
|
|
const ArtistsList({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final db = ref.watch(databaseProvider);
|
|
final controller = usePagingController<int, AristListItem>(
|
|
getNextPageKey: (state) =>
|
|
state.lastPageIsEmpty ? null : state.nextIntPageKey,
|
|
fetchPage: (pageKey) => db.libraryDao.listArtists(
|
|
ArtistsQuery(
|
|
sourceId: ref.read(sourceIdProvider),
|
|
sort: IList([
|
|
SortingTerm.artistsAsc(ArtistsColumn.name),
|
|
]),
|
|
limit: kPageSize,
|
|
offset: (pageKey - 1) * kPageSize,
|
|
),
|
|
),
|
|
);
|
|
|
|
useOnSourceChange(ref, (_) => controller.refresh());
|
|
useOnSourceSync(ref, controller.refresh);
|
|
|
|
return PagingListener(
|
|
controller: controller,
|
|
builder: (context, state, fetchNextPage) {
|
|
return PagedSliverList(
|
|
state: state,
|
|
fetchNextPage: fetchNextPage,
|
|
builderDelegate: PagedChildBuilderDelegate<AristListItem>(
|
|
itemBuilder: (context, item, index) {
|
|
final (:artist, :albumCount) = item;
|
|
|
|
return ArtistListTile(
|
|
artist: artist,
|
|
albumCount: albumCount,
|
|
onTap: () async {
|
|
context.push('/artists/${artist.id}');
|
|
},
|
|
);
|
|
},
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|