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/Auth.dart';
|
||||||
import 'package:spotube/provider/Playback.dart';
|
import 'package:spotube/provider/Playback.dart';
|
||||||
import 'package:spotube/provider/SpotifyDI.dart';
|
import 'package:spotube/provider/SpotifyDI.dart';
|
||||||
|
import 'package:spotube/provider/SpotifyRequests.dart';
|
||||||
|
|
||||||
class PlayerActions extends HookConsumerWidget {
|
class PlayerActions extends HookConsumerWidget {
|
||||||
final MainAxisAlignment mainAxisAlignment;
|
final MainAxisAlignment mainAxisAlignment;
|
||||||
@ -51,6 +52,10 @@ class PlayerActions extends HookConsumerWidget {
|
|||||||
logger.e("FavoriteButton.onPressed", e, stack);
|
logger.e("FavoriteButton.onPressed", e, stack);
|
||||||
} finally {
|
} finally {
|
||||||
update();
|
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/services.dart';
|
||||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:spotube/components/Shared/HeartButton.dart';
|
import 'package:spotube/components/Shared/HeartButton.dart';
|
||||||
import 'package:spotube/components/Shared/TrackCollectionView.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/Auth.dart';
|
||||||
import 'package:spotube/provider/Playback.dart';
|
import 'package:spotube/provider/Playback.dart';
|
||||||
import 'package:spotube/provider/SpotifyDI.dart';
|
import 'package:spotube/provider/SpotifyDI.dart';
|
||||||
|
import 'package:spotube/provider/SpotifyRequests.dart';
|
||||||
|
|
||||||
class TrackTile extends HookConsumerWidget {
|
class TrackTile extends HookConsumerWidget {
|
||||||
final Playback playback;
|
final Playback playback;
|
||||||
@ -41,6 +42,13 @@ class TrackTile extends HookConsumerWidget {
|
|||||||
final spotify = ref.watch(spotifyProvider);
|
final spotify = ref.watch(spotifyProvider);
|
||||||
final update = useForceUpdate();
|
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 {
|
final actionFavorite = useCallback((bool isLiked) async {
|
||||||
try {
|
try {
|
||||||
isLiked
|
isLiked
|
||||||
@ -50,6 +58,8 @@ class TrackTile extends HookConsumerWidget {
|
|||||||
logger.e("FavoriteButton.onPressed", e, stack);
|
logger.e("FavoriteButton.onPressed", e, stack);
|
||||||
} finally {
|
} finally {
|
||||||
update();
|
update();
|
||||||
|
ref.refresh(currentUserSavedTracksQuery);
|
||||||
|
ref.refresh(playlistTracksQuery("user-liked-tracks"));
|
||||||
}
|
}
|
||||||
}, [track.value.id, spotify]);
|
}, [track.value.id, spotify]);
|
||||||
|
|
||||||
@ -229,78 +239,74 @@ class TrackTile extends HookConsumerWidget {
|
|||||||
Text(duration),
|
Text(duration),
|
||||||
],
|
],
|
||||||
const SizedBox(width: 10),
|
const SizedBox(width: 10),
|
||||||
FutureBuilder<bool>(
|
PopupMenuButton(
|
||||||
future: spotify.tracks.me.containsOne(track.value.id!),
|
icon: const Icon(Icons.more_horiz_rounded),
|
||||||
builder: (context, snapshot) {
|
itemBuilder: (context) {
|
||||||
return PopupMenuButton(
|
return [
|
||||||
icon: const Icon(Icons.more_horiz_rounded),
|
if (auth.isLoggedIn)
|
||||||
itemBuilder: (context) {
|
PopupMenuItem(
|
||||||
return [
|
child: Row(
|
||||||
if (auth.isLoggedIn)
|
children: const [
|
||||||
PopupMenuItem(
|
Icon(Icons.add_box_rounded),
|
||||||
child: Row(
|
SizedBox(width: 10),
|
||||||
children: const [
|
Text("Add to Playlist"),
|
||||||
Icon(Icons.add_box_rounded),
|
],
|
||||||
SizedBox(width: 10),
|
),
|
||||||
Text("Add to Playlist"),
|
value: "add-playlist",
|
||||||
],
|
),
|
||||||
),
|
if (userPlaylist && auth.isLoggedIn)
|
||||||
value: "add-playlist",
|
PopupMenuItem(
|
||||||
),
|
child: Row(
|
||||||
if (userPlaylist && auth.isLoggedIn)
|
children: const [
|
||||||
PopupMenuItem(
|
Icon(Icons.remove_circle_outline_rounded),
|
||||||
child: Row(
|
SizedBox(width: 10),
|
||||||
children: const [
|
Text("Remove from Playlist"),
|
||||||
Icon(Icons.remove_circle_outline_rounded),
|
],
|
||||||
SizedBox(width: 10),
|
),
|
||||||
Text("Remove from Playlist"),
|
value: "remove-playlist",
|
||||||
],
|
),
|
||||||
),
|
if (auth.isLoggedIn)
|
||||||
value: "remove-playlist",
|
PopupMenuItem(
|
||||||
),
|
child: Row(
|
||||||
if (auth.isLoggedIn)
|
children: [
|
||||||
PopupMenuItem(
|
Icon(isSaved
|
||||||
child: Row(
|
? Icons.favorite_rounded
|
||||||
children: [
|
: Icons.favorite_border_rounded),
|
||||||
Icon(snapshot.data == true
|
const SizedBox(width: 10),
|
||||||
? Icons.favorite_rounded
|
const Text("Favorite")
|
||||||
: Icons.favorite_border_rounded),
|
],
|
||||||
const SizedBox(width: 10),
|
),
|
||||||
const Text("Favorite")
|
value: "favorite",
|
||||||
],
|
),
|
||||||
),
|
PopupMenuItem(
|
||||||
value: "favorite",
|
child: Row(
|
||||||
),
|
children: const [
|
||||||
PopupMenuItem(
|
Icon(Icons.share_rounded),
|
||||||
child: Row(
|
SizedBox(width: 10),
|
||||||
children: const [
|
Text("Share")
|
||||||
Icon(Icons.share_rounded),
|
],
|
||||||
SizedBox(width: 10),
|
),
|
||||||
Text("Share")
|
value: "share",
|
||||||
],
|
)
|
||||||
),
|
];
|
||||||
value: "share",
|
},
|
||||||
)
|
onSelected: (value) {
|
||||||
];
|
switch (value) {
|
||||||
},
|
case "favorite":
|
||||||
onSelected: (value) {
|
actionFavorite(isSaved);
|
||||||
switch (value) {
|
break;
|
||||||
case "favorite":
|
case "add-playlist":
|
||||||
actionFavorite(snapshot.data == true);
|
actionAddToPlaylist();
|
||||||
break;
|
break;
|
||||||
case "add-playlist":
|
case "remove-playlist":
|
||||||
actionAddToPlaylist();
|
actionRemoveFromPlaylist();
|
||||||
break;
|
break;
|
||||||
case "remove-playlist":
|
case "share":
|
||||||
actionRemoveFromPlaylist();
|
actionShare(track.value);
|
||||||
break;
|
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>(
|
final playlistTracksQuery = FutureProvider.family<List<Track>, String>(
|
||||||
(ref, id) {
|
(ref, id) {
|
||||||
final spotify = ref.watch(spotifyProvider);
|
final spotify = ref.watch(spotifyProvider);
|
||||||
|
Loading…
Reference in New Issue
Block a user