diff --git a/lib/src/controllers/artist_detail_controller.dart b/lib/src/controllers/artist_detail_controller.dart index 8d6d96c5..fb33f16e 100644 --- a/lib/src/controllers/artist_detail_controller.dart +++ b/lib/src/controllers/artist_detail_controller.dart @@ -23,6 +23,7 @@ class ArtistDetailController extends GetxController { @override void onInit() { initArgs(); + checkFollowArtistStatus(); fetchApis(); super.onInit(); } @@ -49,6 +50,11 @@ class ArtistDetailController extends GetxController { return; } //TODO: Wait for API backend implementation + + userRepository.getCurrentUserFollowedArtist(artist().id).then((artist) { + return (artist == null || artist.id == null) ? liked(false) : liked(true); + }).then((artist) => debounce(liked, (_) => updateFollowArtist(), + time: Duration(seconds: 1))); } updateFollowArtist() { diff --git a/lib/src/pages/artist_detail_page.dart b/lib/src/pages/artist_detail_page.dart index fc38fc0c..c48a1308 100644 --- a/lib/src/pages/artist_detail_page.dart +++ b/lib/src/pages/artist_detail_page.dart @@ -67,12 +67,15 @@ class ArtistDetailPageView extends StatelessWidget { List buttons = []; - buttons.add(ActiveFlatButton( - icon: Icon(Icons.favorite), - label: 'like'.tr, - active: controller.liked.value, - onPressed: - (authService.currentUser().id == null) ? null : this._onTapLikeButton, + buttons.add(Obx( + () => ActiveFlatButton( + icon: Icon(Icons.favorite), + label: 'like'.tr, + active: controller.liked.value, + onPressed: (authService.currentUser().id == null) + ? null + : this._onTapLikeButton, + ), )); buttons.add(FlatButton( diff --git a/lib/src/repositories/user_repository.dart b/lib/src/repositories/user_repository.dart index 72e38d5b..dfbc128e 100644 --- a/lib/src/repositories/user_repository.dart +++ b/lib/src/repositories/user_repository.dart @@ -95,4 +95,13 @@ class UserRepository extends RestApiRepository { .get('/api/users/current/ratedSongs/$songId', null) .then((v) => v as String); } + + /// Gets currently logged in user's rating for a artist + Future getCurrentUserFollowedArtist(int artistId) { + return httpService + .get('/api/users/current/followedArtists/$artistId', null) + .then((v) => (v == null || v['artist'] == null) + ? null + : ArtistModel.fromJson(v['artist'])); + } }