Skip to content

Commit

Permalink
fix issue with refresh button showing when it shouldn't
Browse files Browse the repository at this point in the history
when the user is not logged in to an account, subscribe button will subscribe offline automatically
  • Loading branch information
lamarios committed Aug 3, 2024
1 parent d39a661 commit 43c1eee
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 36 deletions.
3 changes: 2 additions & 1 deletion lib/subscription_management/states/subscribe_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ class SubscribeButtonCubit extends Cubit<SubscribeButtonState> {
}

setOfflineSubscription(bool subscribed) async {
emit(state.copyWith(loading: true));
if (subscribed) {
final channel = await service.getChannel(state.channelId);
await db.addOfflineSubscription(OfflineSubscription(
channelId: state.channelId, channelName: channel.author));
} else {
await db.deleteOfflineSubscription(state.channelId);
}
emit(state.copyWith(isOfflineSubscribed: subscribed));
emit(state.copyWith(isOfflineSubscribed: subscribed, loading: false));
}

Future<void> onReady() async {
Expand Down
72 changes: 38 additions & 34 deletions lib/subscription_management/view/components/subscribe_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,46 +16,50 @@ class SubscribeButton extends StatelessWidget {
final cubit = context.read<SubscribeButtonCubit>();
final locals = AppLocalizations.of(context)!;

showModalBottomSheet(
context: context,
builder: (context) {
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (cubit.state.isLoggedIn)
TextButton(
onPressed: () async {
await cubit.setAccountSubscription(true);
if (context.mounted) {
Navigator.of(context).pop();
}
},
child: Text(locals.invidiousAccount)),
TextButton(
onPressed: () async {
await cubit.setOfflineSubscription(true);
if (context.mounted) {
Navigator.of(context).pop();
}
},
child: Text(locals.onDeviceSubscriptions)),
if (cubit.state.isLoggedIn)
if (cubit.state.isLoggedIn) {
showModalBottomSheet(
context: context,
builder: (context) {
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (cubit.state.isLoggedIn)
TextButton(
onPressed: () async {
await cubit.setAccountSubscription(true);
if (context.mounted) {
Navigator.of(context).pop();
}
},
child: Text(locals.invidiousAccount)),
TextButton(
onPressed: () async {
await Future.wait<void>([
cubit.setOfflineSubscription(true),
cubit.setAccountSubscription(true)
]);
await cubit.setOfflineSubscription(true);
if (context.mounted) {
Navigator.of(context).pop();
}
},
child: Text(locals.both)),
],
);
},
);
child: Text(locals.onDeviceSubscriptions)),
if (cubit.state.isLoggedIn)
TextButton(
onPressed: () async {
await Future.wait<void>([
cubit.setOfflineSubscription(true),
cubit.setAccountSubscription(true)
]);
if (context.mounted) {
Navigator.of(context).pop();
}
},
child: Text(locals.both)),
],
);
},
);
} else {
cubit.setOfflineSubscription(true);
}
}

@override
Expand Down
2 changes: 1 addition & 1 deletion lib/videos/views/components/video_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class VideoList<T extends IdedVideo> extends StatelessWidget {
: textTheme.bodyMedium,
)),
)
: items.isEmpty
: items.isEmpty && !state.loading
? FilledButton.tonal(
onPressed: cubit.refreshItems,
child: Text(locals.refresh))
Expand Down

0 comments on commit 43c1eee

Please sign in to comment.