mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 16:05:18 +00:00
fix: Add to Playlist Dialog memory leak #817
This commit is contained in:
parent
7b72a90bc6
commit
fed36ecdd8
@ -1,4 +1,3 @@
|
|||||||
import 'package:async/async.dart';
|
|
||||||
import 'package:fl_query_hooks/fl_query_hooks.dart';
|
import 'package:fl_query_hooks/fl_query_hooks.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||||
@ -21,32 +20,21 @@ class PlaylistAddTrackDialog extends HookConsumerWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, ref) {
|
Widget build(BuildContext context, ref) {
|
||||||
final spotify = ref.watch(spotifyProvider);
|
final spotify = ref.watch(spotifyProvider);
|
||||||
final userPlaylists = useQueries.playlist.ofMine(ref);
|
final userPlaylists = useQueries.playlist.ofMineAll(ref);
|
||||||
|
|
||||||
useEffect(() {
|
|
||||||
final op = CancelableOperation.fromFuture(
|
|
||||||
() async {
|
|
||||||
while (userPlaylists.hasNextPage) {
|
|
||||||
await userPlaylists.fetchNext();
|
|
||||||
}
|
|
||||||
}(),
|
|
||||||
);
|
|
||||||
|
|
||||||
return () {
|
|
||||||
op.cancel();
|
|
||||||
};
|
|
||||||
}, [userPlaylists.hasNextPage]);
|
|
||||||
|
|
||||||
final me = useQueries.user.me(ref);
|
final me = useQueries.user.me(ref);
|
||||||
|
|
||||||
final filteredPlaylists = useMemoized(
|
final filteredPlaylists = useMemoized(
|
||||||
() => userPlaylists.pages
|
() =>
|
||||||
.expand((page) => page.items?.toList() ?? <PlaylistSimple>[])
|
userPlaylists.data
|
||||||
.where(
|
?.where(
|
||||||
(playlist) =>
|
(playlist) =>
|
||||||
playlist.owner?.id != null && playlist.owner!.id == me.data?.id,
|
playlist.owner?.id != null &&
|
||||||
),
|
playlist.owner!.id == me.data?.id,
|
||||||
[userPlaylists.pages, me.data?.id],
|
)
|
||||||
|
.toList() ??
|
||||||
|
[],
|
||||||
|
[userPlaylists.data, me.data?.id],
|
||||||
);
|
);
|
||||||
|
|
||||||
final playlistsCheck = useState(<String, bool>{});
|
final playlistsCheck = useState(<String, bool>{});
|
||||||
@ -93,7 +81,7 @@ class PlaylistAddTrackDialog extends HookConsumerWidget {
|
|||||||
content: SizedBox(
|
content: SizedBox(
|
||||||
height: 300,
|
height: 300,
|
||||||
width: 300,
|
width: 300,
|
||||||
child: userPlaylists.hasNextPage
|
child: userPlaylists.isLoading
|
||||||
? const Center(child: CircularProgressIndicator())
|
? const Center(child: CircularProgressIndicator())
|
||||||
: ListView.builder(
|
: ListView.builder(
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
|
@ -143,6 +143,29 @@ class PlaylistQueries {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Query<List<PlaylistSimple>, dynamic> ofMineAll(WidgetRef ref) {
|
||||||
|
return useSpotifyQuery<List<PlaylistSimple>, dynamic>(
|
||||||
|
"current-user-all-playlists",
|
||||||
|
(spotify) async {
|
||||||
|
var page = await spotify.playlists.me.getPage(50);
|
||||||
|
final playlists = <PlaylistSimple>[];
|
||||||
|
|
||||||
|
if (page.isLast == true) {
|
||||||
|
return page.items?.toList() ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
|
playlists.addAll(page.items ?? []);
|
||||||
|
while (!page.isLast) {
|
||||||
|
page = await spotify.playlists.me.getPage(50, page.nextOffset);
|
||||||
|
playlists.addAll(page.items ?? []);
|
||||||
|
}
|
||||||
|
|
||||||
|
return playlists;
|
||||||
|
},
|
||||||
|
ref: ref,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Future<List<Track>> likedTracks(
|
Future<List<Track>> likedTracks(
|
||||||
SpotifyApi spotify,
|
SpotifyApi spotify,
|
||||||
WidgetRef ref,
|
WidgetRef ref,
|
||||||
|
Loading…
Reference in New Issue
Block a user