mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 07:55:18 +00:00
feat: compatibility with fl-query nextPage method change
This commit is contained in:
parent
3d9da8b4e3
commit
7617439915
@ -48,7 +48,7 @@ class AlbumCard extends HookConsumerWidget {
|
||||
final playlistNotifier = ref.watch(PlaylistQueueNotifier.notifier);
|
||||
final queryBowl = QueryClient.of(context);
|
||||
final query = queryBowl
|
||||
.getQuery<List<TrackSimple>, SpotifyApi>("album-tracks/${album.id}");
|
||||
.getQuery<List<TrackSimple>, dynamic>("album-tracks/${album.id}");
|
||||
final tracks = useState(query?.data ?? album.tracks ?? <Track>[]);
|
||||
bool isPlaylistPlaying = playlistNotifier.isPlayingPlaylist(tracks.value);
|
||||
final int marginH =
|
||||
|
@ -8,7 +8,6 @@ import 'package:spotube/components/shared/shimmers/shimmer_playbutton_card.dart'
|
||||
import 'package:spotube/components/shared/waypoint.dart';
|
||||
import 'package:spotube/components/playlist/playlist_card.dart';
|
||||
import 'package:spotube/models/logger.dart';
|
||||
import 'package:spotube/provider/spotify_provider.dart';
|
||||
import 'package:spotube/services/queries/queries.dart';
|
||||
|
||||
class CategoryCard extends HookConsumerWidget {
|
||||
@ -23,14 +22,10 @@ class CategoryCard extends HookConsumerWidget {
|
||||
@override
|
||||
Widget build(BuildContext context, ref) {
|
||||
final scrollController = useScrollController();
|
||||
final spotify = ref.watch(spotifyProvider);
|
||||
final playlistQuery = useQueries.category.playlistsOf(
|
||||
ref,
|
||||
category.id!,
|
||||
);
|
||||
final hasNextPage = playlistQuery.pages.isEmpty
|
||||
? false
|
||||
: (playlistQuery.pages.last.items?.length ?? 0) == 5;
|
||||
|
||||
final playlists = playlistQuery.pages
|
||||
.expand(
|
||||
@ -48,7 +43,7 @@ class CategoryCard extends HookConsumerWidget {
|
||||
],
|
||||
),
|
||||
),
|
||||
playlistQuery.hasErrors
|
||||
playlistQuery.hasPageError && !playlistQuery.hasPageData
|
||||
? PlatformText(
|
||||
"Something Went Wrong\n${playlistQuery.errors.first}")
|
||||
: SizedBox(
|
||||
@ -75,7 +70,7 @@ class CategoryCard extends HookConsumerWidget {
|
||||
children: [
|
||||
...playlists
|
||||
.map((playlist) => PlaylistCard(playlist)),
|
||||
if (hasNextPage)
|
||||
if (playlistQuery.hasNextPage)
|
||||
const ShimmerPlaybuttonCard(count: 1),
|
||||
],
|
||||
),
|
||||
|
@ -26,7 +26,7 @@ class PlaylistCard extends HookConsumerWidget {
|
||||
final playing = useStream(PlaylistQueueNotifier.playing).data ??
|
||||
PlaylistQueueNotifier.isPlaying;
|
||||
final queryBowl = QueryClient.of(context);
|
||||
final query = queryBowl.getQuery<List<Track>, SpotifyApi>(
|
||||
final query = queryBowl.getQuery<List<Track>, dynamic>(
|
||||
"playlist-tracks/${playlist.id}",
|
||||
);
|
||||
final tracks = useState(query?.data ?? []);
|
||||
|
@ -202,19 +202,8 @@ class SidebarFooter extends HookConsumerWidget {
|
||||
placeholder: ImagePlaceholder.artist,
|
||||
);
|
||||
|
||||
// TODO: Remove below code after fl-query ^0.4.0
|
||||
/// Temporary fix before fl-query 0.4.0
|
||||
final auth = ref.watch(AuthenticationNotifier.provider);
|
||||
|
||||
useEffect(() {
|
||||
if (auth != null && me.hasError) {
|
||||
me.refresh();
|
||||
}
|
||||
return null;
|
||||
}, [auth, me.hasError]);
|
||||
|
||||
/// ===================================
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(16).copyWith(left: 0),
|
||||
child: Row(
|
||||
|
@ -39,9 +39,15 @@ InfiniteQuery<DataType, ErrorType, PageType>
|
||||
);
|
||||
|
||||
useEffect(() {
|
||||
query.refreshAll();
|
||||
return null;
|
||||
}, [spotify]);
|
||||
return ref.listenManual(
|
||||
spotifyProvider,
|
||||
(previous, next) {
|
||||
if (previous != next) {
|
||||
query.refreshAll();
|
||||
}
|
||||
},
|
||||
).close;
|
||||
}, [query]);
|
||||
|
||||
return query;
|
||||
}
|
||||
|
@ -38,9 +38,15 @@ Query<DataType, ErrorType> useSpotifyQuery<DataType, ErrorType>(
|
||||
);
|
||||
|
||||
useEffect(() {
|
||||
query.refresh();
|
||||
return null;
|
||||
}, [spotify]);
|
||||
return ref.listenManual(
|
||||
spotifyProvider,
|
||||
(previous, next) {
|
||||
if (previous != next) {
|
||||
query.refresh();
|
||||
}
|
||||
},
|
||||
).close;
|
||||
}, [query]);
|
||||
|
||||
return query;
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
import 'package:catcher/catcher.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:fl_query/fl_query.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:spotify/spotify.dart';
|
||||
@ -68,13 +67,11 @@ class AlbumQueries {
|
||||
},
|
||||
ref: ref,
|
||||
initialPage: 0,
|
||||
nextPage: (lastParam, pages) {
|
||||
final lastPage = pages.elementAtOrNull(lastParam);
|
||||
if (lastPage == null ||
|
||||
lastPage.isLast ||
|
||||
(lastPage.items ?? []).length < 5) return null;
|
||||
|
||||
return lastPage.nextOffset;
|
||||
nextPage: (lastPage, lastPageData) {
|
||||
if (lastPageData.isLast || (lastPageData.items ?? []).length < 5) {
|
||||
return null;
|
||||
}
|
||||
return lastPageData.nextOffset;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:fl_query/fl_query.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:spotify/spotify.dart';
|
||||
@ -29,10 +28,12 @@ class ArtistQueries {
|
||||
.getPage(15, pageParam);
|
||||
},
|
||||
initialPage: "",
|
||||
nextPage: (lastPage, pages) =>
|
||||
pages.last.isLast || (pages.last.items?.length ?? 0) < 15
|
||||
? null
|
||||
: pages.last.after,
|
||||
nextPage: (lastPage, lastPageData) {
|
||||
if (lastPageData.isLast || (lastPageData.items ?? []).length < 15) {
|
||||
return null;
|
||||
}
|
||||
return lastPageData.after;
|
||||
},
|
||||
ref: ref,
|
||||
);
|
||||
}
|
||||
@ -77,12 +78,11 @@ class ArtistQueries {
|
||||
return spotify.artists.albums(artist).getPage(5, pageParam);
|
||||
},
|
||||
initialPage: 0,
|
||||
nextPage: (lastPage, pages) {
|
||||
final page = pages.elementAtOrNull(lastPage);
|
||||
if (page == null || page.isLast || (page.items ?? []).length < 5) {
|
||||
nextPage: (lastPage, lastPageData) {
|
||||
if (lastPageData.isLast || (lastPageData.items ?? []).length < 5) {
|
||||
return null;
|
||||
}
|
||||
return page.nextOffset;
|
||||
return lastPageData.nextOffset;
|
||||
},
|
||||
ref: ref,
|
||||
);
|
||||
|
@ -18,11 +18,11 @@ class CategoryQueries {
|
||||
return categories;
|
||||
},
|
||||
initialPage: 0,
|
||||
nextPage: (lastPage, pages) {
|
||||
if (pages.isEmpty) return lastPage + 1;
|
||||
return pages.last.isLast || (pages.last.items?.length ?? 0) < 15
|
||||
? null
|
||||
: pages.last.nextOffset;
|
||||
nextPage: (lastPage, lastPageData) {
|
||||
if (lastPageData.isLast || (lastPageData.items ?? []).length < 15) {
|
||||
return null;
|
||||
}
|
||||
return lastPageData.nextOffset;
|
||||
},
|
||||
ref: ref,
|
||||
);
|
||||
@ -42,10 +42,12 @@ class CategoryQueries {
|
||||
return playlists;
|
||||
},
|
||||
initialPage: 0,
|
||||
nextPage: (lastPage, pages) =>
|
||||
pages.last.isLast || (pages.last.items?.length ?? 0) < 5
|
||||
? null
|
||||
: pages.last.nextOffset,
|
||||
nextPage: (lastPage, lastPageData) {
|
||||
if (lastPageData.isLast || (lastPageData.items ?? []).length < 5) {
|
||||
return null;
|
||||
}
|
||||
return lastPageData.nextOffset;
|
||||
},
|
||||
ref: ref,
|
||||
);
|
||||
}
|
||||
|
@ -71,10 +71,12 @@ class PlaylistQueries {
|
||||
}
|
||||
},
|
||||
initialPage: 0,
|
||||
nextPage: (lastPage, pages) =>
|
||||
pages.last.isLast || (pages.last.items?.length ?? 0) < 5
|
||||
? null
|
||||
: pages.last.nextOffset,
|
||||
nextPage: (lastPage, lastPageData) {
|
||||
if (lastPageData.isLast || (lastPageData.items ?? []).length < 5) {
|
||||
return null;
|
||||
}
|
||||
return lastPageData.nextOffset;
|
||||
},
|
||||
ref: ref,
|
||||
);
|
||||
}
|
||||
|
@ -22,10 +22,14 @@ class SearchQueries {
|
||||
},
|
||||
ref: ref,
|
||||
initialPage: 0,
|
||||
nextPage: (lastPage, pages) =>
|
||||
pages.last.isNotEmpty && (pages.last.first.items?.length ?? 0) < 10
|
||||
? null
|
||||
: pages.last.last.nextOffset,
|
||||
nextPage: (lastPage, lastPageData) {
|
||||
if (lastPageData.isEmpty) return null;
|
||||
if ((lastPageData.first.isLast ||
|
||||
(lastPageData.first.items ?? []).length < 10)) {
|
||||
return null;
|
||||
}
|
||||
return lastPageData.first.nextOffset;
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -535,7 +535,7 @@ packages:
|
||||
description:
|
||||
path: "packages/fl_query"
|
||||
ref: new-architecture
|
||||
resolved-ref: d964216ee17e600f79c33f1811080877c8c1b510
|
||||
resolved-ref: f2a23b085cd657a1612d87749f6592b4d67814c5
|
||||
url: "https://github.com/KRTirtho/fl-query.git"
|
||||
source: git
|
||||
version: "0.3.1"
|
||||
@ -544,7 +544,7 @@ packages:
|
||||
description:
|
||||
path: "packages/fl_query_hooks"
|
||||
ref: new-architecture
|
||||
resolved-ref: d964216ee17e600f79c33f1811080877c8c1b510
|
||||
resolved-ref: f2a23b085cd657a1612d87749f6592b4d67814c5
|
||||
url: "https://github.com/KRTirtho/fl-query.git"
|
||||
source: git
|
||||
version: "0.3.1"
|
||||
|
Loading…
Reference in New Issue
Block a user