Skip to content

Commit

Permalink
fix: heart button showing when not logged in, wrong login redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Dec 9, 2022
1 parent 9465d92 commit 4dc26af
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 69 deletions.
4 changes: 3 additions & 1 deletion lib/components/player/player_actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:spotube/components/player/player_queue.dart';
import 'package:spotube/components/player/sibling_tracks_sheet.dart';
import 'package:spotube/components/shared/heart_button.dart';
import 'package:spotube/models/logger.dart';
import 'package:spotube/provider/auth_provider.dart';
import 'package:spotube/provider/downloader_provider.dart';
import 'package:spotube/provider/playback_provider.dart';
import 'package:spotube/utils/type_conversion_utils.dart';
Expand All @@ -33,6 +34,7 @@ class PlayerActions extends HookConsumerWidget {
final isInQueue =
downloader.inQueue.any((element) => element.id == playback.track?.id);
final localTracks = ref.watch(localTracksProvider).value;
final auth = ref.watch(authProvider);

final isDownloaded = useMemoized(() {
return localTracks?.any(
Expand Down Expand Up @@ -122,7 +124,7 @@ class PlayerActions extends HookConsumerWidget {
? () => downloader.addToQueue(playback.track!)
: null,
),
if (playback.track != null && !isLocalTrack)
if (playback.track != null && !isLocalTrack && auth.isLoggedIn)
TrackHeartButton(track: playback.track!),
...(extraActions ?? [])
],
Expand Down
4 changes: 3 additions & 1 deletion lib/components/shared/track_table/track_collection_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:spotube/components/shared/shimmers/shimmer_track_tile.dart';
import 'package:spotube/components/shared/page_window_title_bar.dart';
import 'package:spotube/components/shared/image/universal_image.dart';
import 'package:spotube/components/shared/track_table/tracks_table_view.dart';
import 'package:spotube/provider/auth_provider.dart';
import 'package:spotube/utils/type_conversion_utils.dart';
import 'package:spotube/hooks/use_custom_status_bar_color.dart';
import 'package:spotube/hooks/use_palette_color.dart';
Expand Down Expand Up @@ -55,6 +56,7 @@ class TrackCollectionView<T> extends HookConsumerWidget {

@override
Widget build(BuildContext context, ref) {
final auth = ref.watch(authProvider);
final color = usePaletteGenerator(
context,
titleImage,
Expand All @@ -69,7 +71,7 @@ class TrackCollectionView<T> extends HookConsumerWidget {
),
onPressed: onShare,
),
if (heartBtn != null) heartBtn!,
if (heartBtn != null && auth.isLoggedIn) heartBtn!,
PlatformIconButton(
tooltip: "Shuffle",
icon: Icon(
Expand Down
115 changes: 60 additions & 55 deletions lib/pages/artist/artist.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'package:spotube/hooks/use_breakpoint_value.dart';
import 'package:spotube/hooks/use_breakpoints.dart';
import 'package:spotube/models/current_playlist.dart';
import 'package:spotube/models/logger.dart';
import 'package:spotube/provider/auth_provider.dart';
import 'package:spotube/provider/playback_provider.dart';
import 'package:spotube/provider/spotify_provider.dart';
import 'package:spotube/services/queries/queries.dart';
Expand Down Expand Up @@ -53,6 +54,8 @@ class ArtistPage extends HookConsumerWidget {

final Playback playback = ref.watch(playbackProvider);

final auth = ref.watch(authProvider);

return SafeArea(
child: PlatformScaffold(
appBar: PageWindowTitleBar(
Expand Down Expand Up @@ -128,64 +131,66 @@ class ArtistPage extends HookConsumerWidget {
Row(
mainAxisSize: MainAxisSize.min,
children: [
HookBuilder(
builder: (context) {
final isFollowingQuery = useQuery(
job: Queries.artist.doIFollow(artistId),
externalData: spotify,
);

if (isFollowingQuery.isLoading ||
!isFollowingQuery.hasData) {
return const SizedBox(
height: 20,
width: 20,
child:
PlatformCircularProgressIndicator(),
if (auth.isLoggedIn)
HookBuilder(
builder: (context) {
final isFollowingQuery = useQuery(
job: Queries.artist.doIFollow(artistId),
externalData: spotify,
);
}

return PlatformFilledButton(
onPressed: () async {
try {
isFollowingQuery.data!
? await spotify.me.unfollow(
FollowingType.artist,
[artistId],
if (isFollowingQuery.isLoading ||
!isFollowingQuery.hasData) {
return const SizedBox(
height: 20,
width: 20,
child:
PlatformCircularProgressIndicator(),
);
}

return PlatformFilledButton(
onPressed: () async {
try {
isFollowingQuery.data!
? await spotify.me.unfollow(
FollowingType.artist,
[artistId],
)
: await spotify.me.follow(
FollowingType.artist,
[artistId],
);
await isFollowingQuery.refetch();
QueryBowl.of(context)
.getInfiniteQuery(
Queries.artist.followedByMe
.queryKey,
)
: await spotify.me.follow(
FollowingType.artist,
[artistId],
);
await isFollowingQuery.refetch();
QueryBowl.of(context)
.getInfiniteQuery(
Queries.artist.followedByMe
.queryKey,
)
?.refetch();
} catch (e, stack) {
logger.e(
"FollowButton.onPressed",
e,
stack,
);
} finally {
QueryBowl.of(context).refetchQueries([
Queries.artist
.doIFollow(artistId)
.queryKey,
]);
}
},
child: PlatformText(
isFollowingQuery.data!
? "Following"
: "Follow",
),
);
},
),
?.refetch();
} catch (e, stack) {
logger.e(
"FollowButton.onPressed",
e,
stack,
);
} finally {
QueryBowl.of(context)
.refetchQueries([
Queries.artist
.doIFollow(artistId)
.queryKey,
]);
}
},
child: PlatformText(
isFollowingQuery.data!
? "Following"
: "Follow",
),
);
},
),
PlatformIconButton(
icon: const Icon(Icons.share_rounded),
onPressed: () {
Expand Down
11 changes: 4 additions & 7 deletions lib/pages/desktop_login/desktop_login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class DesktopLoginPage extends HookConsumerWidget {
@override
Widget build(BuildContext context, ref) {
final breakpoint = useBreakpoints();
final textTheme = Theme.of(context).textTheme;

return SafeArea(
child: PlatformScaffold(
Expand All @@ -36,13 +35,11 @@ class DesktopLoginPage extends HookConsumerWidget {
width: MediaQuery.of(context).size.width *
(breakpoint <= Breakpoints.md ? .5 : .3),
),
PlatformText("Add your spotify credentials to get started",
style: breakpoint <= Breakpoints.md
? textTheme.headline5
: textTheme.headline4),
PlatformText(
PlatformText.subheading(
"Add your spotify credentials to get started",
),
PlatformText.label(
"Don't worry, any of your credentials won't be collected or shared with anyone",
style: Theme.of(context).textTheme.caption,
),
const SizedBox(height: 10),
TokenLoginForm(
Expand Down
25 changes: 20 additions & 5 deletions lib/pages/desktop_login/login_tutorial.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:introduction_screen/introduction_screen.dart';
import 'package:platform_ui/platform_ui.dart';
import 'package:spotube/components/desktop_login/login_form.dart';
Expand All @@ -16,6 +17,10 @@ class LoginTutorial extends ConsumerWidget {
final auth = ref.watch(authProvider);
final key = GlobalKey<State<IntroductionScreen>>();

final pageDecoration = PageDecoration(
bodyTextStyle: PlatformTheme.of(context).textTheme!.body!,
titleTextStyle: PlatformTheme.of(context).textTheme!.subheading!,
);
return PlatformScaffold(
appBar: PageWindowTitleBar(
hideWhenWindows: false,
Expand All @@ -28,6 +33,8 @@ class LoginTutorial extends ConsumerWidget {
),
body: IntroductionScreen(
key: key,
globalBackgroundColor:
PlatformTheme.of(context).scaffoldBackgroundColor,
overrideBack: PlatformFilledButton(
isSecondary: true,
child: const Center(child: PlatformText("Previous")),
Expand All @@ -52,6 +59,7 @@ class LoginTutorial extends ConsumerWidget {
),
pages: [
PageViewModel(
decoration: pageDecoration,
title: "Step 1",
image: Image.asset("assets/tutorial/step-1.png"),
bodyWidget: Wrap(
Expand All @@ -70,6 +78,7 @@ class LoginTutorial extends ConsumerWidget {
),
),
PageViewModel(
decoration: pageDecoration,
title: "Step 2",
image: Image.asset("assets/tutorial/step-2.png"),
bodyWidget: const PlatformText(
Expand All @@ -78,6 +87,7 @@ class LoginTutorial extends ConsumerWidget {
),
),
PageViewModel(
decoration: pageDecoration,
title: "Step 3",
image: Image.asset(
"assets/tutorial/step-3.png",
Expand All @@ -89,7 +99,7 @@ class LoginTutorial extends ConsumerWidget {
),
if (auth.isLoggedIn)
PageViewModel(
decoration: const PageDecoration(
decoration: pageDecoration.copyWith(
bodyAlignment: Alignment.center,
),
title: "Success🥳",
Expand All @@ -99,14 +109,19 @@ class LoginTutorial extends ConsumerWidget {
)
else
PageViewModel(
decoration: pageDecoration,
title: "Step 5",
bodyWidget: Column(
children: const [
PlatformText(
children: [
PlatformText.label(
"Paste the copied \"sp_dc\" and \"sp_key\" values in the respective fields",
),
SizedBox(height: 10),
TokenLoginForm(),
const SizedBox(height: 10),
TokenLoginForm(
onDone: () {
GoRouter.of(context).go("/");
},
),
],
),
),
Expand Down

0 comments on commit 4dc26af

Please sign in to comment.