diff --git a/lib/pages/home/personalized.dart b/lib/pages/home/personalized.dart index a502103df..a115e78e2 100644 --- a/lib/pages/home/personalized.dart +++ b/lib/pages/home/personalized.dart @@ -8,6 +8,7 @@ import 'package:spotube/components/album/album_card.dart'; import 'package:spotube/components/playlist/playlist_card.dart'; import 'package:spotube/components/shared/shimmers/shimmer_playbutton_card.dart'; import 'package:spotube/components/shared/waypoint.dart'; +import 'package:spotube/hooks/use_async_effect.dart'; import 'package:spotube/models/logger.dart'; import 'package:spotube/services/queries/queries.dart'; import 'package:spotube/utils/type_conversion_utils.dart'; @@ -106,6 +107,15 @@ class PersonalizedPage extends HookConsumerWidget { final newReleases = useQueries.album.newReleases(ref); + useAsyncEffect(() async { + final releases = newReleases.pages.expand( + (page) => page.items ?? const Iterable.empty(), + ); + if (releases.isEmpty) { + await newReleases.fetchNext(); + } + }, null, [newReleases.pages]); + return ListView( children: [ PersonalizedItemCard( diff --git a/lib/services/queries/album.dart b/lib/services/queries/album.dart index 629f732ad..27c1e483a 100644 --- a/lib/services/queries/album.dart +++ b/lib/services/queries/album.dart @@ -4,6 +4,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:spotify/spotify.dart'; import 'package:spotube/hooks/use_spotify_infinite_query.dart'; import 'package:spotube/hooks/use_spotify_query.dart'; +import 'package:spotube/provider/user_preferences_provider.dart'; class AlbumQueries { const AlbumQueries(); @@ -48,17 +49,17 @@ class AlbumQueries { } InfiniteQuery, dynamic, int> newReleases(WidgetRef ref) { + final market = ref + .watch(userPreferencesProvider.select((s) => s.recommendationMarket)); + return useSpotifyInfiniteQuery, dynamic, int>( "new-releases", (pageParam, spotify) async { try { - final albums = await Pages( - spotify, - 'v1/browse/new-releases', - (json) => AlbumSimple.fromJson(json), - 'albums', - (json) => AlbumSimple.fromJson(json), - ).getPage(5, pageParam); + final albums = await spotify.browse + .getNewReleases(country: market) + .getPage(5, pageParam); + return albums; } catch (e, stack) { Catcher.reportCheckedError(e, stack); @@ -68,7 +69,7 @@ class AlbumQueries { ref: ref, initialPage: 0, nextPage: (lastPage, lastPageData) { - if (lastPageData.isLast || (lastPageData.items ?? []).length < 5) { + if (lastPageData.isLast) { return null; } return lastPageData.nextOffset; diff --git a/lib/services/queries/category.dart b/lib/services/queries/category.dart index c4e8d188d..8028e70b2 100644 --- a/lib/services/queries/category.dart +++ b/lib/services/queries/category.dart @@ -1,4 +1,5 @@ import 'package:fl_query/fl_query.dart'; +import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:spotify/spotify.dart'; import 'package:spotube/extensions/map.dart'; @@ -10,6 +11,8 @@ class CategoryQueries { InfiniteQuery, dynamic, int> list( WidgetRef ref, String recommendationMarket) { + final context = useContext(); + return useSpotifyInfiniteQuery, dynamic, int>( "category-playlists", (pageParam, spotify) async { @@ -35,6 +38,10 @@ class CategoryQueries { }, ), ), + refreshConfig: RefreshConfig.withDefaults( + context, + staleDuration: const Duration(minutes: 30), + ), ref: ref, ); } diff --git a/pubspec.lock b/pubspec.lock index ca29daf61..d7f242908 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1481,11 +1481,12 @@ packages: spotify: dependency: "direct main" description: - name: spotify - sha256: db51b46216465631f90218581b97ea08b7bf5c93f1c9a7066fbf3499fe32c774 - url: "https://pub.dev" - source: hosted - version: "0.8.0" + path: "." + ref: "9e8ef4556942d42d74874de5491253156e7e6f43" + resolved-ref: "9e8ef4556942d42d74874de5491253156e7e6f43" + url: "https://github.com/rinukkusu/spotify-dart" + source: git + version: "0.9.0" sqflite: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 3ee98abc8..15cd72613 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -79,7 +79,10 @@ dependencies: scroll_to_index: ^3.0.1 shared_preferences: ^2.0.11 skeleton_text: ^3.0.0 - spotify: ^0.8.0 + spotify: + git: + url: https://github.com/rinukkusu/spotify-dart + ref: 9e8ef4556942d42d74874de5491253156e7e6f43 tuple: ^2.0.1 url_launcher: ^6.1.7 uuid: ^3.0.7