Skip to content

Commit

Permalink
chore: track view play not working properly
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Nov 27, 2023
1 parent 64080ef commit 722dd86
Show file tree
Hide file tree
Showing 5 changed files with 296 additions and 269 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ class TrackViewBodySection extends HookConsumerWidget {
final playlistNotifier = ref.watch(ProxyPlaylistNotifier.notifier);
final props = InheritedTrackView.of(context);

final trackViewState = ref.watch(trackViewProvider(props.tracks));

final searchController = useTextEditingController();
final searchFocus = useFocusNode();

Expand All @@ -35,20 +33,27 @@ class TrackViewBodySection extends HookConsumerWidget {

final isFiltering = useState(false);

final uniqTracks = useMemoized(() {
final trackIds = props.tracks.map((e) => e.id).toSet();
return props.tracks.where((e) => trackIds.remove(e.id)).toList();
}, [props.tracks]);

final trackViewState = ref.watch(trackViewProvider(uniqTracks));

final tracks = useMemoized(() {
List<Track> filteredTracks;
if (searchQuery.isEmpty) {
filteredTracks = props.tracks;
filteredTracks = uniqTracks;
} else {
filteredTracks = props.tracks
filteredTracks = uniqTracks
.map((e) => (weightedRatio(e.name!, searchQuery), e))
.sorted((a, b) => b.$1.compareTo(a.$1))
.where((e) => e.$1 > 50)
.map((e) => e.$2)
.toList();
}
return ServiceUtils.sortTracks(filteredTracks, trackViewState.sortBy);
}, [trackViewState.sortBy, searchQuery, props.tracks]);
}, [trackViewState.sortBy, searchQuery, uniqTracks]);

final isUserPlaylist = useIsUserPlaylist(ref, props.collectionId);

Expand Down Expand Up @@ -106,8 +111,9 @@ class TrackViewBodySection extends HookConsumerWidget {
if (isActive || playlist.tracks.contains(track)) {
await playlistNotifier.jumpToTrack(track);
} else {
final tracks = await props.pagination.onFetchAll();
await playlistNotifier.load(
props.tracks,
tracks,
initialIndex: index,
autoPlay: true,
);
Expand Down
26 changes: 15 additions & 11 deletions lib/extensions/infinite_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@ extension FetchAllTracks on InfiniteQuery<List<Track>, dynamic, int> {
return pages.expand((page) => page).toList();
}
final tracks = await getAllTracks();
final pagedTracks = tracks.fold(
<int, List<Track>>{},
(acc, element) {
final index = acc.length;
final groupIndex = index ~/ 20;
final group = acc[groupIndex] ?? [];
group.add(element);
acc[groupIndex] = group;
return acc;
},
);

final numOfPages = (tracks.length / 20).round();

final Map<int, List<Track>> pagedTracks = {};

for (var i = 0; i < numOfPages; i++) {
if (i == numOfPages - 1) {
final pageTracks = tracks.sublist(i * 20);
pagedTracks[i] = pageTracks;
break;
}

final pageTracks = tracks.sublist(i * 20, (i + 1) * 20);
pagedTracks[i] = pageTracks;
}

for (final group in pagedTracks.entries) {
setPageData(group.key, group.value);
Expand Down
6 changes: 3 additions & 3 deletions lib/pages/artist/section/footer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ class ArtistPageFooter extends HookConsumerWidget {
BlendMode.darken,
),
image: UniversalImage.imageProvider(
summary.data!.originalimage?.source_ ?? artistImage,
height: summary.data!.originalimage?.height.toDouble(),
width: summary.data!.originalimage?.width.toDouble(),
summary.data!.thumbnail?.source_ ?? artistImage,
height: summary.data!.thumbnail?.height.toDouble(),
width: summary.data!.thumbnail?.width.toDouble(),
),
fit: BoxFit.cover,
alignment: Alignment.center,
Expand Down
Loading

0 comments on commit 722dd86

Please sign in to comment.