Skip to content

Commit

Permalink
Minor fixes and changes (#40)
Browse files Browse the repository at this point in the history
* refactor delete account

* fix permission denied error while sign out

* fix permission denied error while delete account
  • Loading branch information
cp-ishita-g authored Jul 19, 2024
1 parent e05ff9a commit e48ac19
Show file tree
Hide file tree
Showing 14 changed files with 122 additions and 51 deletions.
2 changes: 2 additions & 0 deletions app/assets/locales/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@
"settings_other_option_contact_support_text": "Contact support",
"settings_other_option_about_us_text": "About us",
"settings_other_option_sign_out_text": "Sign out",
"settings_sign_out_alert_title": "See you soon!",
"settings_sign_out_alert_description": "Are you sure you want to sign out?",

"message_add_member_to_send_message_title": "Add members to send messages",
"message_add_member_to_send_message_subtitle": "At least one member needs to join your space to be able to chat.",
Expand Down
9 changes: 8 additions & 1 deletion app/lib/ui/components/profile_picture.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class ProfileImage extends StatefulWidget {
final String firstLetter;
final TextStyle? style;
final Color? backgroundColor;
final Color? borderColor;

const ProfileImage({
super.key,
Expand All @@ -18,6 +19,7 @@ class ProfileImage extends StatefulWidget {
required this.firstLetter,
this.style,
this.backgroundColor,
this.borderColor,
});

@override
Expand All @@ -42,7 +44,12 @@ class _ProfileImageState extends State<ProfileImage> {
fit: BoxFit.cover,
)
: Container(
color: widget.backgroundColor ?? context.colorScheme.containerInverseHigh,
decoration: BoxDecoration(
color: widget.backgroundColor ??
context.colorScheme.containerInverseHigh,
border: Border.all(width: 0.5, color: widget.borderColor ?? Colors.transparent),
borderRadius: BorderRadius.circular(widget.size / 2),
),
child: Center(
child: Text(
widget.firstLetter,
Expand Down
37 changes: 29 additions & 8 deletions app/lib/ui/flow/home/components/home_top_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,20 @@ class _HomeTopBarState extends State<HomeTopBar> with TickerProviderStateMixin {

late AnimationController _animationController;
late Animation<double> _animation;
late AnimationController _buttonController;

@override
void initState() {
super.initState();
_animationController = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 500),
duration: const Duration(milliseconds: 150),
);

_buttonController = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 300),
upperBound: 0.5,
);

_animation = CurvedAnimation(
Expand All @@ -57,14 +64,23 @@ class _HomeTopBarState extends State<HomeTopBar> with TickerProviderStateMixin {
@override
void dispose() {
_animationController.dispose();
_buttonController.dispose();
super.dispose();
}

void performAnimation() {
if (expand) {
_animationController.forward();
} else {
_animationController.reverse();
_animationController.reverse(from: 1.0).orCancel;
}
}

void performArrowButtonAnimation() {
if (expand) {
_buttonController.reverse(from: 0.5);
} else {
_buttonController.forward(from: 0.0);
}
}

Expand Down Expand Up @@ -145,6 +161,7 @@ class _HomeTopBarState extends State<HomeTopBar> with TickerProviderStateMixin {
setState(() {
expand = !expand;
performAnimation();
performArrowButtonAnimation();
});
},
child: Container(
Expand Down Expand Up @@ -174,12 +191,13 @@ class _HomeTopBarState extends State<HomeTopBar> with TickerProviderStateMixin {
const AppProgressIndicator(
size: AppProgressIndicatorSize.small)
] else ...[
Icon(
expand
? Icons.keyboard_arrow_up_rounded
: Icons.keyboard_arrow_down_rounded,
color: context.colorScheme.textPrimary,
),
RotationTransition(
turns: Tween(begin: 0.0, end: 1.0).animate(_buttonController),
child: Icon(
Icons.keyboard_arrow_up_rounded,
color: context.colorScheme.textPrimary,
),
)
],
],
),
Expand Down Expand Up @@ -258,6 +276,9 @@ class _HomeTopBarState extends State<HomeTopBar> with TickerProviderStateMixin {
setState(() {
selectedIndex = index;
widget.onSpaceItemTap(space);
expand = false;
performAnimation();
performArrowButtonAnimation();
});
},
child: Container(
Expand Down
8 changes: 5 additions & 3 deletions app/lib/ui/flow/home/home_screen_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final homeViewStateProvider =
StateNotifierProvider.autoDispose<HomeViewNotifier, HomeViewState>(
(ref) => HomeViewNotifier(
ref.read(spaceServiceProvider),
ref.read(currentUserSessionJsonPod.notifier),
ref.read(currentSpaceId.notifier),
ref.read(permissionServiceProvider),
ref.read(lastBatteryDialogPod.notifier),
),
Expand Down Expand Up @@ -45,19 +45,21 @@ class HomeViewNotifier extends StateNotifier<HomeViewState> {

final sortedSpaces = spaces.toList();

if (currentSpaceId != null) {
if (currentSpaceId?.isNotEmpty ?? false) {
final selectedSpaceIndex = sortedSpaces
.indexWhere((space) => space.space.id == currentSpaceId);
if (selectedSpaceIndex > -1) {
final selectedSpace = sortedSpaces.removeAt(selectedSpaceIndex);
sortedSpaces.insert(0, selectedSpace);
updateSelectedSpace(selectedSpace);
}
}

state = state.copyWith(loading: false, spaceList: sortedSpaces);

if (currentSpaceId != null && sortedSpaces.isNotEmpty) {
if ((currentSpaceId?.isEmpty ?? false) && sortedSpaces.isNotEmpty) {
final selectedSpace = sortedSpaces.first;
currentSpaceId = selectedSpace.space.id;
updateSelectedSpace(selectedSpace);
}
} catch (error, stack) {
Expand Down
22 changes: 12 additions & 10 deletions app/lib/ui/flow/intro/intro_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,19 @@ class _IntroScreenState extends ConsumerState<IntroScreen> {
setState(() {});
},
)),
SmoothPageIndicator(
controller: _controller,
count: _items.length,
effect: ExpandingDotsEffect(
expansionFactor: 4,
dotHeight: 8,
dotWidth: 8,
dotColor: context.colorScheme.containerHigh,
activeDotColor: context.colorScheme.primary,
if (_items.isNotEmpty) ...[
SmoothPageIndicator(
controller: _controller,
count: _items.length,
effect: ExpandingDotsEffect(
expansionFactor: 4,
dotHeight: 8,
dotWidth: 8,
dotColor: context.colorScheme.containerHigh,
activeDotColor: context.colorScheme.primary,
),
),
),
],
const SizedBox(height: 60),
BottomStickyOverlay(
child: PrimaryButton(
Expand Down
10 changes: 6 additions & 4 deletions app/lib/ui/flow/setting/profile/profile_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ class _ProfileScreenState extends ConsumerState<ProfileScreen> {
const SizedBox(height: 16),
_textFields(
context, context.l10n.edit_profile_phone_title, state.phone,
enabled: state.enablePhone),
enabled: state.enablePhone, isPhoneNumber: true),
],
),
_deleteAccountButton(context),
_deleteAccountButton(context, state),
],
);
}
Expand Down Expand Up @@ -254,7 +254,7 @@ class _ProfileScreenState extends ConsumerState<ProfileScreen> {

Widget _textFields(
BuildContext context, String title, TextEditingController controller,
{bool enabled = true}) {
{bool enabled = true, bool isPhoneNumber = false}) {
return AppTextField(
controller: controller,
label: title,
Expand All @@ -263,10 +263,11 @@ class _ProfileScreenState extends ConsumerState<ProfileScreen> {
),
enabled: enabled,
onChanged: (text) => notifier.onChange(),
keyboardType: isPhoneNumber ? TextInputType.number : TextInputType.name,
);
}

Widget _deleteAccountButton(BuildContext context) {
Widget _deleteAccountButton(BuildContext context, EditProfileViewState state) {
return BottomStickyOverlay(
child: PrimaryButton(
context.l10n.edit_profile_delete_account_title,
Expand All @@ -275,6 +276,7 @@ class _ProfileScreenState extends ConsumerState<ProfileScreen> {
showIcon: true,
foreground: context.colorScheme.alert,
background: context.colorScheme.containerLow,
progress: state.deletingAccount,
onPressed: () {
showConfirmation(
context,
Expand Down
12 changes: 6 additions & 6 deletions app/lib/ui/flow/setting/profile/profile_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ class EditProfileViewNotifier extends StateNotifier<EditProfileViewState> {
lastName: TextEditingController(text: user?.last_name),
email: TextEditingController(text: user?.email),
phone: TextEditingController(text: user?.phone),
enableEmail: user?.auth_type == LOGIN_TYPE_GOOGLE,
enablePhone: user?.auth_type == LOGIN_TYPE_PHONE,
enableEmail: user?.auth_type == LOGIN_TYPE_PHONE,
enablePhone: user?.auth_type == LOGIN_TYPE_GOOGLE,
profileUrl: user?.profile_image ?? '',
));

void deleteAccount() {
void deleteAccount() async {
try {
state = state.copyWith(deletingAccount: true);
spaceService.deleteUserSpaces();
authService.deleteUser();
state = state.copyWith(deletingAccount: true, accountDeleted: true);
await spaceService.deleteUserSpaces();
await authService.deleteAccount(currentUserId: user?.id);
state = state.copyWith(deletingAccount: false, accountDeleted: true);
locationManager.stopService();
} catch (error, stack) {
logger.e(
Expand Down
16 changes: 12 additions & 4 deletions app/lib/ui/flow/setting/setting_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:yourspace_flutter/ui/components/resume_detector.dart';
import 'package:yourspace_flutter/ui/flow/setting/setting_view_model.dart';

import '../../../gen/assets.gen.dart';
import '../../components/alert.dart';

class SettingScreen extends ConsumerStatefulWidget {
const SettingScreen({super.key});
Expand All @@ -37,7 +38,6 @@ class _SettingScreenState extends ConsumerState<SettingScreen> {
title: context.l10n.settings_title,
body: ResumeDetector(
onResume: () {
notifier.getUser();
notifier.getUserSpace();
}, child: _body(context, state)),
);
Expand Down Expand Up @@ -81,7 +81,7 @@ class _SettingScreenState extends ConsumerState<SettingScreen> {
const SizedBox(height: 16),
Container(
decoration: BoxDecoration(
color: context.colorScheme.containerLowOnSurface,
color: context.colorScheme.containerNormal,
borderRadius: BorderRadius.circular(16),
),
padding: const EdgeInsets.all(16),
Expand All @@ -91,7 +91,9 @@ class _SettingScreenState extends ConsumerState<SettingScreen> {
profileImageUrl: profileImageUrl,
firstLetter: firstLetter,
style: AppTextStyle.header3
.copyWith(color: context.colorScheme.textPrimaryDark),
.copyWith(color: context.colorScheme.textPrimary),
backgroundColor: context.colorScheme.containerHigh,
borderColor: context.colorScheme.textSecondary,
),
const SizedBox(width: 16),
Text(
Expand Down Expand Up @@ -220,7 +222,13 @@ class _SettingScreenState extends ConsumerState<SettingScreen> {
title: context.l10n.settings_other_option_sign_out_text,
icon: Assets.images.icSignOut,
onTap: () {
notifier.signOut();
showConfirmation(
context,
confirmBtnText: context.l10n.settings_other_option_sign_out_text,
title: context.l10n.settings_sign_out_alert_title,
message: context.l10n.settings_sign_out_alert_description,
onConfirm: () => notifier.signOut(),
);
}),
],
);
Expand Down
18 changes: 17 additions & 1 deletion app/lib/ui/flow/setting/setting_view_model.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:data/api/auth/api_user_service.dart';
import 'package:data/api/auth/auth_models.dart';
import 'package:data/api/space/space_models.dart';
Expand Down Expand Up @@ -25,16 +27,25 @@ class SettingViewNotifier extends StateNotifier<SettingViewState> {
final AuthService authService;
final ApiUserService userService;
final ApiUser? user;
late StreamSubscription<ApiUser?>? _userSubscription;

SettingViewNotifier(this.spaceService, this.authService, this.userService, this.user)
: super(const SettingViewState()) {
getUser();
getUserSpace();
}

@override
void dispose() {
cancelSubscriptions();
super.dispose();
}

void getUser() {
state = state.copyWith(currentUser: user);
authService.getUserStream().listen((user) {
_userSubscription = authService
.getUserStream(currentUserId: state.currentUser?.id ?? '')
.listen((user) {
state = state.copyWith(currentUser: user);
});
}
Expand All @@ -58,6 +69,7 @@ class SettingViewNotifier extends StateNotifier<SettingViewState> {
void signOut() async {
try {
state = state.copyWith(signingOut: true);
cancelSubscriptions();
await userService.signOut();
state = state.copyWith(signingOut: false, logOut: true);
} catch (error, stack) {
Expand All @@ -69,6 +81,10 @@ class SettingViewNotifier extends StateNotifier<SettingViewState> {
);
}
}

void cancelSubscriptions() {
_userSubscription?.cancel();
}
}

@freezed
Expand Down
Loading

0 comments on commit e48ac19

Please sign in to comment.