mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 07:55:18 +00:00
fixed API rate limit exit bug on TrackTile
This commit is contained in:
parent
8f200d6488
commit
038856a1f7
@ -8,6 +8,7 @@ import 'package:spotube/models/Logger.dart';
|
||||
import 'package:spotube/provider/Auth.dart';
|
||||
import 'package:spotube/provider/Playback.dart';
|
||||
import 'package:spotube/provider/SpotifyDI.dart';
|
||||
import 'package:spotube/provider/SpotifyRequests.dart';
|
||||
|
||||
class PlayerActions extends HookConsumerWidget {
|
||||
final MainAxisAlignment mainAxisAlignment;
|
||||
@ -51,6 +52,10 @@ class PlayerActions extends HookConsumerWidget {
|
||||
logger.e("FavoriteButton.onPressed", e, stack);
|
||||
} finally {
|
||||
update();
|
||||
ref.refresh(currentUserSavedTracksQuery);
|
||||
ref.refresh(
|
||||
playlistTracksQuery("user-liked-tracks"),
|
||||
);
|
||||
}
|
||||
});
|
||||
}),
|
||||
|
@ -2,7 +2,6 @@ import 'dart:convert';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:spotube/components/Shared/HeartButton.dart';
|
||||
import 'package:spotube/components/Shared/TrackCollectionView.dart';
|
||||
|
@ -12,6 +12,7 @@ import 'package:spotube/models/Logger.dart';
|
||||
import 'package:spotube/provider/Auth.dart';
|
||||
import 'package:spotube/provider/Playback.dart';
|
||||
import 'package:spotube/provider/SpotifyDI.dart';
|
||||
import 'package:spotube/provider/SpotifyRequests.dart';
|
||||
|
||||
class TrackTile extends HookConsumerWidget {
|
||||
final Playback playback;
|
||||
@ -41,6 +42,13 @@ class TrackTile extends HookConsumerWidget {
|
||||
final spotify = ref.watch(spotifyProvider);
|
||||
final update = useForceUpdate();
|
||||
|
||||
final savedTracksSnapshot = ref.watch(currentUserSavedTracksQuery);
|
||||
|
||||
final isSaved = savedTracksSnapshot.asData?.value.any(
|
||||
(e) => track.value.id! == e.id,
|
||||
) ??
|
||||
false;
|
||||
|
||||
final actionFavorite = useCallback((bool isLiked) async {
|
||||
try {
|
||||
isLiked
|
||||
@ -50,6 +58,8 @@ class TrackTile extends HookConsumerWidget {
|
||||
logger.e("FavoriteButton.onPressed", e, stack);
|
||||
} finally {
|
||||
update();
|
||||
ref.refresh(currentUserSavedTracksQuery);
|
||||
ref.refresh(playlistTracksQuery("user-liked-tracks"));
|
||||
}
|
||||
}, [track.value.id, spotify]);
|
||||
|
||||
@ -229,78 +239,74 @@ class TrackTile extends HookConsumerWidget {
|
||||
Text(duration),
|
||||
],
|
||||
const SizedBox(width: 10),
|
||||
FutureBuilder<bool>(
|
||||
future: spotify.tracks.me.containsOne(track.value.id!),
|
||||
builder: (context, snapshot) {
|
||||
return PopupMenuButton(
|
||||
icon: const Icon(Icons.more_horiz_rounded),
|
||||
itemBuilder: (context) {
|
||||
return [
|
||||
if (auth.isLoggedIn)
|
||||
PopupMenuItem(
|
||||
child: Row(
|
||||
children: const [
|
||||
Icon(Icons.add_box_rounded),
|
||||
SizedBox(width: 10),
|
||||
Text("Add to Playlist"),
|
||||
],
|
||||
),
|
||||
value: "add-playlist",
|
||||
),
|
||||
if (userPlaylist && auth.isLoggedIn)
|
||||
PopupMenuItem(
|
||||
child: Row(
|
||||
children: const [
|
||||
Icon(Icons.remove_circle_outline_rounded),
|
||||
SizedBox(width: 10),
|
||||
Text("Remove from Playlist"),
|
||||
],
|
||||
),
|
||||
value: "remove-playlist",
|
||||
),
|
||||
if (auth.isLoggedIn)
|
||||
PopupMenuItem(
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(snapshot.data == true
|
||||
? Icons.favorite_rounded
|
||||
: Icons.favorite_border_rounded),
|
||||
const SizedBox(width: 10),
|
||||
const Text("Favorite")
|
||||
],
|
||||
),
|
||||
value: "favorite",
|
||||
),
|
||||
PopupMenuItem(
|
||||
child: Row(
|
||||
children: const [
|
||||
Icon(Icons.share_rounded),
|
||||
SizedBox(width: 10),
|
||||
Text("Share")
|
||||
],
|
||||
),
|
||||
value: "share",
|
||||
)
|
||||
];
|
||||
},
|
||||
onSelected: (value) {
|
||||
switch (value) {
|
||||
case "favorite":
|
||||
actionFavorite(snapshot.data == true);
|
||||
break;
|
||||
case "add-playlist":
|
||||
actionAddToPlaylist();
|
||||
break;
|
||||
case "remove-playlist":
|
||||
actionRemoveFromPlaylist();
|
||||
break;
|
||||
case "share":
|
||||
actionShare(track.value);
|
||||
break;
|
||||
}
|
||||
},
|
||||
);
|
||||
})
|
||||
PopupMenuButton(
|
||||
icon: const Icon(Icons.more_horiz_rounded),
|
||||
itemBuilder: (context) {
|
||||
return [
|
||||
if (auth.isLoggedIn)
|
||||
PopupMenuItem(
|
||||
child: Row(
|
||||
children: const [
|
||||
Icon(Icons.add_box_rounded),
|
||||
SizedBox(width: 10),
|
||||
Text("Add to Playlist"),
|
||||
],
|
||||
),
|
||||
value: "add-playlist",
|
||||
),
|
||||
if (userPlaylist && auth.isLoggedIn)
|
||||
PopupMenuItem(
|
||||
child: Row(
|
||||
children: const [
|
||||
Icon(Icons.remove_circle_outline_rounded),
|
||||
SizedBox(width: 10),
|
||||
Text("Remove from Playlist"),
|
||||
],
|
||||
),
|
||||
value: "remove-playlist",
|
||||
),
|
||||
if (auth.isLoggedIn)
|
||||
PopupMenuItem(
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(isSaved
|
||||
? Icons.favorite_rounded
|
||||
: Icons.favorite_border_rounded),
|
||||
const SizedBox(width: 10),
|
||||
const Text("Favorite")
|
||||
],
|
||||
),
|
||||
value: "favorite",
|
||||
),
|
||||
PopupMenuItem(
|
||||
child: Row(
|
||||
children: const [
|
||||
Icon(Icons.share_rounded),
|
||||
SizedBox(width: 10),
|
||||
Text("Share")
|
||||
],
|
||||
),
|
||||
value: "share",
|
||||
)
|
||||
];
|
||||
},
|
||||
onSelected: (value) {
|
||||
switch (value) {
|
||||
case "favorite":
|
||||
actionFavorite(isSaved);
|
||||
break;
|
||||
case "add-playlist":
|
||||
actionAddToPlaylist();
|
||||
break;
|
||||
case "remove-playlist":
|
||||
actionRemoveFromPlaylist();
|
||||
break;
|
||||
case "share":
|
||||
actionShare(track.value);
|
||||
break;
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
@ -98,6 +98,13 @@ final artistRelatedArtistsQuery =
|
||||
},
|
||||
);
|
||||
|
||||
final currentUserSavedTracksQuery = FutureProvider<List<Track>>((ref) {
|
||||
final spotify = ref.watch(spotifyProvider);
|
||||
return spotify.tracks.me.saved.all().then(
|
||||
(tracks) => tracks.map((e) => e.track!).toList(),
|
||||
);
|
||||
});
|
||||
|
||||
final playlistTracksQuery = FutureProvider.family<List<Track>, String>(
|
||||
(ref, id) {
|
||||
final spotify = ref.watch(spotifyProvider);
|
||||
|
Loading…
Reference in New Issue
Block a user