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