Skip to content

Commit

Permalink
feat: actual library render (authors page)
Browse files Browse the repository at this point in the history
  • Loading branch information
nesquikm committed Oct 30, 2023
1 parent be4b4d2 commit 8a2e337
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 38 deletions.
10 changes: 1 addition & 9 deletions lib/features/library/page/library_authors_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,7 @@ class _LibraryAuthorsPageState extends ConsumerState<LibraryAuthorsPage> {
) =>
valueOrNull.entries.isEmpty
? const FullscreenEmptyLibrarySliver()
: SliverList.builder(
itemBuilder: (context, index) {
final author = valueOrNull.keys.elementAt(index);
final tomes = valueOrNull.values.elementAt(index);

return AuthorTomesSliver(author: author, tomes: tomes);
},
itemCount: valueOrNull.entries.length,
),
: authorTomesSliver(authorTomes: valueOrNull.entries),
AsyncValue(
:final error?,
) =>
Expand Down
49 changes: 20 additions & 29 deletions lib/features/library/view/author_tomes_sliver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,25 @@ import 'package:bsr/features/library/library.dart';
import 'package:bsr/features/library/view/view.dart';
import 'package:flutter/material.dart';

class AuthorTomesSliver extends StatelessWidget {
const AuthorTomesSliver({
required this.author,
required this.tomes,
super.key,
});
SliverList authorTomesSliver({
required Iterable<MapEntry<String, LinkedHashMap<String, CachedTome>>>
authorTomes,
}) {
final entries = authorTomes.fold(
<dynamic>[],
(previousValue, element) => [
...previousValue,
element.key,
...element.value.values,
],
);

final String author;
final LinkedHashMap<String, CachedTome> tomes;

@override
Widget build(BuildContext context) {
return SliverList.list(
children: [
SliverToBoxAdapter(
child: AuthorListTile(
author: author,
),
),
SliverList.builder(
itemBuilder: (context, index) => SliverToBoxAdapter(
child: TomeListTile(
tome: tomes.values.elementAt(index),
),
),
itemCount: tomes.length,
),
],
);
}
return SliverList.builder(
itemBuilder: (context, index) => switch (entries[index]) {
final String author => AuthorListTile(author: author),
final CachedTome tome => TomeListTile(tome: tome),
_ => throw Exception('Unexpected type'),
},
itemCount: entries.length,
);
}

0 comments on commit 8a2e337

Please sign in to comment.