mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-14 16:25:16 +00:00
fix: album, artist page not loading #1282
This commit is contained in:
parent
e6a20b5a16
commit
a9a1d4c9dc
@ -15,9 +15,9 @@ import 'package:spotube/utils/type_conversion_utils.dart';
|
||||
class AlbumPage extends HookConsumerWidget {
|
||||
final AlbumSimple album;
|
||||
const AlbumPage({
|
||||
Key? key,
|
||||
super.key,
|
||||
required this.album,
|
||||
}) : super(key: key);
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, ref) {
|
||||
@ -69,8 +69,9 @@ class AlbumPage extends HookConsumerWidget {
|
||||
shareUrl: album.externalUrls!.spotify!,
|
||||
isLiked: isLiked,
|
||||
onHeart: albumIsSaved.hasData
|
||||
? () {
|
||||
toggleAlbumLike.mutate(isLiked);
|
||||
? () async {
|
||||
await toggleAlbumLike.mutate(isLiked);
|
||||
return null;
|
||||
}
|
||||
: null,
|
||||
child: const TrackView(),
|
||||
|
@ -175,59 +175,4 @@ class CustomSpotifyEndpoints {
|
||||
);
|
||||
return SpotifyFriends.fromJson(jsonDecode(res.body));
|
||||
}
|
||||
|
||||
Future<Artist> artist({required String id}) async {
|
||||
final pathQuery = "$_baseUrl/artists/$id";
|
||||
|
||||
final res = await _client.get(
|
||||
Uri.parse(pathQuery),
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
if (accessToken.isNotEmpty) "authorization": "Bearer $accessToken",
|
||||
"accept": "application/json",
|
||||
},
|
||||
);
|
||||
final data = jsonDecode(res.body);
|
||||
|
||||
return Artist.fromJson(_purifyArtistResponse(data));
|
||||
}
|
||||
|
||||
Future<List<Artist>> relatedArtists({required String id}) async {
|
||||
final pathQuery = "$_baseUrl/artists/$id/related-artists";
|
||||
|
||||
final res = await _client.get(
|
||||
Uri.parse(pathQuery),
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
if (accessToken.isNotEmpty) "authorization": "Bearer $accessToken",
|
||||
"accept": "application/json",
|
||||
},
|
||||
);
|
||||
|
||||
final data = jsonDecode(res.body);
|
||||
|
||||
return List.castFrom<dynamic, Artist>(
|
||||
data["artists"]
|
||||
.map((artist) => Artist.fromJson(_purifyArtistResponse(artist)))
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _purifyArtistResponse(Map<String, dynamic> data) {
|
||||
if (data["popularity"] != null) {
|
||||
data["popularity"] = data["popularity"].toInt();
|
||||
}
|
||||
if (data["followers"]?["total"] != null) {
|
||||
data["followers"]["total"] = data["followers"]["total"].toInt();
|
||||
}
|
||||
if (data["images"] != null) {
|
||||
data["images"] = data["images"].map((e) {
|
||||
e["height"] = e["height"].toInt();
|
||||
e["width"] = e["width"].toInt();
|
||||
return e;
|
||||
}).toList();
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:spotify/spotify.dart';
|
||||
import 'package:spotube/hooks/spotify/use_spotify_infinite_query.dart';
|
||||
import 'package:spotube/hooks/spotify/use_spotify_query.dart';
|
||||
import 'package:spotube/provider/custom_spotify_endpoint_provider.dart';
|
||||
import 'package:spotube/provider/user_preferences/user_preferences_provider.dart';
|
||||
import 'package:spotube/services/wikipedia/wikipedia.dart';
|
||||
import 'package:wikipedia_api/wikipedia_api.dart';
|
||||
@ -16,10 +15,9 @@ class ArtistQueries {
|
||||
WidgetRef ref,
|
||||
String artist,
|
||||
) {
|
||||
final customSpotify = ref.watch(customSpotifyEndpointProvider);
|
||||
return useSpotifyQuery<Artist, dynamic>(
|
||||
"artist-profile/$artist",
|
||||
(spotify) => customSpotify.artist(id: artist),
|
||||
(spotify) => spotify.artists.get(artist),
|
||||
ref: ref,
|
||||
);
|
||||
}
|
||||
@ -127,11 +125,10 @@ class ArtistQueries {
|
||||
WidgetRef ref,
|
||||
String artist,
|
||||
) {
|
||||
final customSpotify = ref.watch(customSpotifyEndpointProvider);
|
||||
return useSpotifyQuery<Iterable<Artist>, dynamic>(
|
||||
"artist-related-artist-query/$artist",
|
||||
(spotify) {
|
||||
return customSpotify.relatedArtists(id: artist);
|
||||
return spotify.artists.relatedArtists(artist);
|
||||
},
|
||||
ref: ref,
|
||||
);
|
||||
|
25
pubspec.lock
25
pubspec.lock
@ -1118,10 +1118,10 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: http
|
||||
sha256: "759d1a329847dd0f39226c688d3e06a6b8679668e350e2891a6474f8b4bb8525"
|
||||
sha256: "761a297c042deedc1ffbb156d6e2af13886bb305c2a343a4d972504cd67dd938"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.0"
|
||||
version: "1.2.1"
|
||||
http_multi_server:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -1961,11 +1961,12 @@ packages:
|
||||
spotify:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: spotify
|
||||
sha256: e967c5e295792e9d38f4c5e9e60d7c2868ed9cb2a8fac2a67c75303f8395e374
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.12.0"
|
||||
path: "."
|
||||
ref: fix-spotify-precision
|
||||
resolved-ref: "1ddea720130203021a815253e37ebe5c06845dd2"
|
||||
url: "https://github.com/KRTirtho/spotify-dart.git"
|
||||
source: git
|
||||
version: "0.13.1"
|
||||
sqflite:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -2278,6 +2279,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.1.0"
|
||||
web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: web
|
||||
sha256: "1d9158c616048c38f712a6646e317a3426da10e884447626167240d45209cbad"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.5.0"
|
||||
web_socket_channel:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -2368,5 +2377,5 @@ packages:
|
||||
source: hosted
|
||||
version: "2.0.2"
|
||||
sdks:
|
||||
dart: ">=3.2.0 <4.0.0"
|
||||
dart: ">=3.3.0 <4.0.0"
|
||||
flutter: ">=3.13.0"
|
||||
|
@ -61,7 +61,7 @@ dependencies:
|
||||
hive_flutter: ^1.1.0
|
||||
hooks_riverpod: ^2.4.3
|
||||
html: ^0.15.1
|
||||
http: ^1.1.0
|
||||
http: ^1.2.0
|
||||
image_picker: ^1.0.4
|
||||
intl: ^0.18.0
|
||||
introduction_screen: ^3.0.2
|
||||
@ -89,7 +89,10 @@ dependencies:
|
||||
shared_preferences: ^2.2.2
|
||||
skeleton_text: ^3.0.1
|
||||
smtc_windows: ^0.1.1
|
||||
spotify: ^0.12.0
|
||||
spotify:
|
||||
git:
|
||||
url: https://github.com/KRTirtho/spotify-dart.git
|
||||
ref: fix-spotify-precision
|
||||
stroke_text: ^0.0.2
|
||||
system_theme: ^2.1.0
|
||||
titlebar_buttons: ^1.0.0
|
||||
@ -145,7 +148,6 @@ dev_dependencies:
|
||||
freezed: ^2.4.6
|
||||
|
||||
dependency_overrides:
|
||||
http: ^1.1.0
|
||||
system_tray: 2.0.2
|
||||
|
||||
flutter:
|
||||
|
Loading…
Reference in New Issue
Block a user