fix: fix merge from main

This commit is contained in:
Ian Su 2022-07-22 00:54:11 +08:00
parent 89644e88da
commit 1a887979c4
5 changed files with 25 additions and 17 deletions

View file

@ -34,6 +34,14 @@ class MenuUserBloc extends Bloc<MenuUserEvent, MenuUserState> {
didReceiveUserProfile: (UserProfilePB newUserProfile) { didReceiveUserProfile: (UserProfilePB newUserProfile) {
emit(state.copyWith(userProfile: newUserProfile)); emit(state.copyWith(userProfile: newUserProfile));
}, },
updateUserName: (String name) {
_userService.updateUserProfile(name: name).then((result) {
result.fold(
(l) => null,
(err) => Log.error(err),
);
});
},
); );
}); });
} }

View file

@ -10,7 +10,7 @@ part 'settings_dialog_bloc.freezed.dart';
class SettingsDialogBloc extends Bloc<SettingsDialogEvent, SettingsDialogState> { class SettingsDialogBloc extends Bloc<SettingsDialogEvent, SettingsDialogState> {
final UserListener _userListener; final UserListener _userListener;
final UserProfile userProfile; final UserProfilePB userProfile;
SettingsDialogBloc(this.userProfile) SettingsDialogBloc(this.userProfile)
: _userListener = UserListener(userProfile: userProfile), : _userListener = UserListener(userProfile: userProfile),
@ -20,7 +20,7 @@ class SettingsDialogBloc extends Bloc<SettingsDialogEvent, SettingsDialogState>
initial: () async { initial: () async {
_userListener.start(onProfileUpdated: _profileUpdated); _userListener.start(onProfileUpdated: _profileUpdated);
}, },
didReceiveUserProfile: (UserProfile newUserProfile) { didReceiveUserProfile: (UserProfilePB newUserProfile) {
emit(state.copyWith(userProfile: newUserProfile)); emit(state.copyWith(userProfile: newUserProfile));
}, },
setViewIndex: (int viewIndex) { setViewIndex: (int viewIndex) {
@ -36,7 +36,7 @@ class SettingsDialogBloc extends Bloc<SettingsDialogEvent, SettingsDialogState>
super.close(); super.close();
} }
void _profileUpdated(Either<UserProfile, FlowyError> userProfileOrFailed) { void _profileUpdated(Either<UserProfilePB, FlowyError> userProfileOrFailed) {
userProfileOrFailed.fold( userProfileOrFailed.fold(
(newUserProfile) => add(SettingsDialogEvent.didReceiveUserProfile(newUserProfile)), (newUserProfile) => add(SettingsDialogEvent.didReceiveUserProfile(newUserProfile)),
(err) => Log.error(err), (err) => Log.error(err),
@ -47,19 +47,19 @@ class SettingsDialogBloc extends Bloc<SettingsDialogEvent, SettingsDialogState>
@freezed @freezed
class SettingsDialogEvent with _$SettingsDialogEvent { class SettingsDialogEvent with _$SettingsDialogEvent {
const factory SettingsDialogEvent.initial() = _Initial; const factory SettingsDialogEvent.initial() = _Initial;
const factory SettingsDialogEvent.didReceiveUserProfile(UserProfile newUserProfile) = _DidReceiveUserProfile; const factory SettingsDialogEvent.didReceiveUserProfile(UserProfilePB newUserProfile) = _DidReceiveUserProfile;
const factory SettingsDialogEvent.setViewIndex(int index) = _SetViewIndex; const factory SettingsDialogEvent.setViewIndex(int index) = _SetViewIndex;
} }
@freezed @freezed
class SettingsDialogState with _$SettingsDialogState { class SettingsDialogState with _$SettingsDialogState {
const factory SettingsDialogState({ const factory SettingsDialogState({
required UserProfile userProfile, required UserProfilePB userProfile,
required Either<Unit, String> successOrFailure, required Either<Unit, String> successOrFailure,
required int viewIndex, required int viewIndex,
}) = _SettingsDialogState; }) = _SettingsDialogState;
factory SettingsDialogState.initial(UserProfile userProfile) => SettingsDialogState( factory SettingsDialogState.initial(UserProfilePB userProfile) => SettingsDialogState(
userProfile: userProfile, userProfile: userProfile,
successOrFailure: left(unit), successOrFailure: left(unit),
viewIndex: 0, viewIndex: 0,

View file

@ -12,7 +12,7 @@ part 'settings_user_bloc.freezed.dart';
class SettingsUserViewBloc extends Bloc<SettingsUserEvent, SettingsUserState> { class SettingsUserViewBloc extends Bloc<SettingsUserEvent, SettingsUserState> {
final UserService _userService; final UserService _userService;
final UserListener _userListener; final UserListener _userListener;
final UserProfile userProfile; final UserProfilePB userProfile;
SettingsUserViewBloc(this.userProfile) SettingsUserViewBloc(this.userProfile)
: _userListener = UserListener(userProfile: userProfile), : _userListener = UserListener(userProfile: userProfile),
@ -24,7 +24,7 @@ class SettingsUserViewBloc extends Bloc<SettingsUserEvent, SettingsUserState> {
_userListener.start(onProfileUpdated: _profileUpdated); _userListener.start(onProfileUpdated: _profileUpdated);
await _initUser(); await _initUser();
}, },
didReceiveUserProfile: (UserProfile newUserProfile) { didReceiveUserProfile: (UserProfilePB newUserProfile) {
emit(state.copyWith(userProfile: newUserProfile)); emit(state.copyWith(userProfile: newUserProfile));
}, },
updateUserName: (String name) { updateUserName: (String name) {
@ -50,7 +50,7 @@ class SettingsUserViewBloc extends Bloc<SettingsUserEvent, SettingsUserState> {
result.fold((l) => null, (error) => Log.error(error)); result.fold((l) => null, (error) => Log.error(error));
} }
void _profileUpdated(Either<UserProfile, FlowyError> userProfileOrFailed) { void _profileUpdated(Either<UserProfilePB, FlowyError> userProfileOrFailed) {
userProfileOrFailed.fold( userProfileOrFailed.fold(
(newUserProfile) => add(SettingsUserEvent.didReceiveUserProfile(newUserProfile)), (newUserProfile) => add(SettingsUserEvent.didReceiveUserProfile(newUserProfile)),
(err) => Log.error(err), (err) => Log.error(err),
@ -62,17 +62,17 @@ class SettingsUserViewBloc extends Bloc<SettingsUserEvent, SettingsUserState> {
class SettingsUserEvent with _$SettingsUserEvent { class SettingsUserEvent with _$SettingsUserEvent {
const factory SettingsUserEvent.initial() = _Initial; const factory SettingsUserEvent.initial() = _Initial;
const factory SettingsUserEvent.updateUserName(String name) = _UpdateUserName; const factory SettingsUserEvent.updateUserName(String name) = _UpdateUserName;
const factory SettingsUserEvent.didReceiveUserProfile(UserProfile newUserProfile) = _DidReceiveUserProfile; const factory SettingsUserEvent.didReceiveUserProfile(UserProfilePB newUserProfile) = _DidReceiveUserProfile;
} }
@freezed @freezed
class SettingsUserState with _$SettingsUserState { class SettingsUserState with _$SettingsUserState {
const factory SettingsUserState({ const factory SettingsUserState({
required UserProfile userProfile, required UserProfilePB userProfile,
required Either<Unit, String> successOrFailure, required Either<Unit, String> successOrFailure,
}) = _SettingsUserState; }) = _SettingsUserState;
factory SettingsUserState.initial(UserProfile userProfile) => SettingsUserState( factory SettingsUserState.initial(UserProfilePB userProfile) => SettingsUserState(
userProfile: userProfile, userProfile: userProfile,
successOrFailure: left(unit), successOrFailure: left(unit),
); );

View file

@ -6,17 +6,17 @@ import 'package:app_flowy/workspace/presentation/settings/widgets/settings_langu
import 'package:app_flowy/workspace/presentation/settings/widgets/settings_user_view.dart'; import 'package:app_flowy/workspace/presentation/settings/widgets/settings_user_view.dart';
import 'package:app_flowy/workspace/presentation/settings/widgets/settings_menu.dart'; import 'package:app_flowy/workspace/presentation/settings/widgets/settings_menu.dart';
import 'package:app_flowy/workspace/application/settings/settings_dialog_bloc.dart'; import 'package:app_flowy/workspace/application/settings/settings_dialog_bloc.dart';
import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfile; import 'package:flowy_sdk/protobuf/flowy-user/user_profile.pb.dart';
import 'package:easy_localization/easy_localization.dart'; import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
class SettingsDialog extends StatelessWidget { class SettingsDialog extends StatelessWidget {
final UserProfile user; final UserProfilePB user;
SettingsDialog(this.user, {Key? key}) : super(key: ValueKey(user.id)); SettingsDialog(this.user, {Key? key}) : super(key: ValueKey(user.id));
Widget getSettingsView(int index, UserProfile user) { Widget getSettingsView(int index, UserProfilePB user) {
final List<Widget> settingsViews = [ final List<Widget> settingsViews = [
const SettingsAppearanceView(), const SettingsAppearanceView(),
const SettingsLanguageView(), const SettingsLanguageView(),

View file

@ -2,10 +2,10 @@ import 'package:app_flowy/startup/startup.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:app_flowy/workspace/application/user/settings_user_bloc.dart'; import 'package:app_flowy/workspace/application/user/settings_user_bloc.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart' show UserProfile; import 'package:flowy_sdk/protobuf/flowy-user/user_profile.pb.dart';
class SettingsUserView extends StatelessWidget { class SettingsUserView extends StatelessWidget {
final UserProfile user; final UserProfilePB user;
SettingsUserView(this.user, {Key? key}) : super(key: ValueKey(user.id)); SettingsUserView(this.user, {Key? key}) : super(key: ValueKey(user.id));
@override @override