Skip to content

Commit

Permalink
Merge pull request AppFlowy-IO#485 from AppFlowy-IO/fix_0.0.4_beta3
Browse files Browse the repository at this point in the history
Fix 0.0.4 beta3
  • Loading branch information
appflowy authored May 7, 2022
2 parents a298f7c + 18752e7 commit cb0a868
Show file tree
Hide file tree
Showing 46 changed files with 640 additions and 342 deletions.
1 change: 1 addition & 0 deletions frontend/app_flowy/assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
"textPlaceholder": "Empty"
},
"selectOption": {
"create": "Create",
"purpleColor": "Purple",
"pinkColor": "Pink",
"lightPinkColor": "Light Pink",
Expand Down
12 changes: 3 additions & 9 deletions frontend/app_flowy/lib/startup/deps_resolver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ import 'package:app_flowy/workspace/application/grid/prelude.dart';
import 'package:app_flowy/workspace/application/trash/prelude.dart';
import 'package:app_flowy/workspace/application/workspace/prelude.dart';
import 'package:app_flowy/workspace/application/edit_pannel/edit_pannel_bloc.dart';
import 'package:app_flowy/workspace/application/home/home_bloc.dart';
import 'package:app_flowy/workspace/application/view/prelude.dart';
import 'package:app_flowy/workspace/application/home/prelude.dart';
import 'package:app_flowy/workspace/application/menu/prelude.dart';
import 'package:app_flowy/user/application/prelude.dart';
import 'package:app_flowy/user/presentation/router.dart';
import 'package:app_flowy/workspace/presentation/home/home_stack.dart';
import 'package:app_flowy/workspace/presentation/home/menu/menu.dart';
import 'package:flowy_sdk/protobuf/flowy-folder-data-model/app.pb.dart';
import 'package:flowy_sdk/protobuf/flowy-folder-data-model/view.pb.dart';
import 'package:flowy_sdk/protobuf/flowy-grid-data-model/grid.pb.dart' show EditFieldContext;
import 'package:flowy_sdk/protobuf/flowy-grid/date_type_option.pb.dart';
import 'package:flowy_sdk/protobuf/flowy-grid/number_type_option.pb.dart';
import 'package:flowy_sdk/protobuf/flowy-user-data-model/user_profile.pb.dart';
Expand Down Expand Up @@ -44,7 +43,6 @@ void _resolveUserDeps(GetIt getIt) {
getIt.registerFactory<SignUpBloc>(() => SignUpBloc(getIt<AuthService>()));

getIt.registerFactory<SplashRoute>(() => SplashRoute());
getIt.registerFactory<HomeBloc>(() => HomeBloc());
getIt.registerFactory<EditPannelBloc>(() => EditPannelBloc());
getIt.registerFactory<SplashBloc>(() => SplashBloc());
getIt.registerLazySingleton<NetworkListener>(() => NetworkListener());
Expand All @@ -57,10 +55,6 @@ void _resolveHomeDeps(GetIt getIt) {
(user, _) => UserListener(user: user),
);

getIt.registerFactoryParam<HomeListenBloc, UserProfile, void>(
(user, _) => HomeListenBloc(getIt<UserListener>(param1: user)),
);

//
getIt.registerLazySingleton<HomeStackManager>(() => HomeStackManager());

Expand Down Expand Up @@ -201,8 +195,8 @@ void _resolveGridDeps(GetIt getIt) {
),
);

getIt.registerFactoryParam<FieldSwitcherBloc, SwitchFieldContext, void>(
(context, _) => FieldSwitcherBloc(context),
getIt.registerFactoryParam<FieldEditorPannelBloc, EditFieldContext, void>(
(context, _) => FieldEditorPannelBloc(context),
);

getIt.registerFactoryParam<DateTypeOptionBloc, DateTypeOption, void>(
Expand Down
72 changes: 54 additions & 18 deletions frontend/app_flowy/lib/user/application/user_listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,55 @@ import 'package:flowy_sdk/protobuf/flowy-user-data-model/user_profile.pb.dart';
import 'package:flowy_sdk/protobuf/flowy-user/dart_notification.pb.dart' as user;
import 'package:flowy_sdk/rust_stream.dart';

typedef UserProfileUpdatedNotifierValue = Either<UserProfile, FlowyError>;
typedef AuthNotifierValue = Either<Unit, FlowyError>;
typedef WorkspaceUpdatedNotifierValue = Either<List<Workspace>, FlowyError>;
typedef UserProfileNotifyValue = Either<UserProfile, FlowyError>;
typedef AuthNotifyValue = Either<Unit, FlowyError>;
typedef WorkspaceListNotifyValue = Either<List<Workspace>, FlowyError>;
typedef WorkspaceSettingNotifyValue = Either<CurrentWorkspaceSetting, FlowyError>;

class UserListener {
StreamSubscription<SubscribeObject>? _subscription;
final profileUpdatedNotifier = PublishNotifier<UserProfileUpdatedNotifierValue>();
final authDidChangedNotifier = PublishNotifier<AuthNotifierValue>();
final workspaceUpdatedNotifier = PublishNotifier<WorkspaceUpdatedNotifierValue>();
final _profileNotifier = PublishNotifier<UserProfileNotifyValue>();
final _authNotifier = PublishNotifier<AuthNotifyValue>();
final _workspaceListNotifier = PublishNotifier<WorkspaceListNotifyValue>();
final _workSettingNotifier = PublishNotifier<WorkspaceSettingNotifyValue>();

FolderNotificationParser? _workspaceParser;
UserNotificationParser? _userParser;
late UserProfile _user;
final UserProfile _user;
UserListener({
required UserProfile user,
}) : _user = user;

void start({
void Function(AuthNotifyValue)? onAuthChanged,
void Function(UserProfileNotifyValue)? onProfileUpdated,
void Function(WorkspaceListNotifyValue)? onWorkspaceListUpdated,
void Function(WorkspaceSettingNotifyValue)? onWorkspaceSettingUpdated,
}) {
_user = user;
}
if (onAuthChanged != null) {
_authNotifier.addListener(() {
onAuthChanged(_authNotifier.currentValue!);
});
}

if (onProfileUpdated != null) {
_profileNotifier.addListener(() {
onProfileUpdated(_profileNotifier.currentValue!);
});
}

if (onWorkspaceListUpdated != null) {
_workspaceListNotifier.addListener(() {
onWorkspaceListUpdated(_workspaceListNotifier.currentValue!);
});
}

if (onWorkspaceSettingUpdated != null) {
_workSettingNotifier.addListener(() {
onWorkspaceSettingUpdated(_workSettingNotifier.currentValue!);
});
}

void start() {
_workspaceParser = FolderNotificationParser(id: _user.token, callback: _notificationCallback);
_userParser = UserNotificationParser(id: _user.token, callback: _userNotificationCallback);
_subscription = RustStreamReceiver.listen((observable) {
Expand All @@ -44,9 +73,9 @@ class UserListener {
_workspaceParser = null;
_userParser = null;
await _subscription?.cancel();
profileUpdatedNotifier.dispose();
authDidChangedNotifier.dispose();
workspaceUpdatedNotifier.dispose();
_profileNotifier.dispose();
_authNotifier.dispose();
_workspaceListNotifier.dispose();
}

void _notificationCallback(FolderNotification ty, Either<Uint8List, FlowyError> result) {
Expand All @@ -55,16 +84,23 @@ class UserListener {
case FolderNotification.UserDeleteWorkspace:
case FolderNotification.WorkspaceListUpdated:
result.fold(
(payload) => workspaceUpdatedNotifier.value = left(RepeatedWorkspace.fromBuffer(payload).items),
(error) => workspaceUpdatedNotifier.value = right(error),
(payload) => _workspaceListNotifier.value = left(RepeatedWorkspace.fromBuffer(payload).items),
(error) => _workspaceListNotifier.value = right(error),
);
break;
case FolderNotification.WorkspaceSetting:
result.fold(
(payload) => _workSettingNotifier.value = left(CurrentWorkspaceSetting.fromBuffer(payload)),
(error) => _workSettingNotifier.value = right(error),
);
break;
case FolderNotification.UserUnauthorized:
result.fold(
(_) {},
(error) => authDidChangedNotifier.value = right(FlowyError.create()..code = ErrorCode.UserUnauthorized.value),
(error) => _authNotifier.value = right(FlowyError.create()..code = ErrorCode.UserUnauthorized.value),
);
break;

default:
break;
}
Expand All @@ -74,8 +110,8 @@ class UserListener {
switch (ty) {
case user.UserNotification.UserUnauthorized:
result.fold(
(payload) => profileUpdatedNotifier.value = left(UserProfile.fromBuffer(payload)),
(error) => profileUpdatedNotifier.value = right(error),
(payload) => _profileNotifier.value = left(UserProfile.fromBuffer(payload)),
(error) => _profileNotifier.value = right(error),
);
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class AppBloc extends Bloc<AppEvent, AppState> {

void _startListening() {
appListener.start(
viewsChanged: (result) {
onViewsChanged: (result) {
result.fold(
(views) {
if (!isClosed) {
Expand All @@ -51,7 +51,7 @@ class AppBloc extends Bloc<AppEvent, AppState> {
(error) => Log.error(error),
);
},
appUpdated: (app) {
onAppUpdated: (app) {
if (!isClosed) {
add(AppEvent.appDidUpdate(app));
}
Expand Down Expand Up @@ -97,7 +97,7 @@ class AppBloc extends Bloc<AppEvent, AppState> {

@override
Future<void> close() async {
await appListener.close();
await appListener.stop();
return super.close();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class AppListener {
required this.appId,
});

void start({ViewsDidChangeCallback? viewsChanged, AppDidUpdateCallback? appUpdated}) {
_viewsChanged = viewsChanged;
_updated = appUpdated;
void start({ViewsDidChangeCallback? onViewsChanged, AppDidUpdateCallback? onAppUpdated}) {
_viewsChanged = onViewsChanged;
_updated = onAppUpdated;
_parser = FolderNotificationParser(id: appId, callback: _bservableCallback);
_subscription = RustStreamReceiver.listen((observable) => _parser?.parse(observable));
}
Expand Down Expand Up @@ -60,7 +60,7 @@ class AppListener {
}
}

Future<void> close() async {
Future<void> stop() async {
_parser = null;
await _subscription?.cancel();
_viewsChanged = null;
Expand Down
31 changes: 15 additions & 16 deletions frontend/app_flowy/lib/workspace/application/doc/doc_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class DocumentBloc extends Bloc<DocumentEvent, DocumentState> {

@override
Future<void> close() async {
await listener.close();
await listener.stop();

if (_subscription != null) {
await _subscription?.cancel();
Expand All @@ -70,21 +70,20 @@ class DocumentBloc extends Bloc<DocumentEvent, DocumentState> {
}

Future<void> _initial(Initial value, Emitter<DocumentState> emit) async {
listener.deletedNotifier.addPublishListener((result) {
result.fold(
(view) => add(const DocumentEvent.deleted()),
(error) {},
);
});

listener.restoredNotifier.addPublishListener((result) {
result.fold(
(view) => add(const DocumentEvent.restore()),
(error) {},
);
});

listener.start();
listener.start(
onViewDeleted: (result) {
result.fold(
(view) => add(const DocumentEvent.deleted()),
(error) {},
);
},
onViewRestored: (result) {
result.fold(
(view) => add(const DocumentEvent.restore()),
(error) {},
);
},
);
final result = await service.openDocument(docId: view.id);
result.fold(
(block) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import 'package:app_flowy/workspace/application/grid/cell/cell_service.dart';
import 'dart:async';

import 'package:dartz/dartz.dart';
import 'package:flowy_sdk/log.dart';
import 'package:flowy_sdk/protobuf/flowy-grid/selection_type_option.pb.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'dart:async';

import 'package:app_flowy/workspace/application/grid/cell/cell_service.dart';

import 'select_option_service.dart';

part 'selection_editor_bloc.freezed.dart';
Expand All @@ -24,14 +28,19 @@ class SelectOptionEditorBloc extends Bloc<SelectOptionEditorEvent, SelectOptionE
_startListening();
},
didReceiveOptions: (_DidReceiveOptions value) {
final result = _makeOptions(state.filter, value.options);
emit(state.copyWith(
allOptions: value.options,
options: _makeOptions(state.filter, value.options),
options: result.options,
createOption: result.createOption,
selectedOptions: value.selectedOptions,
));
},
newOption: (_NewOption value) {
_createOption(value.optionName);
emit(state.copyWith(
filter: none(),
));
},
deleteOption: (_DeleteOption value) {
_deleteOption(value.option);
Expand Down Expand Up @@ -91,16 +100,37 @@ class SelectOptionEditorBloc extends Bloc<SelectOptionEditorEvent, SelectOptionE
}

void _filterOption(String optionName, Emitter<SelectOptionEditorState> emit) {
emit(state.copyWith(filter: optionName, options: _makeOptions(optionName, state.allOptions)));
final _MakeOptionResult result = _makeOptions(Some(optionName), state.allOptions);
emit(state.copyWith(
filter: Some(optionName),
options: result.options,
createOption: result.createOption,
));
}

List<SelectOption> _makeOptions(String filter, List<SelectOption> allOptions) {
_MakeOptionResult _makeOptions(Option<String> filter, List<SelectOption> allOptions) {
final List<SelectOption> options = List.from(allOptions);
if (filter.isNotEmpty) {
options.retainWhere((option) => option.name.toLowerCase().contains(filter.toLowerCase()));
}

return options;
Option<String> createOption = filter;

filter.foldRight(null, (filter, previous) {
if (filter.isNotEmpty) {
options.retainWhere((option) {
final name = option.name.toLowerCase();
final lFilter = filter.toLowerCase();

if (name == lFilter) {
createOption = none();
}

return name.contains(lFilter);
});
}
});

return _MakeOptionResult(
options: options,
createOption: createOption,
);
}

void _startListening() {
Expand Down Expand Up @@ -135,7 +165,8 @@ class SelectOptionEditorState with _$SelectOptionEditorState {
required List<SelectOption> options,
required List<SelectOption> allOptions,
required List<SelectOption> selectedOptions,
required String filter,
required Option<String> createOption,
required Option<String> filter,
}) = _SelectOptionEditorState;

factory SelectOptionEditorState.initial(GridSelectOptionCellContext context) {
Expand All @@ -144,7 +175,18 @@ class SelectOptionEditorState with _$SelectOptionEditorState {
options: data?.options ?? [],
allOptions: data?.options ?? [],
selectedOptions: data?.selectOptions ?? [],
filter: "",
createOption: none(),
filter: none(),
);
}
}

class _MakeOptionResult {
List<SelectOption> options;
Option<String> createOption;

_MakeOptionResult({
required this.options,
required this.createOption,
});
}
Loading

0 comments on commit cb0a868

Please sign in to comment.