Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

feat: optimize share section and share tab logic (#8001)

Lucasd3566e303d0d
diff --git a/frontend/appflowy_flutter/assets/test/workspaces/database/v069.afdb b/frontend/appflowy_flutter/assets/test/workspaces/database/v069.afdb
index 42a53528ff..bd64b8f1be 100644
--- a/frontend/appflowy_flutter/assets/test/workspaces/database/v069.afdb
+++ b/frontend/appflowy_flutter/assets/test/workspaces/database/v069.afdb
@@ -8,7 +8,7 @@
"{""data"":""Juan"",""last_modified"":1726063423,""created_at"":1726063423,""field_type"":0}","{""created_at"":1726122510,""reminder_id"":"""",""include_time"":false,""is_range"":true,""last_modified"":1726122515,""data"":""1725604115"",""end_timestamp"":""1725776915"",""field_type"":2}","{""field_type"":1,""created_at"":1726063677,""last_modified"":1726063677,""data"":""93100""}","{""field_type"":1,""data"":""4.86"",""created_at"":1726062597,""last_modified"":1726062597}",,"{""last_modified"":1726062377,""field_type"":5,""data"":""Yes"",""created_at"":1726062377}","{""last_modified"":1726064412,""field_type"":7,""data"":""{\""options\"":[{\""id\"":\""tTDq\"",\""name\"":\""complete onboarding\"",\""color\"":\""Purple\""},{\""id\"":\""E8Ds\"",\""name\"":\""contact support\"",\""color\"":\""Purple\""},{\""id\"":\""RoGN\"",\""name\"":\""get started\"",\""color\"":\""Purple\""}],\""selected_option_ids\"":[\""tTDq\"",\""E8Ds\""]}"",""created_at"":1726064396}",,"{""created_at"":1726065278,""field_type"":3,""data"":""qnja"",""last_modified"":1726065278}","{""data"":""R9I7,yORP,1i4f"",""field_type"":4,""created_at"":1726105126,""last_modified"":1726105127}","{""data"":""1726122515"",""field_type"":8}","{""data"":""1726060541"",""field_type"":9}"
"{""data"":""Alex"",""created_at"":1726063432,""last_modified"":1726063432,""field_type"":0}","{""reminder_id"":"""",""data"":""1725292800"",""include_time"":true,""last_modified"":1726122448,""created_at"":1726122422,""is_range"":true,""end_timestamp"":""1725551940"",""field_type"":2}","{""field_type"":1,""last_modified"":1726063683,""created_at"":1726063683,""data"":""3560""}","{""created_at"":1726062561,""data"":""1.96"",""last_modified"":1726062561,""field_type"":1}","{""last_modified"":1726063952,""created_at"":1726063931,""data"":""[email protected]"",""field_type"":6}","{""last_modified"":1726062375,""field_type"":5,""created_at"":1726062375,""data"":""Yes""}","{""data"":""{\""options\"":[{\""id\"":\""qNyr\"",\""name\"":\""finish reading book\"",\""color\"":\""Purple\""}],\""selected_option_ids\"":[]}"",""created_at"":1726064616,""last_modified"":1726064616,""field_type"":7}",,"{""data"":""qnja"",""created_at"":1726065272,""last_modified"":1726065272,""field_type"":3}","{""created_at"":1726105180,""last_modified"":1726105180,""field_type"":4,""data"":""R9I7,1i4f""}","{""field_type"":8,""data"":""1726122448""}","{""field_type"":9,""data"":""1726060541""}"
"{""last_modified"":1726063478,""created_at"":1726063436,""field_type"":0,""data"":""Alexander""}",,"{""field_type"":1,""last_modified"":1726063691,""created_at"":1726063691,""data"":""2073""}","{""field_type"":1,""data"":""0.5"",""last_modified"":1726062577,""created_at"":1726062577}","{""last_modified"":1726063991,""field_type"":6,""created_at"":1726063991,""data"":""[email protected]""}","{""field_type"":5,""last_modified"":1726062378,""created_at"":1726062377,""data"":""No""}",,,"{""created_at"":1726065291,""data"":""GSf_"",""last_modified"":1726065291,""field_type"":3}","{""last_modified"":1726105142,""created_at"":1726105133,""data"":""SEUo"",""field_type"":4}","{""field_type"":8,""data"":""1726105142""}","{""field_type"":9,""data"":""1726060542""}"
-"{""field_type"":0,""created_at"":1726063454,""last_modified"":1726063454,""data"":""George""}","{""created_at"":1726122467,""end_timestamp"":""1726468070"",""include_time"":false,""is_range"":true,""reminder_id"":"""",""field_type"":2,""data"":""1726295270"",""last_modified"":1726122470}",,,"{""field_type"":6,""data"":""[email protected]"",""last_modified"":1726064104,""created_at"":1726064016}","{""last_modified"":1726062376,""created_at"":1726062376,""field_type"":5,""data"":""Yes""}","{""data"":""{\""options\"":[{\""id\"":\""s_dQ\"",\""name\"":\""bug triage\"",\""color\"":\""Purple\""},{\""id\"":\""-Zfo\"",\""name\"":\""fix bugs\"",\""color\"":\""Purple\""},{\""id\"":\""wsDN\"",\""name\"":\""attend meetings\"",\""color\"":\""Purple\""}],\""selected_option_ids\"":[\""s_dQ\"",\""-Zfo\""]}"",""last_modified"":1726064468,""created_at"":1726064424,""field_type"":7}","{""data"":[""{\""id\"":\""8a77f84d-64e9-4e67-b902-fa23980459ec\"",\""name\"":\""BQdTmxpRI6f.png\"",\""url\"":\""https://file-examples.com/wp-content/storage/2017/10/file_example_PNG_500kB.png\"",\""upload_type\"":\""NetworkMedia\"",\""file_type\"":\""Image\""}""],""field_type"":14,""created_at"":1726122956,""last_modified"":1726122956}","{""field_type"":3,""data"":""qnja"",""created_at"":1726065313,""last_modified"":1726065313}","{""data"":""R9I7,yORP"",""field_type"":4,""last_modified"":1726105198,""created_at"":1726105187}","{""data"":""1726122956"",""field_type"":8}","{""data"":""1726060543"",""field_type"":9}"
+"{""field_type"":0,""created_at"":1726063454,""last_modified"":1726063454,""data"":""George""}","{""created_at"":1726122467,""end_timestamp"":""1726468070"",""include_time"":false,""is_range"":true,""reminder_id"":"""",""field_type"":2,""data"":""1726295270"",""last_modified"":1726122470}",,,"{""field_type"":6,""data"":""[email protected]"",""last_modified"":1726064104,""created_at"":1726064016}","{""last_modified"":1726062376,""created_at"":1726062376,""field_type"":5,""data"":""Yes""}","{""data"":""{\""options\"":[{\""id\"":\""s_dQ\"",\""name\"":\""bug triage\"",\""color\"":\""Purple\""},{\""id\"":\""-Zfo\"",\""name\"":\""fix bugs\"",\""color\"":\""Purple\""},{\""id\"":\""wsDN\"",\""name\"":\""attend meetings\"",\""color\"":\""Purple\""}],\""selected_option_ids\"":[\""s_dQ\"",\""-Zfo\""]}"",""last_modified"":1726064468,""created_at"":1726064424,""field_type"":7}","{""data"":[""{\""id\"":\""8a77f84d-64e9-4e67-b902-fa23980459ec\"",\""name\"":\""BQdTmxpRI6f.png\"",\""url\"":\""https://samplelib.com/lib/preview/png/sample-blue-200x200.png\"",\""upload_type\"":\""NetworkMedia\"",\""file_type\"":\""Image\""}""],""field_type"":14,""created_at"":1726122956,""last_modified"":1726122956}","{""field_type"":3,""data"":""qnja"",""created_at"":1726065313,""last_modified"":1726065313}","{""data"":""R9I7,yORP"",""field_type"":4,""last_modified"":1726105198,""created_at"":1726105187}","{""data"":""1726122956"",""field_type"":8}","{""data"":""1726060543"",""field_type"":9}"
"{""field_type"":0,""last_modified"":1726063467,""data"":""Joanna"",""created_at"":1726063467}","{""include_time"":false,""end_timestamp"":""1727072893"",""is_range"":true,""last_modified"":1726122493,""created_at"":1726122483,""data"":""1726554493"",""field_type"":2,""reminder_id"":""""}","{""last_modified"":1726065463,""data"":""16470"",""field_type"":1,""created_at"":1726065463}","{""created_at"":1726062626,""field_type"":1,""last_modified"":1726062626,""data"":""-5.36""}","{""last_modified"":1726064069,""data"":""[email protected]"",""created_at"":1726064069,""field_type"":6}",,"{""field_type"":7,""created_at"":1726064444,""last_modified"":1726064460,""data"":""{\""options\"":[{\""id\"":\""ZxJz\"",\""name\"":\""post on Twitter\"",\""color\"":\""Purple\""},{\""id\"":\""upwi\"",\""name\"":\""watch Youtube videos\"",\""color\"":\""Purple\""}],\""selected_option_ids\"":[\""upwi\""]}""}",,"{""created_at"":1726065317,""last_modified"":1726065317,""field_type"":3,""data"":""qnja""}","{""field_type"":4,""last_modified"":1726105173,""data"":""uRAO,yORP"",""created_at"":1726105170}","{""data"":""1726122493"",""field_type"":8}","{""data"":""1726060545"",""field_type"":9}"
"{""last_modified"":1726063457,""created_at"":1726063457,""data"":""George"",""field_type"":0}","{""include_time"":true,""reminder_id"":"""",""field_type"":2,""is_range"":true,""created_at"":1726122521,""end_timestamp"":""1725829200"",""data"":""1725822900"",""last_modified"":1726122535}","{""last_modified"":1726065493,""field_type"":1,""data"":""9500"",""created_at"":1726065493}","{""last_modified"":1726062680,""created_at"":1726062680,""field_type"":1,""data"":""1.7""}","{""data"":""[email protected]"",""field_type"":6,""last_modified"":1726064087,""created_at"":1726064036}",,"{""last_modified"":1726064513,""data"":""{\""options\"":[{\""id\"":\""zy0x\"",\""name\"":\""game vs celtics\"",\""color\"":\""Purple\""},{\""id\"":\""WJsv\"",\""name\"":\""training\"",\""color\"":\""Purple\""},{\""id\"":\""w-f8\"",\""name\"":\""game vs spurs\"",\""color\"":\""Purple\""},{\""id\"":\""p1VQ\"",\""name\"":\""game vs knicks\"",\""color\"":\""Purple\""},{\""id\"":\""VjUA\"",\""name\"":\""recovery\"",\""color\"":\""Purple\""},{\""id\"":\""sQ8X\"",\""name\"":\""don't get injured\"",\""color\"":\""Purple\""}],\""selected_option_ids\"":[]}"",""created_at"":1726064486,""field_type"":7}",,"{""field_type"":3,""last_modified"":1726065310,""data"":""qnja"",""created_at"":1726065310}","{""created_at"":1726105205,""field_type"":4,""last_modified"":1726105249,""data"":""R9I7,1i4f,yORP,SEUo""}","{""data"":""1726122535"",""field_type"":8}","{""field_type"":9,""data"":""1726060546""}"
"{""data"":""Judy"",""created_at"":1726063475,""field_type"":0,""last_modified"":1726063487}","{""end_timestamp"":"""",""reminder_id"":"""",""data"":""1726640950"",""field_type"":2,""include_time"":false,""created_at"":1726122550,""last_modified"":1726122550,""is_range"":false}",,,"{""created_at"":1726063882,""field_type"":6,""last_modified"":1726064000,""data"":""[email protected]""}","{""last_modified"":1726062712,""field_type"":5,""data"":""Yes"",""created_at"":1726062712}","{""created_at"":1726064549,""field_type"":7,""data"":""{\""options\"":[{\""id\"":\""j8cC\"",\""name\"":\""finish training\"",\""color\"":\""Purple\""},{\""id\"":\""SmSk\"",\""name\"":\""brainwash\"",\""color\"":\""Purple\""},{\""id\"":\""mnf5\"",\""name\"":\""welcome to ba sing se\"",\""color\"":\""Purple\""},{\""id\"":\""hcrj\"",\""name\"":\""don't mess up\"",\""color\"":\""Purple\""}],\""selected_option_ids\"":[\""j8cC\"",\""SmSk\"",\""mnf5\"",\""hcrj\""]}"",""last_modified"":1726064591}",,,"{""field_type"":4,""last_modified"":1726105152,""created_at"":1726105152,""data"":""R9I7""}","{""field_type"":8,""data"":""1726122550""}","{""field_type"":9,""data"":""1726060549""}"
diff --git a/frontend/appflowy_flutter/integration_test/desktop/cloud/workspace/collaborative_workspace_test.dart b/frontend/appflowy_flutter/integration_test/desktop/cloud/workspace/collaborative_workspace_test.dart
index 4d2e027646..999ae43bb6 100644
--- a/frontend/appflowy_flutter/integration_test/desktop/cloud/workspace/collaborative_workspace_test.dart
+++ b/frontend/appflowy_flutter/integration_test/desktop/cloud/workspace/collaborative_workspace_test.dart
@@ -100,7 +100,7 @@ void main() {
// expect to see the member count
final memberCount = find.text('1 member');
- expect(memberCount, findsNWidgets(2));
+ expect(memberCount, findsAny);
});
testWidgets('workspace menu popover behavior test', (tester) async {
diff --git a/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_database_modal.dart b/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_database_modal.dart
index 3a3724f6d8..05edb84937 100644
--- a/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_database_modal.dart
+++ b/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_database_modal.dart
@@ -1,9 +1,9 @@
import 'package:appflowy/ai/ai.dart';
import 'package:appflowy/ai/service/ai_prompt_database_selector_cubit.dart';
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/workspace/application/sidebar/space/space_bloc.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy/workspace/application/view/view_ext.dart';
import 'package:appflowy/workspace/presentation/home/menu/view/view_item.dart';
import 'package:appflowy/workspace/presentation/widgets/dialog_v2.dart';
diff --git a/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_modal.dart b/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_modal.dart
index 33c1cfae3a..9a2b821526 100644
--- a/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_modal.dart
+++ b/frontend/appflowy_flutter/lib/ai/widgets/ai_prompt_modal/ai_prompt_modal.dart
@@ -1,4 +1,5 @@
import 'package:appflowy/ai/ai.dart';
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/workspace/application/user/prelude.dart';
diff --git a/frontend/appflowy_flutter/lib/ai/widgets/prompt_input/select_sources_bottom_sheet.dart b/frontend/appflowy_flutter/lib/ai/widgets/prompt_input/select_sources_bottom_sheet.dart
index 08aad06a09..33a7ae8372 100644
--- a/frontend/appflowy_flutter/lib/ai/widgets/prompt_input/select_sources_bottom_sheet.dart
+++ b/frontend/appflowy_flutter/lib/ai/widgets/prompt_input/select_sources_bottom_sheet.dart
@@ -1,13 +1,13 @@
import 'dart:async';
+import 'package:appflowy/ai/service/view_selector_cubit.dart';
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/base/flowy_search_text_field.dart';
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet.dart';
-import 'package:appflowy/ai/service/view_selector_cubit.dart';
import 'package:appflowy/plugins/base/drag_handler.dart';
import 'package:appflowy/workspace/application/sidebar/space/space_bloc.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy/workspace/application/view/view_ext.dart';
import 'package:appflowy/workspace/presentation/home/menu/view/view_item.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/protobuf.dart';
diff --git a/frontend/appflowy_flutter/lib/ai/widgets/view_selector.dart b/frontend/appflowy_flutter/lib/ai/widgets/view_selector.dart
index 2875a717a3..c6f86d7bc7 100644
--- a/frontend/appflowy_flutter/lib/ai/widgets/view_selector.dart
+++ b/frontend/appflowy_flutter/lib/ai/widgets/view_selector.dart
@@ -1,3 +1,4 @@
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/workspace/application/sidebar/space/space_bloc.dart';
import 'package:appflowy/workspace/application/user/prelude.dart';
import 'package:flutter/material.dart';
diff --git a/frontend/appflowy_flutter/lib/features/page_access_level/data/repositories/page_access_level_repository.dart b/frontend/appflowy_flutter/lib/features/page_access_level/data/repositories/page_access_level_repository.dart
new file mode 100644
index 0000000000..c91ea152c2
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/features/page_access_level/data/repositories/page_access_level_repository.dart
@@ -0,0 +1,24 @@
+import 'package:appflowy/features/share_tab/data/models/share_access_level.dart';
+import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
+import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
+import 'package:appflowy_result/appflowy_result.dart';
+
+/// Abstract repository for managing view lock status.
+///
+/// For example, we're using rust events now, but we can still use the http api
+/// for the future.
+abstract class PageAccessLevelRepository {
+ /// Gets the current view from the backend.
+ Future<FlowyResult<ViewPB, FlowyError>> getView(String pageId);
+
+ /// Locks the view.
+ Future<FlowyResult<void, FlowyError>> lockView(String pageId);
+
+ /// Unlocks the view.
+ Future<FlowyResult<void, FlowyError>> unlockView(String pageId);
+
+ /// Gets the access level of the current user.
+ Future<FlowyResult<ShareAccessLevel, FlowyError>> getAccessLevel(
+ String pageId,
+ );
+}
diff --git a/frontend/appflowy_flutter/lib/features/page_access_level/data/repositories/rust_page_access_level_repository_impl.dart b/frontend/appflowy_flutter/lib/features/page_access_level/data/repositories/rust_page_access_level_repository_impl.dart
new file mode 100644
index 0000000000..bb94959d96
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/features/page_access_level/data/repositories/rust_page_access_level_repository_impl.dart
@@ -0,0 +1,117 @@
+import 'package:appflowy/features/page_access_level/data/repositories/page_access_level_repository.dart';
+import 'package:appflowy/features/share_tab/data/models/share_access_level.dart';
+import 'package:appflowy/features/util/extensions.dart';
+import 'package:appflowy/user/application/user_service.dart';
+import 'package:appflowy/workspace/application/view/view_service.dart';
+import 'package:appflowy_backend/dispatch/dispatch.dart';
+import 'package:appflowy_backend/log.dart';
+import 'package:appflowy_backend/protobuf/flowy-error/code.pbenum.dart';
+import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
+import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
+import 'package:appflowy_backend/protobuf/flowy-user/workspace.pbenum.dart';
+import 'package:appflowy_result/appflowy_result.dart';
+import 'package:collection/collection.dart';
+
+class RustPageAccessLevelRepositoryImpl implements PageAccessLevelRepository {
+ @override
+ Future<FlowyResult<ViewPB, FlowyError>> getView(String pageId) async {
+ final result = await ViewBackendService.getView(pageId);
+ return result.fold(
+ (view) {
+ Log.info('get view success: ${view.id}');
+ return FlowyResult.success(view);
+ },
+ (error) {
+ Log.error('failed to get view, error: $error');
+ return FlowyResult.failure(error);
+ },
+ );
+ }
+
+ @override
+ Future<FlowyResult<void, FlowyError>> lockView(String pageId) async {
+ final result = await ViewBackendService.lockView(pageId);
+ return result.fold(
+ (_) {
+ Log.info('lock view success: $pageId');
+ return FlowyResult.success(null);
+ },
+ (error) {
+ Log.error('failed to lock view, error: $error');
+ return FlowyResult.failure(error);
+ },
+ );
+ }
+
+ @override
+ Future<FlowyResult<void, FlowyError>> unlockView(String pageId) async {
+ final result = await ViewBackendService.unlockView(pageId);
+ return result.fold(
+ (_) {
+ Log.info('unlock view success: $pageId');
+ return FlowyResult.success(null);
+ },
+ (error) {
+ Log.error('failed to unlock view, error: $error');
+ return FlowyResult.failure(error);
+ },
+ );
+ }
+
+ @override
+ Future<FlowyResult<ShareAccessLevel, FlowyError>> getAccessLevel(
+ String pageId,
+ ) async {
+ final userResult = await UserBackendService.getCurrentUserProfile();
+ final user = userResult.fold(
+ (s) => s,
+ (_) => null,
+ );
+ if (user == null) {
+ return FlowyResult.failure(
+ FlowyError(
+ code: ErrorCode.Internal,
+ msg: 'User not found',
+ ),
+ );
+ }
+
+ if (user.userAuthType == AuthTypePB.Local) {
+ // Local user can always have full access.
+ return FlowyResult.success(ShareAccessLevel.fullAccess);
+ }
+
+ if (user.workspaceType == WorkspaceTypePB.LocalW) {
+ // Local workspace can always have full access.
+ return FlowyResult.success(ShareAccessLevel.fullAccess);
+ }
+
+ final email = user.email;
+
+ final request = GetSharedUsersPayloadPB(
+ viewId: pageId,
+ );
+ final result = await FolderEventGetSharedUsers(request).send();
+ return result.fold(
+ (success) {
+ final accessLevel = success.items
+ .firstWhereOrNull(
+ (item) => item.email == email,
+ )
+ ?.accessLevel
+ .shareAccessLevel ??
+ ShareAccessLevel.readAndWrite;
+
+ Log.debug('current user access level: $accessLevel');
+
+ return FlowyResult.success(accessLevel);
+ },
+ (failure) {
+ Log.error('failed to get user access level: $failure');
+
+ // return the read and write access level if the user is not found
+ return FlowyResult.success(ShareAccessLevel.readAndWrite);
+ },
+ );
+ }
+}
diff --git a/frontend/appflowy_flutter/lib/features/page_access_level/logic/page_access_level_bloc.dart b/frontend/appflowy_flutter/lib/features/page_access_level/logic/page_access_level_bloc.dart
new file mode 100644
index 0000000000..dd22ff4860
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/features/page_access_level/logic/page_access_level_bloc.dart
@@ -0,0 +1,136 @@
+import 'dart:async';
+
+import 'package:appflowy/features/page_access_level/data/repositories/page_access_level_repository.dart';
+import 'package:appflowy/features/page_access_level/data/repositories/rust_page_access_level_repository_impl.dart';
+import 'package:appflowy/features/page_access_level/logic/page_access_level_event.dart';
+import 'package:appflowy/features/page_access_level/logic/page_access_level_state.dart';
+import 'package:appflowy/features/share_tab/data/models/share_access_level.dart';
+import 'package:appflowy/shared/feature_flags.dart';
+import 'package:appflowy/workspace/application/view/view_listener.dart';
+import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
+import 'package:bloc/bloc.dart';
+import 'package:protobuf/protobuf.dart';
+
+export 'page_access_level_event.dart';
+export 'page_access_level_state.dart';
+
+class PageAccessLevelBloc
+ extends Bloc<PageAccessLevelEvent, PageAccessLevelState> {
+ PageAccessLevelBloc({
+ required this.view,
+ PageAccessLevelRepository? repository,
+ }) : repository = repository ?? RustPageAccessLevelRepositoryImpl(),
+ listener = ViewListener(viewId: view.id),
+ super(PageAccessLevelState.initial(view)) {
+ on<PageAccessLevelInitialEvent>(_onInitial);
+ on<PageAccessLevelLockEvent>(_onLock);
+ on<PageAccessLevelUnlockEvent>(_onUnlock);
+ on<PageAccessLevelUpdateLockStatusEvent>(_onUpdateLockStatus);
+ }
+
+ final ViewPB view;
+
+ // The repository to manage view lock status.
+ // If you need to test this bloc, you can add your own repository implementation.
+ final PageAccessLevelRepository repository;
+
+ // Used to listen for view updates.
+ late final ViewListener listener;
+
+ @override
+ Future<void> close() async {
+ await listener.stop();
+ return super.close();
+ }
+
+ Future<void> _onInitial(
+ PageAccessLevelInitialEvent event,
+ Emitter<PageAccessLevelState> emit,
+ ) async {
+ listener.start(
+ onViewUpdated: (view) async {
+ add(PageAccessLevelEvent.updateLockStatus(view.isLocked));
+ },
+ );
+
+ if (!FeatureFlag.sharedSection.isOn) {
+ emit(
+ state.copyWith(
+ view: view,
+ isLocked: view.isLocked,
+ isLoadingLockStatus: false,
+ accessLevel: ShareAccessLevel.fullAccess,
+ ),
+ );
+ return;
+ }
+
+ final result = await repository.getView(view.id);
+ final accessLevel = await repository.getAccessLevel(view.id);
+ final latestView = result.fold(
+ (view) => view,
+ (_) => view,
+ );
+ emit(
+ state.copyWith(
+ view: latestView,
+ isLocked: latestView.isLocked,
+ isLoadingLockStatus: false,
+ accessLevel: accessLevel.fold(
+ (accessLevel) => accessLevel,
+ (_) => ShareAccessLevel.readOnly,
+ ),
+ ),
+ );
+ }
+
+ Future<void> _onLock(
+ PageAccessLevelLockEvent event,
+ Emitter<PageAccessLevelState> emit,
+ ) async {
+ final result = await repository.lockView(view.id);
+ final isLocked = result.fold(
+ (_) => true,
+ (_) => false,
+ );
+ add(
+ PageAccessLevelEvent.updateLockStatus(
+ isLocked,
+ ),
+ );
+ }
+
+ Future<void> _onUnlock(
+ PageAccessLevelUnlockEvent event,
+ Emitter<PageAccessLevelState> emit,
+ ) async {
+ final result = await repository.unlockView(view.id);
+ final isLocked = result.fold(
+ (_) => false,
+ (_) => true,
+ );
+ add(
+ PageAccessLevelEvent.updateLockStatus(
+ isLocked,
+ lockCounter: state.lockCounter + 1,
+ ),
+ );
+ }
+
+ void _onUpdateLockStatus(
+ PageAccessLevelUpdateLockStatusEvent event,
+ Emitter<PageAccessLevelState> emit,
+ ) {
+ state.view.freeze();
+ final updatedView = state.view.rebuild(
+ (update) => update.isLocked = event.isLocked,
+ );
+ emit(
+ state.copyWith(
+ view: updatedView,
+ isLocked: event.isLocked,
+ lockCounter: event.lockCounter ?? state.lockCounter,
+ ),
+ );
+ }
+}
diff --git a/frontend/appflowy_flutter/lib/features/page_access_level/logic/page_access_level_event.dart b/frontend/appflowy_flutter/lib/features/page_access_level/logic/page_access_level_event.dart
new file mode 100644
index 0000000000..c4538a7a05
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/features/page_access_level/logic/page_access_level_event.dart
@@ -0,0 +1,42 @@
+/// Base class for all PageAccessLevel events
+sealed class PageAccessLevelEvent {
+ const PageAccessLevelEvent();
+
+ /// Initialize the view lock status, it will create a view listener to listen for view updates.
+ /// Also, it will fetch the current view lock status from the repository.
+ const factory PageAccessLevelEvent.initial() = PageAccessLevelInitialEvent;
+
+ /// Lock the view.
+ const factory PageAccessLevelEvent.lock() = PageAccessLevelLockEvent;
+
+ /// Unlock the view.
+ const factory PageAccessLevelEvent.unlock() = PageAccessLevelUnlockEvent;
+
+ /// Update the lock status in the state.
+ const factory PageAccessLevelEvent.updateLockStatus(
+ bool isLocked, {
+ int? lockCounter,
+ }) = PageAccessLevelUpdateLockStatusEvent;
+}
+
+class PageAccessLevelInitialEvent extends PageAccessLevelEvent {
+ const PageAccessLevelInitialEvent();
+}
+
+class PageAccessLevelLockEvent extends PageAccessLevelEvent {
+ const PageAccessLevelLockEvent();
+}
+
+class PageAccessLevelUnlockEvent extends PageAccessLevelEvent {
+ const PageAccessLevelUnlockEvent();
+}
+
+class PageAccessLevelUpdateLockStatusEvent extends PageAccessLevelEvent {
+ const PageAccessLevelUpdateLockStatusEvent(
+ this.isLocked, {
+ this.lockCounter,
+ });
+
+ final bool isLocked;
+ final int? lockCounter;
+}
diff --git a/frontend/appflowy_flutter/lib/features/page_access_level/logic/page_access_level_state.dart b/frontend/appflowy_flutter/lib/features/page_access_level/logic/page_access_level_state.dart
new file mode 100644
index 0000000000..6b51450ac6
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/features/page_access_level/logic/page_access_level_state.dart
@@ -0,0 +1,80 @@
+import 'package:appflowy/features/share_tab/data/models/share_access_level.dart';
+import 'package:appflowy/shared/feature_flags.dart';
+import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
+
+class PageAccessLevelState {
+ factory PageAccessLevelState.initial(ViewPB view) => PageAccessLevelState(
+ view: view,
+ isLocked: false,
+ lockCounter: 0,
+ accessLevel: ShareAccessLevel
+ .readAndWrite, // replace it with readOnly if we support offline.
+ );
+
+ const PageAccessLevelState({
+ required this.view,
+ required this.isLocked,
+ required this.lockCounter,
+ required this.accessLevel,
+ this.isLoadingLockStatus = true,
+ });
+
+ final ViewPB view;
+ final bool isLocked;
+ final int lockCounter;
+ final bool isLoadingLockStatus;
+ final ShareAccessLevel accessLevel;
+
+ bool get isEditable {
+ if (!FeatureFlag.sharedSection.isOn) {
+ return !isLocked;
+ }
+
+ return accessLevel != ShareAccessLevel.readOnly && !isLocked;
+ }
+
+ bool get isReadOnly => accessLevel == ShareAccessLevel.readOnly;
+
+ PageAccessLevelState copyWith({
+ ViewPB? view,
+ bool? isLocked,
+ int? lockCounter,
+ bool? isLoadingLockStatus,
+ ShareAccessLevel? accessLevel,
+ }) {
+ return PageAccessLevelState(
+ view: view ?? this.view,
+ isLocked: isLocked ?? this.isLocked,
+ lockCounter: lockCounter ?? this.lockCounter,
+ isLoadingLockStatus: isLoadingLockStatus ?? this.isLoadingLockStatus,
+ accessLevel: accessLevel ?? this.accessLevel,
+ );
+ }
+
+ @override
+ bool operator ==(Object other) {
+ if (identical(this, other)) return true;
+ return other is PageAccessLevelState &&
+ other.view == view &&
+ other.isLocked == isLocked &&
+ other.lockCounter == lockCounter &&
+ other.isLoadingLockStatus == isLoadingLockStatus &&
+ other.accessLevel == accessLevel;
+ }
+
+ @override
+ int get hashCode {
+ return Object.hash(
+ view,
+ isLocked,
+ lockCounter,
+ isLoadingLockStatus,
+ accessLevel,
+ );
+ }
+
+ @override
+ String toString() {
+ return 'PageAccessLevelState(view: $view, isLocked: $isLocked, lockCounter: $lockCounter, isLoadingLockStatus: $isLoadingLockStatus, accessLevel: $accessLevel)';
+ }
+}
diff --git a/frontend/appflowy_flutter/lib/features/share_tab/data/models/share_access_level.dart b/frontend/appflowy_flutter/lib/features/share_tab/data/models/share_access_level.dart
index 141b58d9c7..7c802fc512 100644
--- a/frontend/appflowy_flutter/lib/features/share_tab/data/models/share_access_level.dart
+++ b/frontend/appflowy_flutter/lib/features/share_tab/data/models/share_access_level.dart
@@ -28,3 +28,4 @@ enum ShareAccessLevel {
}
}
}
+
diff --git a/frontend/appflowy_flutter/lib/features/share_tab/data/models/shared_group.dart b/frontend/appflowy_flutter/lib/features/share_tab/data/models/shared_group.dart
new file mode 100644
index 0000000000..296d303023
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/features/share_tab/data/models/shared_group.dart
@@ -0,0 +1,25 @@
+class SharedGroup {
+ SharedGroup({
+ required this.id,
+ required this.name,
+ required this.icon,
+ });
+
+ final String id;
+
+ final String name;
+
+ final String icon;
+
+ SharedGroup copyWith({
+ String? id,
+ String? name,
+ String? icon,
+ }) {
+ return SharedGroup(
+ id: id ?? this.id,
+ name: name ?? this.name,
+ icon: icon ?? this.icon,
+ );
+ }
+}
diff --git a/frontend/appflowy_flutter/lib/features/share_tab/data/repositories/local_share_with_user_repository.dart b/frontend/appflowy_flutter/lib/features/share_tab/data/repositories/local_share_with_user_repository_impl.dart
similarity index 96%
rename from frontend/appflowy_flutter/lib/features/share_tab/data/repositories/local_share_with_user_repository.dart
rename to frontend/appflowy_flutter/lib/features/share_tab/data/repositories/local_share_with_user_repository_impl.dart
index e6a34137bb..944ca88d57 100644
--- a/frontend/appflowy_flutter/lib/features/share_tab/data/repositories/local_share_with_user_repository.dart
+++ b/frontend/appflowy_flutter/lib/features/share_tab/data/repositories/local_share_with_user_repository_impl.dart
@@ -6,8 +6,9 @@ import 'package:appflowy_result/appflowy_result.dart';
import 'share_with_user_repository.dart';
-class LocalShareWithUserRepository extends ShareWithUserRepository {
- LocalShareWithUserRepository();
+// Move this file to test folder
+class LocalShareWithUserRepositoryImpl extends ShareWithUserRepository {
+ LocalShareWithUserRepositoryImpl();
final SharedUsers _sharedUsers = [
SharedUser(
diff --git a/frontend/appflowy_flutter/lib/features/share_tab/data/repositories/rust_share_with_user_repository.dart b/frontend/appflowy_flutter/lib/features/share_tab/data/repositories/rust_share_with_user_repository_impl.dart
similarity index 96%
rename from frontend/appflowy_flutter/lib/features/share_tab/data/repositories/rust_share_with_user_repository.dart
rename to frontend/appflowy_flutter/lib/features/share_tab/data/repositories/rust_share_with_user_repository_impl.dart
index 130c4d460c..327890b562 100644
--- a/frontend/appflowy_flutter/lib/features/share_tab/data/repositories/rust_share_with_user_repository.dart
+++ b/frontend/appflowy_flutter/lib/features/share_tab/data/repositories/rust_share_with_user_repository_impl.dart
@@ -9,8 +9,8 @@ import 'package:appflowy_result/appflowy_result.dart';
import 'share_with_user_repository.dart';
-class RustShareWithUserRepository extends ShareWithUserRepository {
- RustShareWithUserRepository();
+class RustShareWithUserRepositoryImpl extends ShareWithUserRepository {
+ RustShareWithUserRepositoryImpl();
@override
Future<FlowyResult<SharedUsers, FlowyError>> getSharedUsersInPage({
diff --git a/frontend/appflowy_flutter/lib/features/share_tab/logic/share_with_user_bloc.dart b/frontend/appflowy_flutter/lib/features/share_tab/logic/share_tab_bloc.dart
similarity index 60%
rename from frontend/appflowy_flutter/lib/features/share_tab/logic/share_with_user_bloc.dart
rename to frontend/appflowy_flutter/lib/features/share_tab/logic/share_tab_bloc.dart
index 55511a48df..4dc60d9004 100644
--- a/frontend/appflowy_flutter/lib/features/share_tab/logic/share_with_user_bloc.dart
+++ b/frontend/appflowy_flutter/lib/features/share_tab/logic/share_tab_bloc.dart
@@ -1,33 +1,34 @@
import 'package:appflowy/features/share_tab/data/models/models.dart';
import 'package:appflowy/features/share_tab/data/repositories/share_with_user_repository.dart';
+import 'package:appflowy/features/share_tab/logic/share_tab_event.dart';
+import 'package:appflowy/features/share_tab/logic/share_tab_state.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/clipboard_service.dart';
import 'package:appflowy/plugins/shared/share/constants.dart';
import 'package:appflowy/shared/feature_flags.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/user/application/user_service.dart';
-import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
-import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
import 'package:appflowy_result/appflowy_result.dart';
import 'package:bloc/bloc.dart';
-import 'package:freezed_annotation/freezed_annotation.dart';
-part 'share_with_user_bloc.freezed.dart';
+export 'share_tab_event.dart';
+export 'share_tab_state.dart';
-class ShareWithUserBloc extends Bloc<ShareWithUserEvent, ShareWithUserState> {
- ShareWithUserBloc({
+class ShareTabBloc extends Bloc<ShareTabEvent, ShareTabState> {
+ ShareTabBloc({
required this.repository,
required this.pageId,
required this.workspaceId,
- }) : super(ShareWithUserState.initial()) {
- on<Initial>(_onInitial);
- on<GetSharedUsers>(_onGetSharedUsers);
- on<ShareWithUser>(_onShare);
- on<RemoveUser>(_onRemove);
- on<UpdateAccessLevel>(_onUpdateAccessLevel);
- on<UpdateGeneralAccess>(_onUpdateGeneralAccess);
- on<CopyLink>(_onCopyLink);
- on<SearchAvailableUsers>(_onSearchAvailableUsers);
- on<TurnIntoMember>(_onTurnIntoMember);
+ }) : super(ShareTabState.initial()) {
+ on<ShareTabEventInitialize>(_onInitial);
+ on<ShareTabEventLoadSharedUsers>(_onGetSharedUsers);
+ on<ShareTabEventInviteUsers>(_onShare);
+ on<ShareTabEventRemoveUsers>(_onRemove);
+ on<ShareTabEventUpdateUserAccessLevel>(_onUpdateAccessLevel);
+ on<ShareTabEventUpdateGeneralAccessLevel>(_onUpdateGeneralAccess);
+ on<ShareTabEventCopyShareLink>(_onCopyLink);
+ on<ShareTabEventSearchAvailableUsers>(_onSearchAvailableUsers);
+ on<ShareTabEventConvertToMember>(_onTurnIntoMember);
+ on<ShareTabEventClearState>(_onClearState);
}
final ShareWithUserRepository repository;
@@ -35,8 +36,8 @@ class ShareWithUserBloc extends Bloc<ShareWithUserEvent, ShareWithUserState> {
final String pageId;
Future<void> _onInitial(
- Initial event,
- Emitter<ShareWithUserState> emit,
+ ShareTabEventInitialize event,
+ Emitter<ShareTabState> emit,
) async {
if (!FeatureFlag.sharedSection.isOn) {
emit(
@@ -72,8 +73,8 @@ class ShareWithUserBloc extends Bloc<ShareWithUserEvent, ShareWithUserState> {
}
Future<void> _onGetSharedUsers(
- GetSharedUsers event,
- Emitter<ShareWithUserState> emit,
+ ShareTabEventLoadSharedUsers event,
+ Emitter<ShareTabState> emit,
) async {
if (!FeatureFlag.sharedSection.isOn) {
return;
@@ -82,11 +83,6 @@ class ShareWithUserBloc extends Bloc<ShareWithUserEvent, ShareWithUserState> {
emit(
state.copyWith(
errorMessage: '',
- initialResult: null,
- shareResult: null,
- removeResult: null,
- updateAccessLevelResult: null,
- turnIntoMemberResult: null,
),
);
@@ -111,16 +107,12 @@ class ShareWithUserBloc extends Bloc<ShareWithUserEvent, ShareWithUserState> {
}
Future<void> _onShare(
- ShareWithUser event,
- Emitter<ShareWithUserState> emit,
+ ShareTabEventInviteUsers event,
+ Emitter<ShareTabState> emit,
) async {
emit(
state.copyWith(
errorMessage: '',
- shareResult: null,
- turnIntoMemberResult: null,
- removeResult: null,
- updateAccessLevelResult: null,
),
);
@@ -153,16 +145,12 @@ class ShareWithUserBloc extends Bloc<ShareWithUserEvent, ShareWithUserState> {
}
Future<void> _onRemove(
- RemoveUser event,
- Emitter<ShareWithUserState> emit,
+ ShareTabEventRemoveUsers event,
+ Emitter<ShareTabState> emit,
) async {
emit(
state.copyWith(
errorMessage: '',
- removeResult: null,
- shareResult: null,
- updateAccessLevelResult: null,
- turnIntoMemberResult: null,
),
);
@@ -193,13 +181,11 @@ class ShareWithUserBloc extends Bloc<ShareWithUserEvent, ShareWithUserState> {
}
Future<void> _onUpdateAccessLevel(
- UpdateAccessLevel event,
- Emitter<ShareWithUserState> emit,
+ ShareTabEventUpdateUserAccessLevel event,
+ Emitter<ShareTabState> emit,
) async {
emit(
- state.copyWith(
- updateAccessLevelResult: null,
- ),
+ state.copyWith(),
);
final result = await repository.sharePageWithUser(
@@ -230,8 +216,8 @@ class ShareWithUserBloc extends Bloc<ShareWithUserEvent, ShareWithUserState> {
}
void _onUpdateGeneralAccess(
- UpdateGeneralAccess event,
- Emitter<ShareWithUserState> emit,
+ ShareTabEventUpdateGeneralAccessLevel event,
+ Emitter<ShareTabState> emit,
) {
emit(
state.copyWith(
@@ -240,7 +226,10 @@ class ShareWithUserBloc extends Bloc<ShareWithUserEvent, ShareWithUserState> {
);
}
- void _onCopyLink(CopyLink event, Emitter<ShareWithUserState> emit) {
+ void _onCopyLink(
+ ShareTabEventCopyShareLink event,
+ Emitter<ShareTabState> emit,
+ ) {
getIt<ClipboardService>().setData(
ClipboardServiceData(
plainText: event.link,
@@ -255,8 +244,8 @@ class ShareWithUserBloc extends Bloc<ShareWithUserEvent, ShareWithUserState> {
}
Future<void> _onSearchAvailableUsers(
- SearchAvailableUsers event,
- Emitter<ShareWithUserState> emit,
+ ShareTabEventSearchAvailableUsers event,
+ Emitter<ShareTabState> emit,
) async {
emit(
state.copyWith(
@@ -290,16 +279,12 @@ class ShareWithUserBloc extends Bloc<ShareWithUserEvent, ShareWithUserState> {
}
Future<void> _onTurnIntoMember(
- TurnIntoMember event,
- Emitter<ShareWithUserState> emit,
+ ShareTabEventConvertToMember event,
+ Emitter<ShareTabState> emit,
) async {
emit(
state.copyWith(
- turnIntoMemberResult: null,
errorMessage: '',
- removeResult: null,
- shareResult: null,
- updateAccessLevelResult: null,
),
);
@@ -339,71 +324,15 @@ class ShareWithUserBloc extends Bloc<ShareWithUserEvent, ShareWithUserState> {
(error) => state.users,
);
}
-}
-@freezed
-class ShareWithUserEvent with _$ShareWithUserEvent {
- /// Initializes the bloc.
- const factory ShareWithUserEvent.init() = Initial;
-
- /// Loads the shared users for the page.
- const factory ShareWithUserEvent.getSharedUsers() = GetSharedUsers;
-
- /// Invites the users to the page.
- const factory ShareWithUserEvent.share({
- required List<String> emails,
- required ShareAccessLevel accessLevel,
- }) = ShareWithUser;
-
- /// Removes the users from the page.
- const factory ShareWithUserEvent.remove({
- required List<String> emails,
- }) = RemoveUser;
-
- /// Updates the access level of the user.
- const factory ShareWithUserEvent.updateAccessLevel({
- required String email,
- required ShareAccessLevel accessLevel,
- }) = UpdateAccessLevel;
-
- /// Updates the general access role for all users.
- const factory ShareWithUserEvent.updateGeneralAccess({
- required ShareAccessLevel accessLevel,
- }) = UpdateGeneralAccess;
-
- /// Copies the link to the clipboard.
- const factory ShareWithUserEvent.copyLink({
- required String link,
- }) = CopyLink;
-
- /// Searches available users by name or email.
- const factory ShareWithUserEvent.searchAvailableUsers({
- required String query,
- }) = SearchAvailableUsers;
-
- /// Turns the user into a member.
- const factory ShareWithUserEvent.turnIntoMember({
- required String email,
- }) = TurnIntoMember;
-}
-
-@freezed
-class ShareWithUserState with _$ShareWithUserState {
- const factory ShareWithUserState({
- @Default(null) UserProfilePB? currentUser,
- @Default([]) SharedUsers users,
- @Default([]) SharedUsers availableUsers,
- @Default(false) bool isLoading,
- @Default('') String errorMessage,
- @Default('') String shareLink,
- ShareAccessLevel? generalAccessRole,
- @Default(false) bool linkCopied,
- @Default(null) FlowyResult<void, FlowyError>? initialResult,
- @Default(null) FlowyResult<void, FlowyError>? shareResult,
- @Default(null) FlowyResult<void, FlowyError>? removeResult,
- @Default(null) FlowyResult<void, FlowyError>? updateAccessLevelResult,
- @Default(null) FlowyResult<void, FlowyError>? turnIntoMemberResult,
- }) = _ShareWithUserState;
-
- factory ShareWithUserState.initial() => const ShareWithUserState();
+ void _onClearState(
+ ShareTabEventClearState event,
+ Emitter<ShareTabState> emit,
+ ) {
+ emit(
+ state.copyWith(
+ errorMessage: '',
+ ),
+ );
+ }
}
diff --git a/frontend/appflowy_flutter/lib/features/share_tab/logic/share_tab_event.dart b/frontend/appflowy_flutter/lib/features/share_tab/logic/share_tab_event.dart
new file mode 100644
index 0000000000..e48aedd98e
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/features/share_tab/logic/share_tab_event.dart
@@ -0,0 +1,134 @@
+import 'package:appflowy/features/share_tab/data/models/models.dart';
+
+sealed class ShareTabEvent {
+ const ShareTabEvent();
+
+ // Factory functions for creating events
+ factory ShareTabEvent.initialize() => const ShareTabEventInitialize();
+
+ factory ShareTabEvent.loadSharedUsers() =>
+ const ShareTabEventLoadSharedUsers();
+
+ factory ShareTabEvent.inviteUsers({
+ required List<String> emails,
+ required ShareAccessLevel accessLevel,
+ }) =>
+ ShareTabEventInviteUsers(emails: emails, accessLevel: accessLevel);
+
+ factory ShareTabEvent.removeUsers({
+ required List<String> emails,
+ }) =>
+ ShareTabEventRemoveUsers(emails: emails);
+
+ factory ShareTabEvent.updateUserAccessLevel({
+ required String email,
+ required ShareAccessLevel accessLevel,
+ }) =>
+ ShareTabEventUpdateUserAccessLevel(
+ email: email,
+ accessLevel: accessLevel,
+ );
+
+ factory ShareTabEvent.updateGeneralAccessLevel({
+ required ShareAccessLevel accessLevel,
+ }) =>
+ ShareTabEventUpdateGeneralAccessLevel(accessLevel: accessLevel);
+
+ factory ShareTabEvent.copyShareLink({
+ required String link,
+ }) =>
+ ShareTabEventCopyShareLink(link: link);
+
+ factory ShareTabEvent.searchAvailableUsers({
+ required String query,
+ }) =>
+ ShareTabEventSearchAvailableUsers(query: query);
+
+ factory ShareTabEvent.convertToMember({
+ required String email,
+ }) =>
+ ShareTabEventConvertToMember(email: email);
+
+ factory ShareTabEvent.clearState() => const ShareTabEventClearState();
+}
+
+/// Initializes the share tab bloc.
+class ShareTabEventInitialize extends ShareTabEvent {
+ const ShareTabEventInitialize();
+}
+
+/// Loads the shared users for the current page.
+class ShareTabEventLoadSharedUsers extends ShareTabEvent {
+ const ShareTabEventLoadSharedUsers();
+}
+
+/// Invites users to the page with specified access level.
+class ShareTabEventInviteUsers extends ShareTabEvent {
+ const ShareTabEventInviteUsers({
+ required this.emails,
+ required this.accessLevel,
+ });
+
+ final List<String> emails;
+ final ShareAccessLevel accessLevel;
+}
+
+/// Removes users from the shared page.
+class ShareTabEventRemoveUsers extends ShareTabEvent {
+ const ShareTabEventRemoveUsers({
+ required this.emails,
+ });
+
+ final List<String> emails;
+}
+
+/// Updates the access level for a specific user.
+class ShareTabEventUpdateUserAccessLevel extends ShareTabEvent {
+ const ShareTabEventUpdateUserAccessLevel({
+ required this.email,
+ required this.accessLevel,
+ });
+
+ final String email;
+ final ShareAccessLevel accessLevel;
+}
+
+/// Updates the general access level for all users.
+class ShareTabEventUpdateGeneralAccessLevel extends ShareTabEvent {
+ const ShareTabEventUpdateGeneralAccessLevel({
+ required this.accessLevel,
+ });
+
+ final ShareAccessLevel accessLevel;
+}
+
+/// Copies the share link to the clipboard.
+class ShareTabEventCopyShareLink extends ShareTabEvent {
+ const ShareTabEventCopyShareLink({
+ required this.link,
+ });
+
+ final String link;
+}
+
+/// Searches for available users by name or email.
+class ShareTabEventSearchAvailableUsers extends ShareTabEvent {
+ const ShareTabEventSearchAvailableUsers({
+ required this.query,
+ });
+
+ final String query;
+}
+
+/// Converts a user into a member.
+class ShareTabEventConvertToMember extends ShareTabEvent {
+ const ShareTabEventConvertToMember({
+ required this.email,
+ });
+
+ final String email;
+}
+
+class ShareTabEventClearState extends ShareTabEvent {
+ const ShareTabEventClearState();
+}
diff --git a/frontend/appflowy_flutter/lib/features/share_tab/logic/share_tab_state.dart b/frontend/appflowy_flutter/lib/features/share_tab/logic/share_tab_state.dart
new file mode 100644
index 0000000000..88e8ae5ddb
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/features/share_tab/logic/share_tab_state.dart
@@ -0,0 +1,113 @@
+import 'package:appflowy/features/share_tab/data/models/models.dart';
+import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
+import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
+import 'package:appflowy_result/appflowy_result.dart';
+
+class ShareTabState {
+ factory ShareTabState.initial() => const ShareTabState();
+
+ const ShareTabState({
+ this.currentUser,
+ this.users = const [],
+ this.availableUsers = const [],
+ this.isLoading = false,
+ this.errorMessage = '',
+ this.shareLink = '',
+ this.generalAccessRole,
+ this.linkCopied = false,
+ this.initialResult,
+ this.shareResult,
+ this.removeResult,
+ this.updateAccessLevelResult,
+ this.turnIntoMemberResult,
+ });
+
+ final UserProfilePB? currentUser;
+ final SharedUsers users;
+ final SharedUsers availableUsers;
+ final bool isLoading;
+ final String errorMessage;
+ final String shareLink;
+ final ShareAccessLevel? generalAccessRole;
+ final bool linkCopied;
+ final FlowyResult<void, FlowyError>? initialResult;
+ final FlowyResult<void, FlowyError>? shareResult;
+ final FlowyResult<void, FlowyError>? removeResult;
+ final FlowyResult<void, FlowyError>? updateAccessLevelResult;
+ final FlowyResult<void, FlowyError>? turnIntoMemberResult;
+
+ ShareTabState copyWith({
+ UserProfilePB? currentUser,
+ SharedUsers? users,
+ SharedUsers? availableUsers,
+ bool? isLoading,
+ String? errorMessage,
+ String? shareLink,
+ ShareAccessLevel? generalAccessRole,
+ bool? linkCopied,
+ FlowyResult<void, FlowyError>? initialResult,
+ FlowyResult<void, FlowyError>? shareResult,
+ FlowyResult<void, FlowyError>? removeResult,
+ FlowyResult<void, FlowyError>? updateAccessLevelResult,
+ FlowyResult<void, FlowyError>? turnIntoMemberResult,
+ }) {
+ return ShareTabState(
+ currentUser: currentUser ?? this.currentUser,
+ users: users ?? this.users,
+ availableUsers: availableUsers ?? this.availableUsers,
+ isLoading: isLoading ?? this.isLoading,
+ errorMessage: errorMessage ?? this.errorMessage,
+ shareLink: shareLink ?? this.shareLink,
+ generalAccessRole: generalAccessRole ?? this.generalAccessRole,
+ linkCopied: linkCopied ?? this.linkCopied,
+ initialResult: initialResult,
+ shareResult: shareResult,
+ removeResult: removeResult,
+ updateAccessLevelResult: updateAccessLevelResult,
+ turnIntoMemberResult: turnIntoMemberResult,
+ );
+ }
+
+ @override
+ bool operator ==(Object other) {
+ if (identical(this, other)) return true;
+ return other is ShareTabState &&
+ other.currentUser == currentUser &&
+ other.users == users &&
+ other.availableUsers == availableUsers &&
+ other.isLoading == isLoading &&
+ other.errorMessage == errorMessage &&
+ other.shareLink == shareLink &&
+ other.generalAccessRole == generalAccessRole &&
+ other.linkCopied == linkCopied &&
+ other.initialResult == initialResult &&
+ other.shareResult == shareResult &&
+ other.removeResult == removeResult &&
+ other.updateAccessLevelResult == updateAccessLevelResult &&
+ other.turnIntoMemberResult == turnIntoMemberResult;
+ }
+
+ @override
+ int get hashCode {
+ return Object.hash(
+ currentUser,
+ users,
+ availableUsers,
+ isLoading,
+ errorMessage,
+ shareLink,
+ generalAccessRole,
+ linkCopied,
+ initialResult,
+ shareResult,
+ removeResult,
+ updateAccessLevelResult,
+ turnIntoMemberResult,
+ );
+ }
+
+ @override
+ String toString() {
+ return 'ShareTabState(currentUser: $currentUser, users: $users, availableUsers: $availableUsers, isLoading: $isLoading, errorMessage: $errorMessage, shareLink: $shareLink, generalAccessRole: $generalAccessRole, linkCopied: $linkCopied, initialResult: $initialResult, shareResult: $shareResult, removeResult: $removeResult, updateAccessLevelResult: $updateAccessLevelResult, turnIntoMemberResult: $turnIntoMemberResult)';
+ }
+}
diff --git a/frontend/appflowy_flutter/lib/features/share_tab/presentation/share_tab.dart b/frontend/appflowy_flutter/lib/features/share_tab/presentation/share_tab.dart
index 3344bb5be5..39d65b55bb 100644
--- a/frontend/appflowy_flutter/lib/features/share_tab/presentation/share_tab.dart
+++ b/frontend/appflowy_flutter/lib/features/share_tab/presentation/share_tab.dart
@@ -1,8 +1,11 @@
import 'package:appflowy/features/share_tab/data/models/models.dart';
-import 'package:appflowy/features/share_tab/logic/share_with_user_bloc.dart';
+import 'package:appflowy/features/share_tab/data/models/shared_group.dart';
+import 'package:appflowy/features/share_tab/logic/share_tab_bloc.dart';
import 'package:appflowy/features/share_tab/presentation/widgets/copy_link_widget.dart';
+import 'package:appflowy/features/share_tab/presentation/widgets/general_access_section.dart';
import 'package:appflowy/features/share_tab/presentation/widgets/people_with_access_section.dart';
import 'package:appflowy/features/share_tab/presentation/widgets/share_with_user_widget.dart';
+import 'package:appflowy/workspace/presentation/home/menu/sidebar/space/shared_widget.dart';
import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';
import 'package:appflowy_backend/protobuf/flowy-error/code.pbenum.dart';
import 'package:appflowy_ui/appflowy_ui.dart';
@@ -16,21 +19,36 @@ class ShareTab extends StatefulWidget {
super.key,
required this.workspaceId,
required this.pageId,
+ required this.workspaceName,
+ required this.workspaceIcon,
});
final String workspaceId;
final String pageId;
+ // these 2 values should be provided by the share tab bloc
+ final String workspaceName;
+ final String workspaceIcon;
+
@override
State<ShareTab> createState() => _ShareTabState();
}
class _ShareTabState extends State<ShareTab> {
final TextEditingController controller = TextEditingController();
+ late final ShareTabBloc shareTabBloc;
+
+ @override
+ void initState() {
+ super.initState();
+
+ shareTabBloc = context.read<ShareTabBloc>();
+ }
@override
void dispose() {
controller.dispose();
+ shareTabBloc.add(ShareTabEvent.clearState());
super.dispose();
}
@@ -39,7 +57,7 @@ class _ShareTabState extends State<ShareTab> {
Widget build(BuildContext context) {
final theme = AppFlowyTheme.of(context);
- return BlocConsumer<ShareWithUserBloc, ShareWithUserState>(
+ return BlocConsumer<ShareTabBloc, ShareTabState>(
listener: (context, state) {
_onListenShareWithUserState(context, state);
},
@@ -84,13 +102,16 @@ class _ShareTabState extends State<ShareTab> {
],
// general access
- // enable it when the backend support general access features.
- // VSpace(theme.spacing.m),
- // GeneralAccessSection(),
+ VSpace(theme.spacing.m),
+ GeneralAccessSection(
+ group: SharedGroup(
+ id: widget.workspaceId,
+ name: widget.workspaceName,
+ icon: widget.workspaceIcon,
+ ),
+ ),
// copy link
- VSpace(theme.spacing.l),
- const AFDivider(),
VSpace(theme.spacing.xl),
CopyLinkWidget(shareLink: state.shareLink),
VSpace(theme.spacing.m),
@@ -105,8 +126,8 @@ class _ShareTabState extends State<ShareTab> {
required List<String> emails,
required ShareAccessLevel accessLevel,
}) {
- context.read<ShareWithUserBloc>().add(
- ShareWithUserEvent.share(emails: emails, accessLevel: accessLevel),
+ context.read<ShareTabBloc>().add(
+ ShareTabEvent.inviteUsers(emails: emails, accessLevel: accessLevel),
);
}
@@ -115,29 +136,47 @@ class _ShareTabState extends State<ShareTab> {
) {
return PeopleWithAccessSectionCallbacks(
onSelectAccessLevel: (user, accessLevel) {
- context.read<ShareWithUserBloc>().add(
- ShareWithUserEvent.updateAccessLevel(
+ context.read<ShareTabBloc>().add(
+ ShareTabEvent.updateUserAccessLevel(
email: user.email,
accessLevel: accessLevel,
),
);
},
onTurnIntoMember: (user) {
- context.read<ShareWithUserBloc>().add(
- ShareWithUserEvent.turnIntoMember(email: user.email),
+ context.read<ShareTabBloc>().add(
+ ShareTabEvent.convertToMember(email: user.email),
);
},
onRemoveAccess: (user) {
- context.read<ShareWithUserBloc>().add(
- ShareWithUserEvent.remove(emails: [user.email]),
- );
+ // show a dialog to confirm the action when removing self access
+ final removingSelf =
+ user.email == context.read<ShareTabBloc>().state.currentUser?.email;
+ if (removingSelf) {
+ showConfirmDialog(
+ context: context,
+ title: 'Remove your own access',
+ description: '',
+ style: ConfirmPopupStyle.cancelAndOk,
+ confirmLabel: 'Remove',
+ onConfirm: () {
+ context.read<ShareTabBloc>().add(
+ ShareTabEvent.removeUsers(emails: [user.email]),
+ );
+ },
+ );
+ } else {
+ context.read<ShareTabBloc>().add(
+ ShareTabEvent.removeUsers(emails: [user.email]),
+ );
+ }
},
);
}
void _onListenShareWithUserState(
BuildContext context,
- ShareWithUserState state,
+ ShareTabState state,
) {
final shareResult = state.shareResult;
if (shareResult != null) {
diff --git a/frontend/appflowy_flutter/lib/features/share_tab/presentation/widgets/access_level_list_widget.dart b/frontend/appflowy_flutter/lib/features/share_tab/presentation/widgets/access_level_list_widget.dart
index b648b43d49..3a33170a66 100644
--- a/frontend/appflowy_flutter/lib/features/share_tab/presentation/widgets/access_level_list_widget.dart
+++ b/frontend/appflowy_flutter/lib/features/share_tab/presentation/widgets/access_level_list_widget.dart
@@ -43,6 +43,11 @@ class AccessLevelListCallbacks {
}
}
+enum AdditionalUserManagementOptions {
+ turnIntoMember,
+ removeAccess,
+}
+
/// A widget that displays a list of access levels for sharing.
///
/// This widget is used in a popover to allow users to select different access levels
@@ -53,6 +58,7 @@ class AccessLevelListWidget extends StatelessWidget {
required this.selectedAccessLevel,
required this.callbacks,
required this.supportedAccessLevels,
+ required this.additionalUserManagementOptions,
});
/// The currently selected access level
@@ -64,6 +70,9 @@ class AccessLevelListWidget extends StatelessWidget {
/// Supported access levels
final List<ShareAccessLevel> supportedAccessLevels;
+ /// Additional user management options
+ final List<AdditionalUserManagementOptions> additionalUserManagementOptions;
+
@override
Widget build(BuildContext context) {
final theme = AppFlowyTheme.of(context);
@@ -83,25 +92,23 @@ class AccessLevelListWidget extends StatelessWidget {
],
// Additional user management options
- AFTextMenuItem(
- title: LocaleKeys.shareTab_turnIntoMember.tr(),
- onTap: callbacks.onTurnIntoMember,
- ),
- AFTextMenuItem(
- title: LocaleKeys.shareTab_removeAccess.tr(),
- titleColor: theme.textColorScheme.error,
- onTap: callbacks.onRemoveAccess,
- ),
+ if (additionalUserManagementOptions
+ .contains(AdditionalUserManagementOptions.turnIntoMember))
+ AFTextMenuItem(
+ title: LocaleKeys.shareTab_turnIntoMember.tr(),
+ onTap: callbacks.onTurnIntoMember,
+ ),
+ if (additionalUserManagementOptions
+ .contains(AdditionalUserManagementOptions.removeAccess))
+ AFTextMenuItem(
+ title: LocaleKeys.shareTab_removeAccess.tr(),
+ titleColor: theme.textColorScheme.error,
+ onTap: callbacks.onRemoveAccess,
+ ),
],
);
}
- /// Builds an individual access level menu item
- ///
- /// @param context The build context
- /// @param accessLevel The access level to display
- /// @param onTap Callback when this item is tapped
- /// @return A menu item widget for the specified access level
Widget _buildAccessLevelItem(
BuildContext context, {
required ShareAccessLevel accessLevel,
diff --git a/frontend/appflowy_flutter/lib/features/share_tab/presentation/widgets/copy_link_widget.dart b/frontend/appflowy_flutter/lib/features/share_tab/presentation/widgets/copy_link_widget.dart
index 62d426b4f9..cbc3f80ccd 100644
--- a/frontend/appflowy_flutter/lib/features/share_tab/presentation/widgets/copy_link_widget.dart
+++ b/frontend/appflowy_flutter/lib/features/share_tab/presentation/widgets/copy_link_widget.dart
@@ -1,4 +1,4 @@
-import 'package:appflowy/features/share_tab/logic/share_with_user_bloc.dart';
+import 'package:appflowy/features/share_tab/logic/share_tab_bloc.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';
@@ -19,37 +19,62 @@ class CopyLinkWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
final theme = AppFlowyTheme.of(context);
- return Row(
- children: [
- Expanded(
- child: AFTextField(
- initialText: shareLink,
- size: AFTextFieldSize.m,
- readOnly: true,
- ),
+ return Container(
+ padding: EdgeInsets.symmetric(
+ vertical: theme.spacing.m,
+ horizontal: theme.spacing.l,
+ ),
+ decoration: BoxDecoration(
+ color: theme.surfaceContainerColorScheme.layer01,
+ borderRadius: BorderRadius.circular(theme.spacing.m),
+ border: Border.all(
+ color: theme.borderColorScheme.primary,
),
- HSpace(theme.spacing.s),
- AFOutlinedIconTextButton.normal(
- text: LocaleKeys.shareTab_copyLink.tr(),
- size: AFButtonSize.l,
- padding: EdgeInsets.symmetric(
- horizontal: theme.spacing.l,
- vertical: theme.spacing.s,
- ),
- iconBuilder: (context, isHovering, disabled) => FlowySvg(
+ ),
+ child: Row(
+ children: [
+ FlowySvg(
FlowySvgs.toolbar_link_m,
),
- onTap: () {
- context.read<ShareWithUserBloc>().add(
- ShareWithUserEvent.copyLink(link: shareLink),
- );
+ HSpace(theme.spacing.m),
+ Expanded(
+ child: Text(
+ 'People above can access with the link',
+ style: theme.textStyle.caption.standard(
+ color: theme.textColorScheme.primary,
+ ),
+ overflow: TextOverflow.ellipsis,
+ ),
+ ),
+ AFOutlinedTextButton.normal(
+ text: LocaleKeys.shareTab_copyLink.tr(),
+ size: AFButtonSize.l,
+ padding: EdgeInsets.symmetric(
+ horizontal: theme.spacing.l,
+ vertical: theme.spacing.s,
+ ),
+ backgroundColor: (context, isHovering, disabled) {
+ final theme = AppFlowyTheme.of(context);
+ if (disabled) {
+ return theme.fillColorScheme.content;
+ }
+ if (isHovering) {
+ return theme.fillColorScheme.contentHover;
+ }
+ return theme.surfaceColorScheme.layer02;
+ },
+ onTap: () {
+ context.read<ShareTabBloc>().add(
+ ShareTabEvent.copyShareLink(link: shareLink),
+ );
- showToastNotification(
- message: LocaleKeys.shareTab_copiedLinkToClipboard.tr(),
- );
- },
- ),
- ],
+ showToastNotification(
+ message: LocaleKeys.shareTab_copiedLinkToClipboard.tr(),
+ );
+ },
+ ),
+ ],
+ ),
);
}
}
diff --git a/frontend/appflowy_flutter/lib/features/share_tab/presentation/widgets/edit_access_level_widget.dart b/frontend/appflowy_flutter/lib/features/share_tab/presentation/widgets/edit_access_level_widget.dart
index 238f1ccd6f..0e88b2a0ca 100644
--- a/frontend/appflowy_flutter/lib/features/share_tab/presentation/widgets/edit_access_level_widget.dart
+++ b/frontend/appflowy_flutter/lib/features/share_tab/presentation/widgets/edit_access_level_widget.dart
@@ -11,6 +11,7 @@ class EditAccessLevelWidget extends StatefulWidget {
required this.callbacks,
required this.selectedAccessLevel,
required this.supportedAccessLevels,
+ required this.additionalUserManagementOptions,
this.disabled = false,
});
@@ -26,6 +27,9 @@ class EditAccessLevelWidget extends StatefulWidget {
/// Supported access levels
final List<ShareAccessLevel> supportedAccessLevels;
+ /// Additional user management options
+ final List<AdditionalUserManagementOptions> additionalUserManagementOptions;
+
@override
State<EditAccessLevelWidget> createState() => _EditAccessLevelWidgetState();
}
@@ -52,6 +56,8 @@ class _EditAccessLevelWidgetState extends State<EditAccessLevelWidget> {
return AccessLevelListWidget(
selectedAccessLevel: widget.selectedAccessLevel,
supportedAccessLevels: widget.supportedAccessLevels,
+ additionalUserManagementOptions:
+ widget.additionalUserManagementOptions,
callbacks: widget.callbacks.copyWith(
onSelectAccessLevel: (accessLevel) {
widget.callbacks.onSelectAccessLevel(accessLevel);
diff --git a/frontend/appflowy_flutter/lib/features/share_tab/presentation/widgets/general_access_section.dart b/frontend/appflowy_flutter/lib/features/share_tab/presentation/widgets/general_access_section.dart
index 718ef8e9cc..320908f45b 100644
--- a/frontend/appflowy_flutter/lib/features/share_tab/presentation/widgets/general_access_section.dart
+++ b/frontend/appflowy_flutter/lib/features/share_tab/presentation/widgets/general_access_section.dart
@@ -1,9 +1,15 @@
+import 'package:appflowy/features/share_tab/data/models/shared_group.dart';
import 'package:appflowy/features/share_tab/presentation/widgets/shared_group_widget.dart';
import 'package:appflowy_ui/appflowy_ui.dart';
import 'package:flutter/material.dart';
class GeneralAccessSection extends StatelessWidget {
- const GeneralAccessSection({super.key});
+ const GeneralAccessSection({
+ super.key,
+ required this.group,
+ });
+
+ final SharedGroup group;
@override
Widget build(BuildContext context) {
@@ -11,10 +17,13 @@ class GeneralAccessSection extends StatelessWidget {
return AFMenuSection(
title: 'General access',
padding: EdgeInsets.symmetric(
- vertical: theme.spacing.s,
+ vertical: theme.spacing.xs,
+ horizontal: theme.spacing.m,
),
children: [
- SharedGroupWidget(),
+ SharedGroupWidget(
+ group: group,
+ ),
],
);
}
diff --git a/frontend/appflowy_flutter/lib/features/share_tab/presentation/widgets/guest_tag.dart b/frontend/appflowy_flutter/lib/features/share_tab/presentation/widgets/guest_tag.dart
new file mode 100644
index 0000000000..f5384c677e
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/features/share_tab/presentation/widgets/guest_tag.dart
@@ -0,0 +1,34 @@
+import 'package:appflowy/generated/locale_keys.g.dart';
+import 'package:appflowy_ui/appflowy_ui.dart';
+import 'package:easy_localization/easy_localization.dart';
+import 'package:flutter/material.dart';
+
+class GuestTag extends StatelessWidget {
+ const GuestTag({super.key});
+
+ @override
+ Widget build(BuildContext context) {
+ final theme = AppFlowyTheme.of(context);
+ return Container(
+ padding: EdgeInsets.only(
+ left: theme.spacing.m,
+ right: theme.spacing.m,
+ bottom: 2,
+ ),
+ decoration: BoxDecoration(
+ color: theme.fillColorScheme.warningLight,
+ borderRadius: BorderRadius.circular(theme.spacing.s),
+ ),
+ child: Text(
+ LocaleKeys.shareTab_guest.tr(),
+ style: theme.textStyle.caption
+ .standard(
+ color: theme.textColorScheme.warning,
+ )
+ .copyWith(
+ height: 16.0 / 12.0,
+ ),
+ ),
+ );
+ }
+}
diff --git a/frontend/appflowy_flutter/lib/features/share_tab/presentation/widgets/people_with_access_section.dart b/frontend/appflowy_flutter/lib/features/share_tab/presentation/widgets/people_with_access_section.dart
index 85ae8f46ce..6416bcee57 100644
--- a/frontend/appflowy_flutter/lib/features/share_tab/presentation/widgets/people_with_access_section.dart
+++ b/frontend/appflowy_flutter/lib/features/share_tab/presentation/widgets/people_with_access_section.dart
@@ -57,6 +57,7 @@ class PeopleWithAccessSection extends StatelessWidget {
),
padding: EdgeInsets.symmetric(
vertical: theme.spacing.xs,
+ horizontal: theme.spacing.m,
),
children: users.map((user) {
if (currentUser == null) {
diff --git a/frontend/appflowy_flutter/lib/features/share_tab/presentation/widgets/shared_group_widget.dart b/frontend/appflowy_flutter/lib/features/share_tab/presentation/widgets/shared_group_widget.dart
index 2b372be2cd..565f267018 100644
--- a/frontend/appflowy_flutter/lib/features/share_tab/presentation/widgets/shared_group_widget.dart
+++ b/frontend/appflowy_flutter/lib/features/share_tab/presentation/widgets/shared_group_widget.dart
@@ -1,15 +1,20 @@
import 'package:appflowy/features/share_tab/data/models/share_access_level.dart';
+import 'package:appflowy/features/share_tab/data/models/shared_group.dart';
import 'package:appflowy/features/share_tab/presentation/widgets/access_level_list_widget.dart';
import 'package:appflowy/features/share_tab/presentation/widgets/edit_access_level_widget.dart';
-import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
+import 'package:appflowy/workspace/presentation/home/menu/sidebar/workspace/_sidebar_workspace_icon.dart';
import 'package:appflowy_ui/appflowy_ui.dart';
import 'package:easy_localization/easy_localization.dart';
-import 'package:flowy_infra_ui/widget/spacing.dart';
import 'package:flutter/material.dart';
class SharedGroupWidget extends StatelessWidget {
- const SharedGroupWidget({super.key});
+ const SharedGroupWidget({
+ super.key,
+ required this.group,
+ });
+
+ final SharedGroup group;
@override
Widget build(BuildContext context) {
@@ -18,11 +23,13 @@ class SharedGroupWidget extends StatelessWidget {
return AFMenuItem(
padding: EdgeInsets.symmetric(
vertical: theme.spacing.s,
+ horizontal: theme.spacing.m,
),
leading: _buildLeading(context),
title: _buildTitle(context),
subtitle: _buildSubtitle(context),
trailing: _buildTrailing(context),
+ onTap: () {},
);
}
@@ -30,9 +37,17 @@ class SharedGroupWidget extends StatelessWidget {
return AFAvatar(
child: Padding(
padding: const EdgeInsets.all(3.0),
- child: FlowySvg(
- FlowySvgs.app_logo_s, // replace it with group avatar
- blendMode: null,
+ child: WorkspaceIcon(
+ isEditable: false,
+ workspaceIcon: group.icon,
+ workspaceName: group.name,
+ iconSize: 32.0,
+ emojiSize: 24.0,
+ fontSize: 24.0,
+ onSelected: (r) {},
+ borderRadius: 8.0,
+ showBorder: false,
+ figmaLineHeight: 24.0,
),
),
);
@@ -44,18 +59,22 @@ class SharedGroupWidget extends StatelessWidget {
children: [
Flexible(
child: Text(
- LocaleKeys.shareTab_anyoneAtWorkspace.tr(),
+ LocaleKeys.shareTab_anyoneAtWorkspace.tr(
+ namedArgs: {
+ 'workspace': group.name,
+ },
+ ),
style: theme.textStyle.body.standard(
color: theme.textColorScheme.primary,
),
overflow: TextOverflow.ellipsis,
),
),
- HSpace(theme.spacing.xs),
- FlowySvg(
- FlowySvgs.arrow_down_s,
- color: theme.textColorScheme.secondary,
- ),
+ // HSpace(theme.spacing.xs),
+ // FlowySvg(
+ // FlowySvgs.arrow_down_s,
+ // color: theme.textColorScheme.secondary,
+ // ),
],
);
}
@@ -75,8 +94,9 @@ class SharedGroupWidget extends StatelessWidget {
return EditAccessLevelWidget(
disabled: true,
supportedAccessLevels: ShareAccessLevel.values,
- selectedAccessLevel: ShareAccessLevel.fullAccess,
+ selectedAccessLevel: ShareAccessLevel.readAndWrite,
callbacks: AccessLevelListCallbacks.none(),
+ additionalUserManagementOptions: [],
);
}
}
diff --git a/frontend/appflowy_flutter/lib/features/share_tab/presentation/widgets/shared_user_widget.dart b/frontend/appflowy_flutter/lib/features/share_tab/presentation/widgets/shared_user_widget.dart
index 12332f76c7..631f66c583 100644
--- a/frontend/appflowy_flutter/lib/features/share_tab/presentation/widgets/shared_user_widget.dart
+++ b/frontend/appflowy_flutter/lib/features/share_tab/presentation/widgets/shared_user_widget.dart
@@ -1,6 +1,7 @@
import 'package:appflowy/features/share_tab/data/models/models.dart';
import 'package:appflowy/features/share_tab/presentation/widgets/access_level_list_widget.dart';
import 'package:appflowy/features/share_tab/presentation/widgets/edit_access_level_widget.dart';
+import 'package:appflowy/features/share_tab/presentation/widgets/guest_tag.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy_ui/appflowy_ui.dart';
import 'package:easy_localization/easy_localization.dart';
@@ -27,6 +28,7 @@ class SharedUserWidget extends StatelessWidget {
return AFMenuItem(
padding: EdgeInsets.symmetric(
vertical: theme.spacing.s,
+ horizontal: theme.spacing.m,
),
leading: AFAvatar(
name: user.name,
@@ -35,6 +37,9 @@ class SharedUserWidget extends StatelessWidget {
title: _buildTitle(context),
subtitle: _buildSubtitle(context),
trailing: _buildTrailing(context),
+ onTap: () {
+ // callbacks?.onSelectAccessLevel.call(user, user.accessLevel);
+ },
);
}
@@ -60,20 +65,15 @@ class SharedUserWidget extends StatelessWidget {
HSpace(theme.spacing.xs),
Text(
LocaleKeys.shareTab_you.tr(),
- style: theme.textStyle.body.standard(
+ style: theme.textStyle.caption.standard(
color: theme.textColorScheme.secondary,
),
),
],
// if the user is a guest, show 'Guest'
if (user.role == ShareRole.guest) ...[
- HSpace(theme.spacing.xs),
- Text(
- LocaleKeys.shareTab_guest.tr(),
- style: theme.textStyle.body.standard(
- color: theme.textColorScheme.warning,
- ),
- ),
+ HSpace(theme.spacing.m),
+ const GuestTag(),
],
],
);
@@ -108,8 +108,18 @@ class SharedUserWidget extends StatelessWidget {
ShareRole.owner => [ShareAccessLevel.fullAccess],
};
// The current guest user can't edit the access level of the other user
- return isCurrentUser ||
- currentUser.role == ShareRole.guest ||
+ if (isCurrentUser) {
+ return EditAccessLevelWidget(
+ selectedAccessLevel: user.accessLevel,
+ supportedAccessLevels: [],
+ additionalUserManagementOptions: [
+ AdditionalUserManagementOptions.removeAccess,
+ ],
+ callbacks: callbacks ?? AccessLevelListCallbacks.none(),
+ );
+ }
+
+ return currentUser.role == ShareRole.guest ||
user.role == ShareRole.member ||
user.role == ShareRole.owner
? AFGhostTextButton.disabled(
@@ -121,6 +131,10 @@ class SharedUserWidget extends StatelessWidget {
: EditAccessLevelWidget(
selectedAccessLevel: user.accessLevel,
supportedAccessLevels: supportedAccessLevels,
+ additionalUserManagementOptions: [
+ AdditionalUserManagementOptions.turnIntoMember,
+ AdditionalUserManagementOptions.removeAccess,
+ ],
callbacks: callbacks ?? AccessLevelListCallbacks.none(),
);
}
diff --git a/frontend/appflowy_flutter/lib/features/shared_section/data/local_share_pages_repository.dart b/frontend/appflowy_flutter/lib/features/shared_section/data/repositories/local_shared_pages_repository_impl.dart
similarity index 82%
rename from frontend/appflowy_flutter/lib/features/shared_section/data/local_share_pages_repository.dart
rename to frontend/appflowy_flutter/lib/features/shared_section/data/repositories/local_shared_pages_repository_impl.dart
index 31341bc6f0..b3266ac032 100644
--- a/frontend/appflowy_flutter/lib/features/shared_section/data/local_share_pages_repository.dart
+++ b/frontend/appflowy_flutter/lib/features/shared_section/data/repositories/local_shared_pages_repository_impl.dart
@@ -1,11 +1,12 @@
import 'package:appflowy/features/share_tab/data/models/share_access_level.dart';
-import 'package:appflowy/features/shared_section/data/share_pages_repository.dart';
+import 'package:appflowy/features/shared_section/data/repositories/shared_pages_repository.dart';
import 'package:appflowy/features/shared_section/models/shared_page.dart';
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:appflowy_result/appflowy_result.dart';
-class LocalSharePagesRepository implements SharePagesRepository {
+// Move this file to test folder
+class LocalSharedPagesRepositoryImpl implements SharedPagesRepository {
@override
Future<FlowyResult<SharedPages, FlowyError>> getSharedPages() async {
final pages = [
diff --git a/frontend/appflowy_flutter/lib/features/shared_section/data/rust_share_pagers_repository.dart b/frontend/appflowy_flutter/lib/features/shared_section/data/repositories/rust_shared_pages_repository_impl.dart
similarity index 83%
rename from frontend/appflowy_flutter/lib/features/shared_section/data/rust_share_pagers_repository.dart
rename to frontend/appflowy_flutter/lib/features/shared_section/data/repositories/rust_shared_pages_repository_impl.dart
index 811801acd5..0e0ddf79a2 100644
--- a/frontend/appflowy_flutter/lib/features/shared_section/data/rust_share_pagers_repository.dart
+++ b/frontend/appflowy_flutter/lib/features/shared_section/data/repositories/rust_shared_pages_repository_impl.dart
@@ -1,4 +1,4 @@
-import 'package:appflowy/features/shared_section/data/share_pages_repository.dart';
+import 'package:appflowy/features/shared_section/data/repositories/shared_pages_repository.dart';
import 'package:appflowy/features/shared_section/models/shared_page.dart';
import 'package:appflowy/features/util/extensions.dart';
import 'package:appflowy_backend/dispatch/dispatch.dart';
@@ -6,7 +6,7 @@ import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
import 'package:appflowy_result/appflowy_result.dart';
-class RustSharePagesRepository implements SharePagesRepository {
+class RustSharePagesRepositoryImpl implements SharedPagesRepository {
@override
Future<FlowyResult<SharedPages, FlowyError>> getSharedPages() async {
final result = await FolderEventGetSharedViews().send();
diff --git a/frontend/appflowy_flutter/lib/features/shared_section/data/share_pages_repository.dart b/frontend/appflowy_flutter/lib/features/shared_section/data/repositories/shared_pages_repository.dart
similarity index 92%
rename from frontend/appflowy_flutter/lib/features/shared_section/data/share_pages_repository.dart
rename to frontend/appflowy_flutter/lib/features/shared_section/data/repositories/shared_pages_repository.dart
index d7e87832f2..c70efc83af 100644
--- a/frontend/appflowy_flutter/lib/features/shared_section/data/share_pages_repository.dart
+++ b/frontend/appflowy_flutter/lib/features/shared_section/data/repositories/shared_pages_repository.dart
@@ -6,7 +6,7 @@ import 'package:appflowy_result/appflowy_result.dart';
///
/// For example, we're using rust events now, but we can still use the http api
/// for the future.
-abstract class SharePagesRepository {
+abstract class SharedPagesRepository {
/// Gets the list of users and their roles for a shared page.
Future<FlowyResult<SharedPages, FlowyError>> getSharedPages();
}
diff --git a/frontend/appflowy_flutter/lib/features/shared_section/logic/shared_section_bloc.dart b/frontend/appflowy_flutter/lib/features/shared_section/logic/shared_section_bloc.dart
index 0865b163fd..9e650c07cd 100644
--- a/frontend/appflowy_flutter/lib/features/shared_section/logic/shared_section_bloc.dart
+++ b/frontend/appflowy_flutter/lib/features/shared_section/logic/shared_section_bloc.dart
@@ -1,15 +1,16 @@
import 'dart:async';
import 'package:appflowy/core/notification/folder_notification.dart';
-import 'package:appflowy/features/shared_section/data/share_pages_repository.dart';
-import 'package:appflowy/features/shared_section/models/shared_page.dart';
+import 'package:appflowy/features/shared_section/data/repositories/shared_pages_repository.dart';
+import 'package:appflowy/features/shared_section/logic/shared_section_event.dart';
+import 'package:appflowy/features/shared_section/logic/shared_section_state.dart';
import 'package:appflowy/features/util/extensions.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/protobuf.dart';
import 'package:bloc/bloc.dart';
-import 'package:freezed_annotation/freezed_annotation.dart';
-part 'shared_section_bloc.freezed.dart';
+export 'shared_section_event.dart';
+export 'shared_section_state.dart';
class SharedSectionBloc extends Bloc<SharedSectionEvent, SharedSectionState> {
SharedSectionBloc({
@@ -18,16 +19,17 @@ class SharedSectionBloc extends Bloc<SharedSectionEvent, SharedSectionState> {
this.enablePolling = false,
this.pollingIntervalSeconds = 30,
}) : super(SharedSectionState.initial()) {
- on<_Init>(_onInit);
- on<_Refresh>(_onRefresh);
- on<_UpdateSharedPages>(_onUpdateSharedPages);
+ on<SharedSectionInitEvent>(_onInit);
+ on<SharedSectionRefreshEvent>(_onRefresh);
+ on<SharedSectionUpdateSharedPagesEvent>(_onUpdateSharedPages);
+ on<SharedSectionToggleExpandedEvent>(_onToggleExpanded);
}
final String workspaceId;
// The repository to fetch the shared views.
// If you need to test this bloc, you can add your own repository implementation.
- final SharePagesRepository repository;
+ final SharedPagesRepository repository;
// Used to listen for shared view updates.
late final FolderNotificationListener _folderNotificationListener;
@@ -49,7 +51,7 @@ class SharedSectionBloc extends Bloc<SharedSectionEvent, SharedSectionState> {
}
Future<void> _onInit(
- _Init event,
+ SharedSectionInitEvent event,
Emitter<SharedSectionState> emit,
) async {
_initFolderNotificationListener();
@@ -83,7 +85,7 @@ class SharedSectionBloc extends Bloc<SharedSectionEvent, SharedSectionState> {
}
Future<void> _onRefresh(
- _Refresh event,
+ SharedSectionRefreshEvent event,
Emitter<SharedSectionState> emit,
) async {
final result = await repository.getSharedPages();
@@ -107,7 +109,7 @@ class SharedSectionBloc extends Bloc<SharedSectionEvent, SharedSectionState> {
}
void _onUpdateSharedPages(
- _UpdateSharedPages event,
+ SharedSectionUpdateSharedPagesEvent event,
Emitter<SharedSectionState> emit,
) {
emit(
@@ -117,6 +119,17 @@ class SharedSectionBloc extends Bloc<SharedSectionEvent, SharedSectionState> {
);
}
+ void _onToggleExpanded(
+ SharedSectionToggleExpandedEvent event,
+ Emitter<SharedSectionState> emit,
+ ) {
+ emit(
+ state.copyWith(
+ isExpanded: !state.isExpanded,
+ ),
+ );
+ }
+
void _initFolderNotificationListener() {
_folderNotificationListener = FolderNotificationListener(
objectId: workspaceId,
@@ -156,31 +169,3 @@ class SharedSectionBloc extends Bloc<SharedSectionEvent, SharedSectionState> {
}
}
}
-
-@freezed
-class SharedSectionEvent with _$SharedSectionEvent {
- /// Initialize, it will create a folder notification listener to listen for shared view updates.
- /// Also, it will fetch the shared pages from the repository.
- const factory SharedSectionEvent.init() = _Init;
-
- /// Refresh, it will re-fetch the shared pages from the repository.
- const factory SharedSectionEvent.refresh() = _Refresh;
-
- /// Update the shared pages in the state.
- const factory SharedSectionEvent.updateSharedPages({
- required SharedPages sharedPages,
- }) = _UpdateSharedPages;
-}
-
-@freezed
-class SharedSectionState with _$SharedSectionState {
- const factory SharedSectionState({
- @Default([]) SharedPages sharedPages,
- @Default(false) bool isLoading,
- @Default('') String errorMessage,
- }) = _SharedSectionState;
-
- const SharedSectionState._();
-
- factory SharedSectionState.initial() => const SharedSectionState();
-}
diff --git a/frontend/appflowy_flutter/lib/features/shared_section/logic/shared_section_event.dart b/frontend/appflowy_flutter/lib/features/shared_section/logic/shared_section_event.dart
new file mode 100644
index 0000000000..ac7381667e
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/features/shared_section/logic/shared_section_event.dart
@@ -0,0 +1,42 @@
+import 'package:appflowy/features/shared_section/models/shared_page.dart';
+
+/// Base class for all SharedSection events
+sealed class SharedSectionEvent {
+ const SharedSectionEvent();
+
+ /// Initialize, it will create a folder notification listener to listen for shared view updates.
+ /// Also, it will fetch the shared pages from the repository.
+ const factory SharedSectionEvent.init() = SharedSectionInitEvent;
+
+ /// Refresh, it will re-fetch the shared pages from the repository.
+ const factory SharedSectionEvent.refresh() = SharedSectionRefreshEvent;
+
+ /// Update the shared pages in the state.
+ const factory SharedSectionEvent.updateSharedPages({
+ required SharedPages sharedPages,
+ }) = SharedSectionUpdateSharedPagesEvent;
+
+ /// Toggle the expanded status of the shared section.
+ const factory SharedSectionEvent.toggleExpanded() =
+ SharedSectionToggleExpandedEvent;
+}
+
+class SharedSectionInitEvent extends SharedSectionEvent {
+ const SharedSectionInitEvent();
+}
+
+class SharedSectionRefreshEvent extends SharedSectionEvent {
+ const SharedSectionRefreshEvent();
+}
+
+class SharedSectionUpdateSharedPagesEvent extends SharedSectionEvent {
+ const SharedSectionUpdateSharedPagesEvent({
+ required this.sharedPages,
+ });
+
+ final SharedPages sharedPages;
+}
+
+class SharedSectionToggleExpandedEvent extends SharedSectionEvent {
+ const SharedSectionToggleExpandedEvent();
+}
diff --git a/frontend/appflowy_flutter/lib/features/shared_section/logic/shared_section_state.dart b/frontend/appflowy_flutter/lib/features/shared_section/logic/shared_section_state.dart
new file mode 100644
index 0000000000..c4a1d84789
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/features/shared_section/logic/shared_section_state.dart
@@ -0,0 +1,56 @@
+import 'package:appflowy/features/shared_section/models/shared_page.dart';
+
+class SharedSectionState {
+ factory SharedSectionState.initial() => const SharedSectionState();
+
+ const SharedSectionState({
+ this.sharedPages = const [],
+ this.isLoading = false,
+ this.errorMessage = '',
+ this.isExpanded = true,
+ });
+
+ final SharedPages sharedPages;
+ final bool isLoading;
+ final String errorMessage;
+ final bool isExpanded;
+
+ SharedSectionState copyWith({
+ SharedPages? sharedPages,
+ bool? isLoading,
+ String? errorMessage,
+ bool? isExpanded,
+ }) {
+ return SharedSectionState(
+ sharedPages: sharedPages ?? this.sharedPages,
+ isLoading: isLoading ?? this.isLoading,
+ errorMessage: errorMessage ?? this.errorMessage,
+ isExpanded: isExpanded ?? this.isExpanded,
+ );
+ }
+
+ @override
+ bool operator ==(Object other) {
+ if (identical(this, other)) return true;
+ return other is SharedSectionState &&
+ other.sharedPages == sharedPages &&
+ other.isLoading == isLoading &&
+ other.errorMessage == errorMessage &&
+ other.isExpanded == isExpanded;
+ }
+
+ @override
+ int get hashCode {
+ return Object.hash(
+ sharedPages,
+ isLoading,
+ errorMessage,
+ isExpanded,
+ );
+ }
+
+ @override
+ String toString() {
+ return 'SharedSectionState(sharedPages: $sharedPages, isLoading: $isLoading, errorMessage: $errorMessage, isExpanded: $isExpanded)';
+ }
+}
diff --git a/frontend/appflowy_flutter/lib/features/shared_section/presentation/shared_section.dart b/frontend/appflowy_flutter/lib/features/shared_section/presentation/shared_section.dart
index 80382ef63d..f26ec3c48b 100644
--- a/frontend/appflowy_flutter/lib/features/shared_section/presentation/shared_section.dart
+++ b/frontend/appflowy_flutter/lib/features/shared_section/presentation/shared_section.dart
@@ -1,4 +1,4 @@
-import 'package:appflowy/features/shared_section/data/rust_share_pagers_repository.dart';
+import 'package:appflowy/features/shared_section/data/repositories/rust_shared_pages_repository_impl.dart';
import 'package:appflowy/features/shared_section/logic/shared_section_bloc.dart';
import 'package:appflowy/features/shared_section/presentation/widgets/refresh_button.dart';
import 'package:appflowy/features/shared_section/presentation/widgets/shared_pages_list.dart';
@@ -11,6 +11,7 @@ import 'package:appflowy/workspace/application/tabs/tabs_bloc.dart';
import 'package:appflowy/workspace/application/view/view_bloc.dart';
import 'package:appflowy/workspace/application/view/view_ext.dart';
import 'package:appflowy/workspace/application/view/view_service.dart';
+import 'package:appflowy/workspace/presentation/home/menu/sidebar/space/shared_widget.dart';
import 'package:appflowy/workspace/presentation/home/menu/view/view_action_type.dart';
import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';
import 'package:easy_localization/easy_localization.dart';
@@ -29,12 +30,14 @@ class SharedSection extends StatelessWidget {
@override
Widget build(BuildContext context) {
+ final repository = RustSharePagesRepositoryImpl();
+
return BlocProvider(
create: (_) => SharedSectionBloc(
workspaceId: workspaceId,
- repository: RustSharePagesRepository(),
+ repository: repository,
enablePolling: true,
- )..add(const SharedSectionEvent.init()),
+ )..add(const SharedSectionInitEvent()),
child: BlocBuilder<SharedSectionBloc, SharedSectionState>(
builder: (context, state) {
if (state.isLoading) {
@@ -54,55 +57,76 @@ class SharedSection extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Shared header
- const SharedSectionHeader(),
+ SharedSectionHeader(
+ onTap: () {
+ // expand or collapse the shared section
+ context.read<SharedSectionBloc>().add(
+ const SharedSectionToggleExpandedEvent(),
+ );
+ },
+ ),
// Shared pages list
- SharedPagesList(
- sharedPages: state.sharedPages,
- onSetEditing: (context, value) {
- context.read<ViewBloc>().add(ViewEvent.setIsEditing(value));
- },
- onAction: (action, view, data) async {
- switch (action) {
- case ViewMoreActionType.favorite:
- case ViewMoreActionType.unFavorite:
- context
- .read<FavoriteBloc>()
- .add(FavoriteEvent.toggle(view));
- break;
- case ViewMoreActionType.openInNewTab:
+ if (state.isExpanded)
+ SharedPagesList(
+ sharedPages: state.sharedPages,
+ onSetEditing: (context, value) {
+ context.read<ViewBloc>().add(ViewEvent.setIsEditing(value));
+ },
+ onAction: (action, view, data) async {
+ switch (action) {
+ case ViewMoreActionType.favorite:
+ case ViewMoreActionType.unFavorite:
+ context
+ .read<FavoriteBloc>()
+ .add(FavoriteEvent.toggle(view));
+ break;
+ case ViewMoreActionType.openInNewTab:
+ context.read<TabsBloc>().openTab(view);
+ break;
+ case ViewMoreActionType.rename:
+ await NavigatorTextFieldDialog(
+ title: LocaleKeys.disclosureAction_rename.tr(),
+ autoSelectAllText: true,
+ value: view.nameOrDefault,
+ maxLength: 256,
+ onConfirm: (newValue, _) {
+ // can not use bloc here because it has been disposed.
+ ViewBackendService.updateView(
+ viewId: view.id,
+ name: newValue,
+ );
+ },
+ ).show(context);
+ break;
+ case ViewMoreActionType.leaveSharedPage:
+ // show a dialog to confirm the action
+ await showConfirmDialog(
+ context: context,
+ title: 'Remove your own access',
+ description: '',
+ style: ConfirmPopupStyle.cancelAndOk,
+ confirmLabel: 'Remove',
+ onConfirm: () {
+ // todo: remove the access
+ },
+ );
+ break;
+ default:
+ // Other actions are not allowed for read-only access
+ break;
+ }
+ },
+ onSelected: (context, view) {
+ if (HardwareKeyboard.instance.isControlPressed) {
context.read<TabsBloc>().openTab(view);
- break;
- case ViewMoreActionType.rename:
- await NavigatorTextFieldDialog(
- title: LocaleKeys.disclosureAction_rename.tr(),
- autoSelectAllText: true,
- value: view.nameOrDefault,
- maxLength: 256,
- onConfirm: (newValue, _) {
- // can not use bloc here because it has been disposed.
- ViewBackendService.updateView(
- viewId: view.id,
- name: newValue,
- );
- },
- ).show(context);
- break;
- default:
- // Other actions are not allowed for read-only access
- break;
- }
- },
- onSelected: (context, view) {
- if (HardwareKeyboard.instance.isControlPressed) {
+ }
+ context.read<TabsBloc>().openPlugin(view);
+ },
+ onTertiarySelected: (context, view) {
context.read<TabsBloc>().openTab(view);
- }
- context.read<TabsBloc>().openPlugin(view);
- },
- onTertiarySelected: (context, view) {
- context.read<TabsBloc>().openTab(view);
- },
- ),
+ },
+ ),
// Refresh button, for debugging only
if (kDebugMode)
diff --git a/frontend/appflowy_flutter/lib/features/shared_section/presentation/widgets/shared_page_actions_button.dart b/frontend/appflowy_flutter/lib/features/shared_section/presentation/widgets/shared_page_actions_button.dart
index 0134d49b8b..4718b3b1a0 100644
--- a/frontend/appflowy_flutter/lib/features/shared_section/presentation/widgets/shared_page_actions_button.dart
+++ b/frontend/appflowy_flutter/lib/features/shared_section/presentation/widgets/shared_page_actions_button.dart
@@ -67,12 +67,12 @@ class _SharedPageActionsButtonState extends State<SharedPageActionsButton> {
padding: EdgeInsets.zero,
decoration: BoxDecoration(), // the AFMenu has a border
anchor: const AFAnchorAuto(
- offset: Offset(-8, 116),
- followerAnchor: Alignment.centerRight,
- targetAnchor: Alignment.centerLeft,
+ offset: Offset(98, 8),
),
popover: (context) => AFMenu(
width: 240,
+ backgroundColor:
+ Theme.of(context).cardColor, // to compatible with the old design
children: _buildMenuItems(context),
),
child: widget.buildChild(controller),
@@ -125,6 +125,10 @@ class _SharedPageActionsButtonState extends State<SharedPageActionsButton> {
: ViewMoreActionType.favorite,
);
+ actionTypes.add(
+ ViewMoreActionType.leaveSharedPage,
+ );
+
// Only show editable actions if access level allows it
if (widget.accessLevel != ShareAccessLevel.readOnly) {
actionTypes.addAll([
diff --git a/frontend/appflowy_flutter/lib/features/shared_section/presentation/widgets/shared_section_header.dart b/frontend/appflowy_flutter/lib/features/shared_section/presentation/widgets/shared_section_header.dart
index 203b72d8c5..676a645049 100644
--- a/frontend/appflowy_flutter/lib/features/shared_section/presentation/widgets/shared_section_header.dart
+++ b/frontend/appflowy_flutter/lib/features/shared_section/presentation/widgets/shared_section_header.dart
@@ -1,24 +1,34 @@
+import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy_ui/appflowy_ui.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
class SharedSectionHeader extends StatelessWidget {
- const SharedSectionHeader({super.key});
+ const SharedSectionHeader({
+ super.key,
+ required this.onTap,
+ });
+
+ final VoidCallback onTap;
@override
Widget build(BuildContext context) {
final theme = AppFlowyTheme.of(context);
- return Padding(
- padding: EdgeInsets.only(
- left: theme.spacing.xs,
- bottom: theme.spacing.s,
+ return AFGhostIconTextButton.primary(
+ text: LocaleKeys.shareSection_shared.tr(),
+ mainAxisAlignment: MainAxisAlignment.start,
+ size: AFButtonSize.l,
+ onTap: onTap,
+ // todo: ask the designer to provide the token.
+ padding: EdgeInsets.symmetric(
+ horizontal: 4,
+ vertical: 6,
),
- child: Text(
- LocaleKeys.shareSection_shared.tr(),
- style: theme.textStyle.caption.enhanced(
- color: theme.textColorScheme.tertiary,
- ),
+ borderRadius: theme.borderRadius.s,
+ iconBuilder: (context, isHover, disabled) => FlowySvg(
+ FlowySvgs.shared_with_me_m,
+ color: theme.badgeColorScheme.color13Thick2,
),
);
}
diff --git a/frontend/appflowy_flutter/lib/features/workspace/data/repositories/rust_workspace_repository_impl.dart b/frontend/appflowy_flutter/lib/features/workspace/data/repositories/rust_workspace_repository_impl.dart
new file mode 100644
index 0000000000..a257b3fdb3
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/features/workspace/data/repositories/rust_workspace_repository_impl.dart
@@ -0,0 +1,87 @@
+import 'package:appflowy/features/workspace/data/repositories/workspace_repository.dart';
+import 'package:appflowy/user/application/user_service.dart';
+import 'package:appflowy/workspace/presentation/settings/widgets/setting_appflowy_cloud.dart'
+ as billing_service;
+import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
+import 'package:appflowy_backend/protobuf/flowy-folder/protobuf.dart';
+import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
+import 'package:appflowy_result/appflowy_result.dart';
+import 'package:fixnum/fixnum.dart';
+
+/// Implementation of WorkspaceRepository using UserBackendService.
+class RustWorkspaceRepositoryImpl implements WorkspaceRepository {
+ RustWorkspaceRepositoryImpl({
+ required Int64 userId,
+ }) : _userService = UserBackendService(userId: userId);
+
+ final UserBackendService _userService;
+
+ @override
+ Future<FlowyResult<WorkspacePB, FlowyError>> getCurrentWorkspace() async {
+ return UserBackendService.getCurrentWorkspace();
+ }
+
+ @override
+ Future<FlowyResult<List<UserWorkspacePB>, FlowyError>> getWorkspaces() async {
+ return _userService.getWorkspaces();
+ }
+
+ @override
+ Future<FlowyResult<UserWorkspacePB, FlowyError>> createWorkspace({
+ required String name,
+ required WorkspaceTypePB workspaceType,
+ }) async {
+ return _userService.createUserWorkspace(name, workspaceType);
+ }
+
+ @override
+ Future<FlowyResult<void, FlowyError>> deleteWorkspace({
+ required String workspaceId,
+ }) async {
+ return _userService.deleteWorkspaceById(workspaceId);
+ }
+
+ @override
+ Future<FlowyResult<void, FlowyError>> openWorkspace({
+ required String workspaceId,
+ required WorkspaceTypePB workspaceType,
+ }) async {
+ return _userService.openWorkspace(workspaceId, workspaceType);
+ }
+
+ @override
+ Future<FlowyResult<void, FlowyError>> renameWorkspace({
+ required String workspaceId,
+ required String name,
+ }) async {
+ return _userService.renameWorkspace(workspaceId, name);
+ }
+
+ @override
+ Future<FlowyResult<void, FlowyError>> updateWorkspaceIcon({
+ required String workspaceId,
+ required String icon,
+ }) async {
+ return _userService.updateWorkspaceIcon(workspaceId, icon);
+ }
+
+ @override
+ Future<FlowyResult<void, FlowyError>> leaveWorkspace({
+ required String workspaceId,
+ }) async {
+ return _userService.leaveWorkspace(workspaceId);
+ }
+
+ @override
+ Future<FlowyResult<WorkspaceSubscriptionInfoPB, FlowyError>>
+ getWorkspaceSubscriptionInfo({
+ required String workspaceId,
+ }) async {
+ return UserBackendService.getWorkspaceSubscriptionInfo(workspaceId);
+ }
+
+ @override
+ Future<bool> isBillingEnabled() async {
+ return billing_service.isBillingEnabled();
+ }
+}
diff --git a/frontend/appflowy_flutter/lib/features/workspace/data/repositories/workspace_repository.dart b/frontend/appflowy_flutter/lib/features/workspace/data/repositories/workspace_repository.dart
new file mode 100644
index 0000000000..26f286c4b5
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/features/workspace/data/repositories/workspace_repository.dart
@@ -0,0 +1,59 @@
+import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
+import 'package:appflowy_backend/protobuf/flowy-folder/protobuf.dart';
+import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
+import 'package:appflowy_result/appflowy_result.dart';
+
+/// Abstract repository for workspace operations.
+///
+/// This abstracts the data source for workspace operations,
+/// allowing for different implementations (e.g., REST API, gRPC, local storage).
+abstract class WorkspaceRepository {
+ /// Gets the current workspace for the user.
+ Future<FlowyResult<WorkspacePB, FlowyError>> getCurrentWorkspace();
+
+ /// Gets the list of workspaces for the current user.
+ Future<FlowyResult<List<UserWorkspacePB>, FlowyError>> getWorkspaces();
+
+ /// Creates a new workspace.
+ Future<FlowyResult<UserWorkspacePB, FlowyError>> createWorkspace({
+ required String name,
+ required WorkspaceTypePB workspaceType,
+ });
+
+ /// Deletes a workspace by ID.
+ Future<FlowyResult<void, FlowyError>> deleteWorkspace({
+ required String workspaceId,
+ });
+
+ /// Opens a workspace.
+ Future<FlowyResult<void, FlowyError>> openWorkspace({
+ required String workspaceId,
+ required WorkspaceTypePB workspaceType,
+ });
+
+ /// Renames a workspace.
+ Future<FlowyResult<void, FlowyError>> renameWorkspace({
+ required String workspaceId,
+ required String name,
+ });
+
+ /// Updates workspace icon.
+ Future<FlowyResult<void, FlowyError>> updateWorkspaceIcon({
+ required String workspaceId,
+ required String icon,
+ });
+
+ /// Leaves a workspace.
+ Future<FlowyResult<void, FlowyError>> leaveWorkspace({
+ required String workspaceId,
+ });
+
+ /// Gets workspace subscription information.
+ Future<FlowyResult<WorkspaceSubscriptionInfoPB, FlowyError>>
+ getWorkspaceSubscriptionInfo({
+ required String workspaceId,
+ });
+
+ /// Is billing enabled.
+ Future<bool> isBillingEnabled();
+}
diff --git a/frontend/appflowy_flutter/lib/features/workspace/logic/workspace_bloc.dart b/frontend/appflowy_flutter/lib/features/workspace/logic/workspace_bloc.dart
new file mode 100644
index 0000000000..629f5d80ac
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/features/workspace/logic/workspace_bloc.dart
@@ -0,0 +1,663 @@
+import 'dart:async';
+
+import 'package:appflowy/features/workspace/data/repositories/workspace_repository.dart';
+import 'package:appflowy/features/workspace/logic/workspace_event.dart';
+import 'package:appflowy/features/workspace/logic/workspace_state.dart';
+import 'package:appflowy/generated/locale_keys.g.dart';
+import 'package:appflowy/shared/feature_flags.dart';
+import 'package:appflowy/startup/startup.dart';
+import 'package:appflowy/user/application/reminder/reminder_bloc.dart';
+import 'package:appflowy/user/application/user_listener.dart';
+import 'package:appflowy_backend/log.dart';
+import 'package:appflowy_backend/protobuf/flowy-error/code.pbenum.dart';
+import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
+import 'package:appflowy_backend/protobuf/flowy-folder/protobuf.dart';
+import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
+import 'package:appflowy_result/appflowy_result.dart';
+import 'package:bloc/bloc.dart';
+import 'package:collection/collection.dart';
+import 'package:easy_localization/easy_localization.dart';
+import 'package:protobuf/protobuf.dart';
+
+export 'workspace_event.dart';
+export 'workspace_state.dart';
+
+class _WorkspaceFetchResult {
+ const _WorkspaceFetchResult({
+ this.currentWorkspace,
+ required this.workspaces,
+ required this.shouldOpenWorkspace,
+ });
+
+ final UserWorkspacePB? currentWorkspace;
+ final List<UserWorkspacePB> workspaces;
+ final bool shouldOpenWorkspace;
+}
+
+class UserWorkspaceBloc extends Bloc<UserWorkspaceEvent, UserWorkspaceState> {
+ UserWorkspaceBloc({
+ required WorkspaceRepository repository,
+ required UserProfilePB userProfile,
+ this.initialWorkspaceId,
+ }) : _repository = repository,
+ _listener = UserListener(userProfile: userProfile),
+ super(UserWorkspaceState.initial(userProfile)) {
+ on<WorkspaceEventInitialize>(_onInitialize);
+ on<WorkspaceEventFetchWorkspaces>(_onFetchWorkspaces);
+ on<WorkspaceEventCreateWorkspace>(_onCreateWorkspace);
+ on<WorkspaceEventDeleteWorkspace>(_onDeleteWorkspace);
+ on<WorkspaceEventOpenWorkspace>(_onOpenWorkspace);
+ on<WorkspaceEventRenameWorkspace>(_onRenameWorkspace);
+ on<WorkspaceEventUpdateWorkspaceIcon>(_onUpdateWorkspaceIcon);
+ on<WorkspaceEventLeaveWorkspace>(_onLeaveWorkspace);
+ on<WorkspaceEventFetchWorkspaceSubscriptionInfo>(
+ _onFetchWorkspaceSubscriptionInfo,
+ );
+ on<WorkspaceEventUpdateWorkspaceSubscriptionInfo>(
+ _onUpdateWorkspaceSubscriptionInfo,
+ );
+ }
+
+ final String? initialWorkspaceId;
+ final WorkspaceRepository _repository;
+ final UserListener _listener;
+
+ @override
+ Future<void> close() {
+ _listener.stop();
+ return super.close();
+ }
+
+ Future<void> _onInitialize(
+ WorkspaceEventInitialize event,
+ Emitter<UserWorkspaceState> emit,
+ ) async {
+ await _setupListeners(emit);
+ await _initializeWorkspaces(emit);
+ }
+
+ Future<void> _onFetchWorkspaces(
+ WorkspaceEventFetchWorkspaces event,
+ Emitter<UserWorkspaceState> emit,
+ ) async {
+ final result = await _fetchWorkspaces(
+ initialWorkspaceId: event.initialWorkspaceId,
+ );
+
+ final currentWorkspace = result.currentWorkspace;
+ final workspaces = result.workspaces;
+ Log.info(
+ 'fetch workspaces: current workspace: ${currentWorkspace?.workspaceId}, workspaces: ${workspaces.map((e) => e.workspaceId)}',
+ );
+
+ emit(
+ state.copyWith(
+ workspaces: workspaces,
+ ),
+ );
+
+ if (currentWorkspace != null &&
+ currentWorkspace.workspaceId != state.currentWorkspace?.workspaceId) {
+ Log.info(
+ 'fetch workspaces: try to open workspace: ${currentWorkspace.workspaceId}',
+ );
+ add(
+ UserWorkspaceEvent.openWorkspace(
+ workspaceId: currentWorkspace.workspaceId,
+ workspaceType: currentWorkspace.workspaceType,
+ ),
+ );
+ }
+ }
+
+ Future<void> _onCreateWorkspace(
+ WorkspaceEventCreateWorkspace event,
+ Emitter<UserWorkspaceState> emit,
+ ) async {
+ emit(
+ state.copyWith(
+ actionResult: const WorkspaceActionResult(
+ actionType: WorkspaceActionType.create,
+ isLoading: true,
+ result: null,
+ ),
+ ),
+ );
+
+ final result = await _repository.createWorkspace(
+ name: event.name,
+ workspaceType: event.workspaceType,
+ );
+
+ final workspaces = result.fold(
+ (s) => [...state.workspaces, s],
+ (e) => state.workspaces,
+ );
+
+ emit(
+ state.copyWith(
+ workspaces: _sortWorkspaces(workspaces),
+ actionResult: WorkspaceActionResult(
+ actionType: WorkspaceActionType.create,
+ isLoading: false,
+ result: result.map((_) {}),
+ ),
+ ),
+ );
+
+ result
+ ..onSuccess((s) {
+ Log.info('create workspace success: $s');
+ add(
+ UserWorkspaceEvent.openWorkspace(
+ workspaceId: s.workspaceId,
+ workspaceType: s.workspaceType,
+ ),
+ );
+ })
+ ..onFailure((f) {
+ Log.error('create workspace error: $f');
+ });
+ }
+
+ Future<void> _onDeleteWorkspace(
+ WorkspaceEventDeleteWorkspace event,
+ Emitter<UserWorkspaceState> emit,
+ ) async {
+ Log.info('try to delete workspace: ${event.workspaceId}');
+ emit(
+ state.copyWith(
+ actionResult: const WorkspaceActionResult(
+ actionType: WorkspaceActionType.delete,
+ isLoading: true,
+ result: null,
+ ),
+ ),
+ );
+
+ final remoteWorkspaces = await _fetchWorkspaces().then(
+ (value) => value.workspaces,
+ );
+
+ if (state.workspaces.length <= 1 || remoteWorkspaces.length <= 1) {
+ final result = FlowyResult.failure(
+ FlowyError(
+ code: ErrorCode.Internal,
+ msg: LocaleKeys.workspace_cannotDeleteTheOnlyWorkspace.tr(),
+ ),
+ );
+ return emit(
+ state.copyWith(
+ actionResult: WorkspaceActionResult(
+ actionType: WorkspaceActionType.delete,
+ result: result,
+ isLoading: false,
+ ),
+ ),
+ );
+ }
+
+ final result = await _repository.deleteWorkspace(
+ workspaceId: event.workspaceId,
+ );
+ final workspacesResult = await _fetchWorkspaces();
+ final workspaces = workspacesResult.workspaces;
+ final containsDeletedWorkspace =
+ _findWorkspaceById(event.workspaceId, workspaces) != null;
+
+ result
+ ..onSuccess((_) {
+ Log.info('delete workspace success: ${event.workspaceId}');
+ final firstWorkspace = workspaces.firstOrNull;
+ assert(
+ firstWorkspace != null,
+ 'the first workspace must not be null',
+ );
+ if (state.currentWorkspace?.workspaceId == event.workspaceId &&
+ firstWorkspace != null) {
+ Log.info(
+ 'delete workspace: open the first workspace: ${firstWorkspace.workspaceId}',
+ );
+ add(
+ UserWorkspaceEvent.openWorkspace(
+ workspaceId: firstWorkspace.workspaceId,
+ workspaceType: firstWorkspace.workspaceType,
+ ),
+ );
+ }
+ })
+ ..onFailure((f) {
+ Log.error('delete workspace error: $f');
+ if (!containsDeletedWorkspace && workspaces.isNotEmpty) {
+ add(
+ UserWorkspaceEvent.openWorkspace(
+ workspaceId: workspaces.first.workspaceId,
+ workspaceType: workspaces.first.workspaceType,
+ ),
+ );
+ }
+ });
+
+ emit(
+ state.copyWith(
+ workspaces: workspaces,
+ actionResult: WorkspaceActionResult(
+ actionType: WorkspaceActionType.delete,
+ result: result,
+ isLoading: false,
+ ),
+ ),
+ );
+ }
+
+ Future<void> _onOpenWorkspace(
+ WorkspaceEventOpenWorkspace event,
+ Emitter<UserWorkspaceState> emit,
+ ) async {
+ emit(
+ state.copyWith(
+ actionResult: const WorkspaceActionResult(
+ actionType: WorkspaceActionType.open,
+ isLoading: true,
+ result: null,
+ ),
+ ),
+ );
+
+ final result = await _repository.openWorkspace(
+ workspaceId: event.workspaceId,
+ workspaceType: event.workspaceType,
+ );
+
+ final currentWorkspace = result.fold(
+ (s) => _findWorkspaceById(event.workspaceId),
+ (e) => state.currentWorkspace,
+ );
+
+ result
+ ..onSuccess((s) {
+ add(
+ UserWorkspaceEvent.fetchWorkspaceSubscriptionInfo(
+ workspaceId: event.workspaceId,
+ ),
+ );
+
+ Log.info(
+ 'open workspace success: ${event.workspaceId}, current workspace: ${currentWorkspace?.toProto3Json()}',
+ );
+ })
+ ..onFailure((f) {
+ Log.error('open workspace error: $f');
+ });
+
+ emit(
+ state.copyWith(
+ currentWorkspace: currentWorkspace,
+ actionResult: WorkspaceActionResult(
+ actionType: WorkspaceActionType.open,
+ isLoading: false,
+ result: result,
+ ),
+ ),
+ );
+
+ getIt<ReminderBloc>().add(
+ ReminderEvent.started(),
+ );
+ }
+
+ Future<void> _onRenameWorkspace(
+ WorkspaceEventRenameWorkspace event,
+ Emitter<UserWorkspaceState> emit,
+ ) async {
+ final result = await _repository.renameWorkspace(
+ workspaceId: event.workspaceId,
+ name: event.name,
+ );
+
+ final workspaces = result.fold(
+ (s) => _updateWorkspaceInList(event.workspaceId, (workspace) {
+ workspace.freeze();
+ return workspace.rebuild((p0) {
+ p0.name = event.name;
+ });
+ }),
+ (f) => state.workspaces,
+ );
+
+ final currentWorkspace = _findWorkspaceById(
+ state.currentWorkspace?.workspaceId ?? '',
+ workspaces,
+ );
+
+ Log.info('rename workspace: ${event.workspaceId}, name: ${event.name}');
+
+ result.onFailure((f) {
+ Log.error('rename workspace error: $f');
+ });
+
+ emit(
+ state.copyWith(
+ workspaces: workspaces,
+ currentWorkspace: currentWorkspace,
+ actionResult: WorkspaceActionResult(
+ actionType: WorkspaceActionType.rename,
+ isLoading: false,
+ result: result,
+ ),
+ ),
+ );
+ }
+
+ Future<void> _onUpdateWorkspaceIcon(
+ WorkspaceEventUpdateWorkspaceIcon event,
+ Emitter<UserWorkspaceState> emit,
+ ) async {
+ final workspace = _findWorkspaceById(event.workspaceId);
+ if (workspace == null) {
+ Log.error('workspace not found: ${event.workspaceId}');
+ return;
+ }
+
+ if (event.icon == workspace.icon) {
+ Log.info('ignore same icon update');
+ return;
+ }
+
+ final result = await _repository.updateWorkspaceIcon(
+ workspaceId: event.workspaceId,
+ icon: event.icon,
+ );
+
+ final workspaces = result.fold(
+ (s) => _updateWorkspaceInList(event.workspaceId, (workspace) {
+ workspace.freeze();
+ return workspace.rebuild((p0) {
+ p0.icon = event.icon;
+ });
+ }),
+ (f) => state.workspaces,
+ );
+
+ final currentWorkspace = _findWorkspaceById(
+ state.currentWorkspace?.workspaceId ?? '',
+ workspaces,
+ );
+
+ Log.info(
+ 'update workspace icon: ${event.workspaceId}, icon: ${event.icon}',
+ );
+
+ result.onFailure((f) {
+ Log.error('update workspace icon error: $f');
+ });
+
+ emit(
+ state.copyWith(
+ workspaces: workspaces,
+ currentWorkspace: currentWorkspace,
+ actionResult: WorkspaceActionResult(
+ actionType: WorkspaceActionType.updateIcon,
+ isLoading: false,
+ result: result,
+ ),
+ ),
+ );
+ }
+
+ Future<void> _onLeaveWorkspace(
+ WorkspaceEventLeaveWorkspace event,
+ Emitter<UserWorkspaceState> emit,
+ ) async {
+ final result = await _repository.leaveWorkspace(
+ workspaceId: event.workspaceId,
+ );
+
+ final workspaces = result.fold(
+ (s) => state.workspaces
+ .where((e) => e.workspaceId != event.workspaceId)
+ .toList(),
+ (e) => state.workspaces,
+ );
+
+ result
+ ..onSuccess((_) {
+ Log.info('leave workspace success: ${event.workspaceId}');
+ if (state.currentWorkspace?.workspaceId == event.workspaceId &&
+ workspaces.isNotEmpty) {
+ add(
+ UserWorkspaceEvent.openWorkspace(
+ workspaceId: workspaces.first.workspaceId,
+ workspaceType: workspaces.first.workspaceType,
+ ),
+ );
+ }
+ })
+ ..onFailure((f) {
+ Log.error('leave workspace error: $f');
+ });
+
+ emit(
+ state.copyWith(
+ workspaces: _sortWorkspaces(workspaces),
+ actionResult: WorkspaceActionResult(
+ actionType: WorkspaceActionType.leave,
+ isLoading: false,
+ result: result,
+ ),
+ ),
+ );
+ }
+
+ Future<void> _onFetchWorkspaceSubscriptionInfo(
+ WorkspaceEventFetchWorkspaceSubscriptionInfo event,
+ Emitter<UserWorkspaceState> emit,
+ ) async {
+ final enabled = await _repository.isBillingEnabled();
+ // If billing is not enabled, we don't need to fetch the workspace subscription info
+ if (!enabled) {
+ return;
+ }
+
+ unawaited(
+ _repository
+ .getWorkspaceSubscriptionInfo(
+ workspaceId: event.workspaceId,
+ )
+ .fold(
+ (workspaceSubscriptionInfo) {
+ if (isClosed) {
+ return;
+ }
+
+ if (state.currentWorkspace?.workspaceId != event.workspaceId) {
+ return;
+ }
+
+ Log.debug(
+ 'fetch workspace subscription info: ${event.workspaceId}, $workspaceSubscriptionInfo',
+ );
+
+ add(
+ UserWorkspaceEvent.updateWorkspaceSubscriptionInfo(
+ workspaceId: event.workspaceId,
+ subscriptionInfo: workspaceSubscriptionInfo,
+ ),
+ );
+ },
+ (e) => Log.error('fetch workspace subscription info error: $e'),
+ ),
+ );
+ }
+
+ Future<void> _onUpdateWorkspaceSubscriptionInfo(
+ WorkspaceEventUpdateWorkspaceSubscriptionInfo event,
+ Emitter<UserWorkspaceState> emit,
+ ) async {
+ emit(
+ state.copyWith(workspaceSubscriptionInfo: event.subscriptionInfo),
+ );
+ }
+
+ Future<void> _setupListeners(Emitter<UserWorkspaceState> emit) async {
+ _listener.start(
+ onProfileUpdated: (result) {
+ if (!isClosed && !emit.isDone) {
+ result.fold(
+ (newProfile) => emit(
+ state.copyWith(userProfile: newProfile),
+ ),
+ (error) => Log.error("Failed to get user profile: $error"),
+ );
+ }
+ },
+ onUserWorkspaceListUpdated: (workspaces) {
+ if (!isClosed && !emit.isDone) {
+ emit(
+ state.copyWith(
+ workspaces: _sortWorkspaces(workspaces.items),
+ ),
+ );
+ }
+ },
+ onUserWorkspaceUpdated: (workspace) {
+ if (!isClosed && !emit.isDone) {
+ final currentWorkspace = state.currentWorkspace;
+ if (currentWorkspace?.workspaceId == workspace.workspaceId) {
+ emit(
+ state.copyWith(currentWorkspace: workspace),
+ );
+ }
+ }
+ },
+ );
+ }
+
+ Future<void> _initializeWorkspaces(Emitter<UserWorkspaceState> emit) async {
+ final result = await _fetchWorkspaces(
+ initialWorkspaceId: initialWorkspaceId,
+ );
+ final currentWorkspace = result.currentWorkspace;
+ final workspaces = result.workspaces;
+ final isCollabWorkspaceOn =
+ state.userProfile.userAuthType == AuthTypePB.Server &&
+ FeatureFlag.collaborativeWorkspace.isOn;
+
+ Log.info(
+ 'init workspace, current workspace: ${currentWorkspace?.workspaceId}, '
+ 'workspaces: ${workspaces.map((e) => e.workspaceId)}, isCollabWorkspaceOn: $isCollabWorkspaceOn',
+ );
+
+ if (currentWorkspace != null) {
+ add(
+ UserWorkspaceEvent.fetchWorkspaceSubscriptionInfo(
+ workspaceId: currentWorkspace.workspaceId,
+ ),
+ );
+ }
+
+ if (currentWorkspace != null && result.shouldOpenWorkspace == true) {
+ Log.info('init open workspace: ${currentWorkspace.workspaceId}');
+ await _repository.openWorkspace(
+ workspaceId: currentWorkspace.workspaceId,
+ workspaceType: currentWorkspace.workspaceType,
+ );
+ }
+
+ emit(
+ state.copyWith(
+ currentWorkspace: currentWorkspace,
+ workspaces: workspaces,
+ isCollabWorkspaceOn: isCollabWorkspaceOn,
+ actionResult: const WorkspaceActionResult(
+ actionType: WorkspaceActionType.none,
+ isLoading: false,
+ result: null,
+ ),
+ ),
+ );
+ }
+
+ // Helper methods
+ List<UserWorkspacePB> _sortWorkspaces(List<UserWorkspacePB> workspaces) {
+ final sorted = [...workspaces];
+ sorted.sort(
+ (a, b) => a.createdAtTimestamp.compareTo(b.createdAtTimestamp),
+ );
+ return sorted;
+ }
+
+ UserWorkspacePB? _findWorkspaceById(
+ String id, [
+ List<UserWorkspacePB>? workspacesList,
+ ]) {
+ final workspaces = workspacesList ?? state.workspaces;
+ return workspaces.firstWhereOrNull((e) => e.workspaceId == id);
+ }
+
+ List<UserWorkspacePB> _updateWorkspaceInList(
+ String workspaceId,
+ UserWorkspacePB Function(UserWorkspacePB workspace) updater,
+ ) {
+ final workspaces = [...state.workspaces];
+ final index = workspaces.indexWhere((e) => e.workspaceId == workspaceId);
+ if (index != -1) {
+ workspaces[index] = updater(workspaces[index]);
+ }
+ return workspaces;
+ }
+
+ Future<_WorkspaceFetchResult> _fetchWorkspaces({
+ String? initialWorkspaceId,
+ }) async {
+ try {
+ final currentWorkspaceResult = await _repository.getCurrentWorkspace();
+ final currentWorkspace = currentWorkspaceResult.fold(
+ (s) => s,
+ (e) => null,
+ );
+ final currentWorkspaceId = initialWorkspaceId ?? currentWorkspace?.id;
+ final workspacesResult = await _repository.getWorkspaces();
+ final workspaces = workspacesResult.getOrThrow();
+
+ if (workspaces.isEmpty && currentWorkspace != null) {
+ workspaces.add(
+ _convertWorkspacePBToUserWorkspace(currentWorkspace),
+ );
+ }
+
+ final currentWorkspaceInList = _findWorkspaceById(
+ currentWorkspaceId ?? '',
+ workspaces,
+ ) ??
+ workspaces.firstOrNull;
+
+ final sortedWorkspaces = _sortWorkspaces(workspaces);
+
+ Log.info(
+ 'fetch workspaces: current workspace: ${currentWorkspaceInList?.workspaceId}, sorted workspaces: ${sortedWorkspaces.map((e) => '${e.name}: ${e.workspaceId}')}',
+ );
+
+ return _WorkspaceFetchResult(
+ currentWorkspace: currentWorkspaceInList,
+ workspaces: sortedWorkspaces,
+ shouldOpenWorkspace:
+ currentWorkspaceInList?.workspaceId != currentWorkspaceId,
+ );
+ } catch (e) {
+ Log.error('fetch workspace error: $e');
+ return _WorkspaceFetchResult(
+ currentWorkspace: state.currentWorkspace,
+ workspaces: state.workspaces,
+ shouldOpenWorkspace: false,
+ );
+ }
+ }
+
+ UserWorkspacePB _convertWorkspacePBToUserWorkspace(WorkspacePB workspace) {
+ return UserWorkspacePB.create()
+ ..workspaceId = workspace.id
+ ..name = workspace.name
+ ..createdAtTimestamp = workspace.createTime;
+ }
+}
diff --git a/frontend/appflowy_flutter/lib/features/workspace/logic/workspace_event.dart b/frontend/appflowy_flutter/lib/features/workspace/logic/workspace_event.dart
new file mode 100644
index 0000000000..d9be253d56
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/features/workspace/logic/workspace_event.dart
@@ -0,0 +1,163 @@
+import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
+
+sealed class UserWorkspaceEvent {
+ UserWorkspaceEvent();
+
+ // Factory functions for creating events
+ factory UserWorkspaceEvent.initialize() => WorkspaceEventInitialize();
+
+ factory UserWorkspaceEvent.fetchWorkspaces({
+ String? initialWorkspaceId,
+ }) =>
+ WorkspaceEventFetchWorkspaces(initialWorkspaceId: initialWorkspaceId);
+
+ factory UserWorkspaceEvent.createWorkspace({
+ required String name,
+ required WorkspaceTypePB workspaceType,
+ }) =>
+ WorkspaceEventCreateWorkspace(name: name, workspaceType: workspaceType);
+
+ factory UserWorkspaceEvent.deleteWorkspace({
+ required String workspaceId,
+ }) =>
+ WorkspaceEventDeleteWorkspace(workspaceId: workspaceId);
+
+ factory UserWorkspaceEvent.openWorkspace({
+ required String workspaceId,
+ required WorkspaceTypePB workspaceType,
+ }) =>
+ WorkspaceEventOpenWorkspace(
+ workspaceId: workspaceId,
+ workspaceType: workspaceType,
+ );
+
+ factory UserWorkspaceEvent.renameWorkspace({
+ required String workspaceId,
+ required String name,
+ }) =>
+ WorkspaceEventRenameWorkspace(workspaceId: workspaceId, name: name);
+
+ factory UserWorkspaceEvent.updateWorkspaceIcon({
+ required String workspaceId,
+ required String icon,
+ }) =>
+ WorkspaceEventUpdateWorkspaceIcon(
+ workspaceId: workspaceId,
+ icon: icon,
+ );
+
+ factory UserWorkspaceEvent.leaveWorkspace({
+ required String workspaceId,
+ }) =>
+ WorkspaceEventLeaveWorkspace(workspaceId: workspaceId);
+
+ factory UserWorkspaceEvent.fetchWorkspaceSubscriptionInfo({
+ required String workspaceId,
+ }) =>
+ WorkspaceEventFetchWorkspaceSubscriptionInfo(workspaceId: workspaceId);
+
+ factory UserWorkspaceEvent.updateWorkspaceSubscriptionInfo({
+ required String workspaceId,
+ required WorkspaceSubscriptionInfoPB subscriptionInfo,
+ }) =>
+ WorkspaceEventUpdateWorkspaceSubscriptionInfo(
+ workspaceId: workspaceId,
+ subscriptionInfo: subscriptionInfo,
+ );
+}
+
+/// Initializes the workspace bloc.
+class WorkspaceEventInitialize extends UserWorkspaceEvent {
+ WorkspaceEventInitialize();
+}
+
+/// Fetches the list of workspaces for the current user.
+class WorkspaceEventFetchWorkspaces extends UserWorkspaceEvent {
+ WorkspaceEventFetchWorkspaces({
+ this.initialWorkspaceId,
+ });
+
+ final String? initialWorkspaceId;
+}
+
+/// Creates a new workspace.
+class WorkspaceEventCreateWorkspace extends UserWorkspaceEvent {
+ WorkspaceEventCreateWorkspace({
+ required this.name,
+ required this.workspaceType,
+ });
+
+ final String name;
+ final WorkspaceTypePB workspaceType;
+}
+
+/// Deletes a workspace.
+class WorkspaceEventDeleteWorkspace extends UserWorkspaceEvent {
+ WorkspaceEventDeleteWorkspace({
+ required this.workspaceId,
+ });
+
+ final String workspaceId;
+}
+
+/// Opens a workspace.
+class WorkspaceEventOpenWorkspace extends UserWorkspaceEvent {
+ WorkspaceEventOpenWorkspace({
+ required this.workspaceId,
+ required this.workspaceType,
+ });
+
+ final String workspaceId;
+ final WorkspaceTypePB workspaceType;
+}
+
+/// Renames a workspace.
+class WorkspaceEventRenameWorkspace extends UserWorkspaceEvent {
+ WorkspaceEventRenameWorkspace({
+ required this.workspaceId,
+ required this.name,
+ });
+
+ final String workspaceId;
+ final String name;
+}
+
+/// Updates workspace icon.
+class WorkspaceEventUpdateWorkspaceIcon extends UserWorkspaceEvent {
+ WorkspaceEventUpdateWorkspaceIcon({
+ required this.workspaceId,
+ required this.icon,
+ });
+
+ final String workspaceId;
+ final String icon;
+}
+
+/// Leaves a workspace.
+class WorkspaceEventLeaveWorkspace extends UserWorkspaceEvent {
+ WorkspaceEventLeaveWorkspace({
+ required this.workspaceId,
+ });
+
+ final String workspaceId;
+}
+
+/// Fetches workspace subscription info.
+class WorkspaceEventFetchWorkspaceSubscriptionInfo extends UserWorkspaceEvent {
+ WorkspaceEventFetchWorkspaceSubscriptionInfo({
+ required this.workspaceId,
+ });
+
+ final String workspaceId;
+}
+
+/// Updates workspace subscription info.
+class WorkspaceEventUpdateWorkspaceSubscriptionInfo extends UserWorkspaceEvent {
+ WorkspaceEventUpdateWorkspaceSubscriptionInfo({
+ required this.workspaceId,
+ required this.subscriptionInfo,
+ });
+
+ final String workspaceId;
+ final WorkspaceSubscriptionInfoPB subscriptionInfo;
+}
diff --git a/frontend/appflowy_flutter/lib/features/workspace/logic/workspace_state.dart b/frontend/appflowy_flutter/lib/features/workspace/logic/workspace_state.dart
new file mode 100644
index 0000000000..18d5bed499
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/features/workspace/logic/workspace_state.dart
@@ -0,0 +1,103 @@
+import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
+import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
+import 'package:appflowy_result/appflowy_result.dart';
+
+enum WorkspaceActionType {
+ none,
+ create,
+ delete,
+ open,
+ rename,
+ updateIcon,
+ fetchWorkspaces,
+ leave,
+ fetchSubscriptionInfo,
+}
+
+class WorkspaceActionResult {
+ const WorkspaceActionResult({
+ required this.actionType,
+ required this.isLoading,
+ required this.result,
+ });
+
+ final WorkspaceActionType actionType;
+ final bool isLoading;
+ final FlowyResult<void, FlowyError>? result;
+
+ @override
+ String toString() {
+ return 'WorkspaceActionResult(actionType: $actionType, isLoading: $isLoading, result: $result)';
+ }
+}
+
+class UserWorkspaceState {
+ factory UserWorkspaceState.initial(UserProfilePB userProfile) =>
+ UserWorkspaceState(
+ userProfile: userProfile,
+ );
+
+ const UserWorkspaceState({
+ this.currentWorkspace,
+ this.workspaces = const [],
+ this.actionResult,
+ this.isCollabWorkspaceOn = false,
+ required this.userProfile,
+ this.workspaceSubscriptionInfo,
+ });
+
+ final UserWorkspacePB? currentWorkspace;
+ final List<UserWorkspacePB> workspaces;
+ final WorkspaceActionResult? actionResult;
+ final bool isCollabWorkspaceOn;
+ final UserProfilePB userProfile;
+ final WorkspaceSubscriptionInfoPB? workspaceSubscriptionInfo;
+
+ UserWorkspaceState copyWith({
+ UserWorkspacePB? currentWorkspace,
+ List<UserWorkspacePB>? workspaces,
+ WorkspaceActionResult? actionResult,
+ bool? isCollabWorkspaceOn,
+ UserProfilePB? userProfile,
+ WorkspaceSubscriptionInfoPB? workspaceSubscriptionInfo,
+ }) {
+ return UserWorkspaceState(
+ currentWorkspace: currentWorkspace ?? this.currentWorkspace,
+ workspaces: workspaces ?? this.workspaces,
+ actionResult: actionResult ?? this.actionResult,
+ isCollabWorkspaceOn: isCollabWorkspaceOn ?? this.isCollabWorkspaceOn,
+ userProfile: userProfile ?? this.userProfile,
+ workspaceSubscriptionInfo:
+ workspaceSubscriptionInfo ?? this.workspaceSubscriptionInfo,
+ );
+ }
+
+ @override
+ bool operator ==(Object other) {
+ if (identical(this, other)) return true;
+ return other is UserWorkspaceState &&
+ other.currentWorkspace == currentWorkspace &&
+ other.workspaces == workspaces &&
+ other.actionResult == actionResult &&
+ other.isCollabWorkspaceOn == isCollabWorkspaceOn &&
+ other.userProfile == userProfile &&
+ other.workspaceSubscriptionInfo == workspaceSubscriptionInfo;
+ }
+
+ @override
+ int get hashCode {
+ return Object.hash(
+ currentWorkspace,
+ workspaces,
+ actionResult,
+ isCollabWorkspaceOn,
+ userProfile,
+ workspaceSubscriptionInfo,
+ );
+ }
+
+ @override
+ String toString() {
+ return 'WorkspaceState(currentWorkspace: $currentWorkspace, workspaces: $workspaces, actionResult: $actionResult, isCollabWorkspaceOn: $isCollabWorkspaceOn, userProfile: $userProfile, workspaceSubscriptionInfo: $workspaceSubscriptionInfo)';
+ }
+}
diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/base/mobile_view_page.dart b/frontend/appflowy_flutter/lib/mobile/presentation/base/mobile_view_page.dart
index 863dbcd94c..162ada63f5 100644
--- a/frontend/appflowy_flutter/lib/mobile/presentation/base/mobile_view_page.dart
+++ b/frontend/appflowy_flutter/lib/mobile/presentation/base/mobile_view_page.dart
@@ -1,3 +1,6 @@
+import 'package:appflowy/features/page_access_level/logic/page_access_level_bloc.dart';
+import 'package:appflowy/features/workspace/data/repositories/rust_workspace_repository_impl.dart';
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/application/base/mobile_view_page_bloc.dart';
@@ -17,10 +20,8 @@ import 'package:appflowy/startup/plugin/plugin.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/user/application/reminder/reminder_bloc.dart';
import 'package:appflowy/workspace/application/favorite/favorite_bloc.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy/workspace/application/view/view_bloc.dart';
import 'package:appflowy/workspace/application/view/view_ext.dart';
-import 'package:appflowy/workspace/application/view/view_lock_status_bloc.dart';
import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';
import 'package:appflowy/workspace/presentation/widgets/view_title_bar.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
@@ -120,9 +121,12 @@ class _MobileViewPageState extends State<MobileViewPage> {
),
if (state.userProfilePB != null)
BlocProvider(
- create: (_) =>
- UserWorkspaceBloc(userProfile: state.userProfilePB!)
- ..add(const UserWorkspaceEvent.initial()),
+ create: (_) => UserWorkspaceBloc(
+ userProfile: state.userProfilePB!,
+ repository: RustWorkspaceRepositoryImpl(
+ userId: state.userProfilePB!.id,
+ ),
+ )..add(UserWorkspaceEvent.initialize()),
),
if (view.layout.isDocumentView)
BlocProvider(
@@ -131,8 +135,8 @@ class _MobileViewPageState extends State<MobileViewPage> {
),
if (view.layout.isDocumentView || view.layout.isDatabaseView)
BlocProvider(
- create: (_) => ViewLockStatusBloc(view: view)
- ..add(const ViewLockStatusEvent.initial()),
+ create: (_) => PageAccessLevelBloc(view: view)
+ ..add(const PageAccessLevelEvent.initial()),
),
],
child: Builder(
@@ -239,7 +243,7 @@ class _MobileViewPageState extends State<MobileViewPage> {
final isImmersiveMode =
context.read<MobileViewPageBloc>().state.isImmersiveMode;
final isLocked =
- context.read<ViewLockStatusBloc?>()?.state.isLocked ?? false;
+ context.read<PageAccessLevelBloc?>()?.state.isLocked ?? false;
final actions = <Widget>[];
if (FeatureFlag.syncDocument.isOn) {
@@ -334,7 +338,7 @@ class _MobileViewPageState extends State<MobileViewPage> {
return const SizedBox.shrink();
}
- return BlocConsumer<ViewLockStatusBloc, ViewLockStatusState>(
+ return BlocConsumer<PageAccessLevelBloc, PageAccessLevelState>(
listenWhen: (previous, current) =>
previous.isLoadingLockStatus == current.isLoadingLockStatus &&
current.isLoadingLockStatus == false,
@@ -363,7 +367,7 @@ class _MobileViewPageState extends State<MobileViewPage> {
return const SizedBox.shrink();
}
- return BlocConsumer<ViewLockStatusBloc, ViewLockStatusState>(
+ return BlocConsumer<PageAccessLevelBloc, PageAccessLevelState>(
listenWhen: (previous, current) =>
previous.isLoadingLockStatus == current.isLoadingLockStatus &&
current.isLoadingLockStatus == false,
@@ -379,8 +383,8 @@ class _MobileViewPageState extends State<MobileViewPage> {
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
- context.read<ViewLockStatusBloc>().add(
- const ViewLockStatusEvent.unlock(),
+ context.read<PageAccessLevelBloc>().add(
+ const PageAccessLevelEvent.unlock(),
);
},
child: Padding(
@@ -399,8 +403,8 @@ class _MobileViewPageState extends State<MobileViewPage> {
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
- context.read<ViewLockStatusBloc>().add(
- const ViewLockStatusEvent.lock(),
+ context.read<PageAccessLevelBloc>().add(
+ const PageAccessLevelEvent.lock(),
);
},
child: Padding(
diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/base/view_page/app_bar_buttons.dart b/frontend/appflowy_flutter/lib/mobile/presentation/base/view_page/app_bar_buttons.dart
index a91fbf577b..0cec8b0f82 100644
--- a/frontend/appflowy_flutter/lib/mobile/presentation/base/view_page/app_bar_buttons.dart
+++ b/frontend/appflowy_flutter/lib/mobile/presentation/base/view_page/app_bar_buttons.dart
@@ -1,3 +1,4 @@
+import 'package:appflowy/features/page_access_level/logic/page_access_level_bloc.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/application/base/mobile_view_page_bloc.dart';
@@ -12,7 +13,6 @@ import 'package:appflowy/plugins/shared/share/share_bloc.dart';
import 'package:appflowy/shared/icon_emoji_picker/tab.dart';
import 'package:appflowy/workspace/application/favorite/favorite_bloc.dart';
import 'package:appflowy/workspace/application/view/prelude.dart';
-import 'package:appflowy/workspace/application/view/view_lock_status_bloc.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/theme_extension.dart';
@@ -112,9 +112,9 @@ class MobileViewPageMoreButton extends StatelessWidget {
BlocProvider.value(value: context.read<MobileViewPageBloc>()),
BlocProvider.value(value: context.read<ShareBloc>()),
BlocProvider(
- create: (context) => ViewLockStatusBloc(view: view)
+ create: (context) => PageAccessLevelBloc(view: view)
..add(
- ViewLockStatusEvent.initial(),
+ PageAccessLevelEvent.initial(),
),
),
],
diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/base/view_page/more_bottom_sheet.dart b/frontend/appflowy_flutter/lib/mobile/presentation/base/view_page/more_bottom_sheet.dart
index be134e0a92..28ac0c2d2d 100644
--- a/frontend/appflowy_flutter/lib/mobile/presentation/base/view_page/more_bottom_sheet.dart
+++ b/frontend/appflowy_flutter/lib/mobile/presentation/base/view_page/more_bottom_sheet.dart
@@ -1,6 +1,7 @@
import 'dart:async';
import 'package:appflowy/core/helpers/url_launcher.dart';
+import 'package:appflowy/features/page_access_level/logic/page_access_level_bloc.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet.dart';
import 'package:appflowy/mobile/presentation/home/workspaces/create_workspace_menu.dart';
@@ -14,7 +15,6 @@ import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/util/string_extension.dart';
import 'package:appflowy/workspace/application/favorite/favorite_bloc.dart';
import 'package:appflowy/workspace/application/view/prelude.dart';
-import 'package:appflowy/workspace/application/view/view_lock_status_bloc.dart';
import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
@@ -128,11 +128,13 @@ class MobileViewPageMoreBottomSheet extends StatelessWidget {
required bool isLocked,
}) async {
if (isLocked) {
- context.read<ViewLockStatusBloc>().add(const ViewLockStatusEvent.lock());
+ context
+ .read<PageAccessLevelBloc>()
+ .add(const PageAccessLevelEvent.lock());
} else {
context
- .read<ViewLockStatusBloc>()
- .add(const ViewLockStatusEvent.unlock());
+ .read<PageAccessLevelBloc>()
+ .add(const PageAccessLevelEvent.unlock());
}
}
diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/bottom_sheet/bottom_sheet_view_item_body.dart b/frontend/appflowy_flutter/lib/mobile/presentation/bottom_sheet/bottom_sheet_view_item_body.dart
index 0ca60fe40b..cccba35e5d 100644
--- a/frontend/appflowy_flutter/lib/mobile/presentation/bottom_sheet/bottom_sheet_view_item_body.dart
+++ b/frontend/appflowy_flutter/lib/mobile/presentation/bottom_sheet/bottom_sheet_view_item_body.dart
@@ -1,7 +1,7 @@
+import 'package:appflowy/features/page_access_level/logic/page_access_level_bloc.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/widgets/widgets.dart';
-import 'package:appflowy/workspace/application/view/view_lock_status_bloc.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
@@ -43,7 +43,7 @@ class MobileViewItemBottomSheetBody extends StatelessWidget {
MobileViewItemBottomSheetBodyAction action,
) {
final isLocked =
- context.read<ViewLockStatusBloc?>()?.state.isLocked ?? false;
+ context.read<PageAccessLevelBloc?>()?.state.isLocked ?? false;
switch (action) {
case MobileViewItemBottomSheetBodyAction.rename:
return FlowyOptionTile.text(
diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/bottom_sheet/bottom_sheet_view_page.dart b/frontend/appflowy_flutter/lib/mobile/presentation/bottom_sheet/bottom_sheet_view_page.dart
index 15ce2b4d2d..636dff342d 100644
--- a/frontend/appflowy_flutter/lib/mobile/presentation/bottom_sheet/bottom_sheet_view_page.dart
+++ b/frontend/appflowy_flutter/lib/mobile/presentation/bottom_sheet/bottom_sheet_view_page.dart
@@ -1,3 +1,4 @@
+import 'package:appflowy/features/page_access_level/logic/page_access_level_bloc.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/application/base/mobile_view_page_bloc.dart';
@@ -5,7 +6,6 @@ import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet.dart';
import 'package:appflowy/mobile/presentation/widgets/flowy_mobile_quick_action_button.dart';
import 'package:appflowy/plugins/shared/share/share_bloc.dart';
import 'package:appflowy/workspace/application/view/view_ext.dart';
-import 'package:appflowy/workspace/application/view/view_lock_status_bloc.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
import 'package:easy_localization/easy_localization.dart';
@@ -112,8 +112,8 @@ class MobileViewBottomSheetBody extends StatelessWidget {
@override
Widget build(BuildContext context) {
final isFavorite = view.isFavorite;
- final isLocked =
- context.watch<ViewLockStatusBloc?>()?.state.isLocked ?? false;
+ final isEditable =
+ context.watch<PageAccessLevelBloc?>()?.state.isEditable ?? false;
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
@@ -121,7 +121,7 @@ class MobileViewBottomSheetBody extends StatelessWidget {
text: LocaleKeys.button_rename.tr(),
icon: FlowySvgs.view_item_rename_s,
iconSize: const Size.square(18),
- enable: !isLocked,
+ enable: isEditable,
onTap: () => onAction(
MobileViewBottomSheetBodyAction.rename,
),
@@ -150,12 +150,12 @@ class MobileViewBottomSheetBody extends StatelessWidget {
),
onTap: () {
final isLocked =
- context.read<ViewLockStatusBloc?>()?.state.isLocked ?? false;
+ context.read<PageAccessLevelBloc?>()?.state.isLocked ?? false;
onAction(
MobileViewBottomSheetBodyAction.lockPage,
arguments: {
MobileViewBottomSheetBodyActionArguments.isLockedKey:
- !isLocked,
+ isLocked,
},
);
},
@@ -189,7 +189,7 @@ class MobileViewBottomSheetBody extends StatelessWidget {
icon: FlowySvgs.trash_s,
iconColor: Theme.of(context).colorScheme.error,
iconSize: const Size.square(18),
- enable: !isLocked,
+ enable: isEditable,
onTap: () => onAction(
MobileViewBottomSheetBodyAction.delete,
),
@@ -264,15 +264,15 @@ class _LockPageRightIconBuilder extends StatelessWidget {
@override
Widget build(BuildContext context) {
- final isLocked =
- context.watch<ViewLockStatusBloc?>()?.state.isLocked ?? false;
+ final isEditable =
+ context.watch<PageAccessLevelBloc?>()?.state.isEditable ?? false;
return SizedBox(
width: 46,
height: 30,
child: FittedBox(
fit: BoxFit.fill,
child: CupertinoSwitch(
- value: isLocked,
+ value: isEditable,
activeTrackColor: Theme.of(context).colorScheme.primary,
onChanged: (value) {
onAction(
diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/bottom_sheet/default_mobile_action_pane.dart b/frontend/appflowy_flutter/lib/mobile/presentation/bottom_sheet/default_mobile_action_pane.dart
index d4b4292443..bc3558fb4a 100644
--- a/frontend/appflowy_flutter/lib/mobile/presentation/bottom_sheet/default_mobile_action_pane.dart
+++ b/frontend/appflowy_flutter/lib/mobile/presentation/bottom_sheet/default_mobile_action_pane.dart
@@ -1,3 +1,4 @@
+import 'package:appflowy/features/page_access_level/logic/page_access_level_bloc.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet.dart';
@@ -8,7 +9,6 @@ import 'package:appflowy/workspace/application/recent/recent_views_bloc.dart';
import 'package:appflowy/workspace/application/sidebar/folder/folder_bloc.dart';
import 'package:appflowy/workspace/application/view/view_bloc.dart';
import 'package:appflowy/workspace/application/view/view_ext.dart';
-import 'package:appflowy/workspace/application/view/view_lock_status_bloc.dart';
import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:easy_localization/easy_localization.dart';
@@ -132,8 +132,8 @@ enum MobilePaneActionType {
BlocProvider.value(value: recentViewsBloc),
BlocProvider(
create: (_) =>
- ViewLockStatusBloc(view: viewBloc.state.view)
- ..add(const ViewLockStatusEvent.initial()),
+ PageAccessLevelBloc(view: viewBloc.state.view)
+ ..add(const PageAccessLevelEvent.initial()),
),
],
child: BlocBuilder<ViewBloc, ViewState>(
diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/database/board/mobile_board_page.dart b/frontend/appflowy_flutter/lib/mobile/presentation/database/board/mobile_board_page.dart
index 29841dd22a..c01b726827 100644
--- a/frontend/appflowy_flutter/lib/mobile/presentation/database/board/mobile_board_page.dart
+++ b/frontend/appflowy_flutter/lib/mobile/presentation/database/board/mobile_board_page.dart
@@ -1,3 +1,4 @@
+import 'package:appflowy/features/page_access_level/logic/page_access_level_bloc.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/database/board/board.dart';
@@ -11,7 +12,6 @@ import 'package:appflowy/plugins/database/widgets/cell/card_cell_style_maps/mobi
import 'package:appflowy/shared/flowy_error_page.dart';
import 'package:appflowy/util/field_type_extension.dart';
import 'package:appflowy/workspace/application/settings/appearance/appearance_cubit.dart';
-import 'package:appflowy/workspace/application/view/view_lock_status_bloc.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/protobuf.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/protobuf.dart';
import 'package:appflowy_board/appflowy_board.dart';
@@ -143,8 +143,9 @@ class _BoardContentState extends State<_BoardContent> {
return state.maybeMap(
orElse: () => const SizedBox.shrink(),
ready: (state) {
- final isLocked =
- context.watch<ViewLockStatusBloc?>()?.state.isLocked ?? false;
+ final isEditable =
+ context.watch<PageAccessLevelBloc?>()?.state.isEditable ??
+ false;
final showCreateGroupButton = context
.read<BoardBloc>()
.groupingFieldType
@@ -162,15 +163,12 @@ class _BoardContentState extends State<_BoardContent> {
padding: config.groupHeaderPadding,
)
: const HSpace(16),
- trailing: showCreateGroupButton && !isLocked
+ trailing: showCreateGroupButton && isEditable
? const MobileBoardTrailing()
: const HSpace(16),
headerBuilder: (_, groupData) {
- final isLocked =
- context.read<ViewLockStatusBloc?>()?.state.isLocked ??
- false;
return IgnorePointer(
- ignoring: isLocked,
+ ignoring: !isEditable,
child: GroupCardHeader(
groupData: groupData,
),
@@ -191,15 +189,15 @@ class _BoardContentState extends State<_BoardContent> {
}
Widget _buildFooter(BuildContext context, AppFlowyGroupData columnData) {
- final isLocked =
- context.read<ViewLockStatusBloc?>()?.state.isLocked ?? false;
+ final isEditable =
+ context.read<PageAccessLevelBloc?>()?.state.isEditable ?? false;
final style = Theme.of(context);
return SizedBox(
height: 42,
width: double.infinity,
child: IgnorePointer(
- ignoring: isLocked,
+ ignoring: !isEditable,
child: TextButton.icon(
style: TextButton.styleFrom(
padding: const EdgeInsets.only(left: 8),
@@ -244,7 +242,7 @@ class _BoardContentState extends State<_BoardContent> {
final groupItemId = groupItem.row.id + groupData.group.groupId;
final isLocked =
- context.read<ViewLockStatusBloc?>()?.state.isLocked ?? false;
+ context.read<PageAccessLevelBloc?>()?.state.isLocked ?? false;
return Container(
key: ValueKey(groupItemId),
diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/favorite/mobile_favorite_folder.dart b/frontend/appflowy_flutter/lib/mobile/presentation/favorite/mobile_favorite_folder.dart
index ca012891f6..6b97e7052c 100644
--- a/frontend/appflowy_flutter/lib/mobile/presentation/favorite/mobile_favorite_folder.dart
+++ b/frontend/appflowy_flutter/lib/mobile/presentation/favorite/mobile_favorite_folder.dart
@@ -4,7 +4,7 @@ import 'package:appflowy/mobile/presentation/home/favorite_folder/mobile_home_fa
import 'package:appflowy/mobile/presentation/widgets/flowy_mobile_state_container.dart';
import 'package:appflowy/workspace/application/favorite/favorite_bloc.dart';
import 'package:appflowy/workspace/application/menu/sidebar_sections_bloc.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pb.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/favorite/mobile_favorite_page.dart b/frontend/appflowy_flutter/lib/mobile/presentation/favorite/mobile_favorite_page.dart
index 0e7a7cb4c6..bf253754ea 100644
--- a/frontend/appflowy_flutter/lib/mobile/presentation/favorite/mobile_favorite_page.dart
+++ b/frontend/appflowy_flutter/lib/mobile/presentation/favorite/mobile_favorite_page.dart
@@ -1,10 +1,11 @@
import 'dart:io';
+import 'package:appflowy/features/workspace/data/repositories/rust_workspace_repository_impl.dart';
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/mobile/presentation/favorite/mobile_favorite_folder.dart';
import 'package:appflowy/mobile/presentation/home/mobile_home_page_header.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/user/application/auth/auth_service.dart';
-import 'package:appflowy/workspace/application/user/prelude.dart';
import 'package:appflowy/workspace/presentation/home/errors/workspace_failed_screen.dart';
import 'package:appflowy_backend/dispatch/dispatch.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/workspace.pb.dart';
@@ -53,9 +54,13 @@ class MobileFavoriteScreen extends StatelessWidget {
return Scaffold(
body: SafeArea(
child: BlocProvider(
- create: (_) => UserWorkspaceBloc(userProfile: userProfile)
- ..add(
- const UserWorkspaceEvent.initial(),
+ create: (_) => UserWorkspaceBloc(
+ userProfile: userProfile,
+ repository: RustWorkspaceRepositoryImpl(
+ userId: userProfile.id,
+ ),
+ )..add(
+ UserWorkspaceEvent.initialize(),
),
child: BlocBuilder<UserWorkspaceBloc, UserWorkspaceState>(
buildWhen: (previous, current) =>
diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/home/favorite_folder/favorite_space.dart b/frontend/appflowy_flutter/lib/mobile/presentation/home/favorite_folder/favorite_space.dart
index 6282421109..44b1c837d0 100644
--- a/frontend/appflowy_flutter/lib/mobile/presentation/home/favorite_folder/favorite_space.dart
+++ b/frontend/appflowy_flutter/lib/mobile/presentation/home/favorite_folder/favorite_space.dart
@@ -1,10 +1,10 @@
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/mobile/application/mobile_router.dart';
import 'package:appflowy/mobile/presentation/home/shared/empty_placeholder.dart';
import 'package:appflowy/mobile/presentation/home/shared/mobile_page_card.dart';
import 'package:appflowy/util/theme_extension.dart';
import 'package:appflowy/workspace/application/favorite/favorite_bloc.dart';
import 'package:appflowy/workspace/application/menu/sidebar_sections_bloc.dart';
-import 'package:appflowy/workspace/application/user/prelude.dart';
import 'package:appflowy/workspace/presentation/home/home_sizes.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/home/home_space/home_space.dart b/frontend/appflowy_flutter/lib/mobile/presentation/home/home_space/home_space.dart
index 5651379522..3b5717ec5b 100644
--- a/frontend/appflowy_flutter/lib/mobile/presentation/home/home_space/home_space.dart
+++ b/frontend/appflowy_flutter/lib/mobile/presentation/home/home_space/home_space.dart
@@ -1,5 +1,5 @@
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/mobile/presentation/home/mobile_folders.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy/workspace/presentation/home/home_sizes.dart';
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
import 'package:flutter/material.dart';
diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/home/mobile_folders.dart b/frontend/appflowy_flutter/lib/mobile/presentation/home/mobile_folders.dart
index 0013650df9..58cfe08c1f 100644
--- a/frontend/appflowy_flutter/lib/mobile/presentation/home/mobile_folders.dart
+++ b/frontend/appflowy_flutter/lib/mobile/presentation/home/mobile_folders.dart
@@ -1,10 +1,10 @@
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/home/section_folder/mobile_home_section_folder.dart';
import 'package:appflowy/mobile/presentation/home/space/mobile_space.dart';
import 'package:appflowy/workspace/application/menu/sidebar_sections_bloc.dart';
import 'package:appflowy/workspace/application/sidebar/folder/folder_bloc.dart';
import 'package:appflowy/workspace/application/sidebar/space/space_bloc.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/home/mobile_home_page.dart b/frontend/appflowy_flutter/lib/mobile/presentation/home/mobile_home_page.dart
index cac9a24ae9..e8f4585daa 100644
--- a/frontend/appflowy_flutter/lib/mobile/presentation/home/mobile_home_page.dart
+++ b/frontend/appflowy_flutter/lib/mobile/presentation/home/mobile_home_page.dart
@@ -1,3 +1,4 @@
+import 'package:appflowy/features/workspace/data/repositories/rust_workspace_repository_impl.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/home/mobile_home_page_header.dart';
import 'package:appflowy/mobile/presentation/home/tab/mobile_space_tab.dart';
@@ -121,8 +122,12 @@ class _MobileHomePageState extends State<MobileHomePage> {
return MultiBlocProvider(
providers: [
BlocProvider(
- create: (_) => UserWorkspaceBloc(userProfile: widget.userProfile)
- ..add(const UserWorkspaceEvent.initial()),
+ create: (_) => UserWorkspaceBloc(
+ userProfile: widget.userProfile,
+ repository: RustWorkspaceRepositoryImpl(
+ userId: widget.userProfile.id,
+ ),
+ )..add(UserWorkspaceEvent.initialize()),
),
BlocProvider(
create: (context) =>
@@ -278,13 +283,13 @@ class _HomePageState extends State<_HomePage> {
final String? message;
ToastificationType toastType = ToastificationType.success;
switch (actionType) {
- case UserWorkspaceActionType.open:
+ case WorkspaceActionType.open:
message = result.onFailure((e) {
toastType = ToastificationType.error;
return '${LocaleKeys.workspace_openFailed.tr()}: ${e.msg}';
});
break;
- case UserWorkspaceActionType.delete:
+ case WorkspaceActionType.delete:
message = result.fold(
(s) {
toastType = ToastificationType.success;
@@ -296,7 +301,7 @@ class _HomePageState extends State<_HomePage> {
},
);
break;
- case UserWorkspaceActionType.leave:
+ case WorkspaceActionType.leave:
message = result.fold(
(s) {
toastType = ToastificationType.success;
@@ -310,7 +315,7 @@ class _HomePageState extends State<_HomePage> {
},
);
break;
- case UserWorkspaceActionType.rename:
+ case WorkspaceActionType.rename:
message = result.fold(
(s) {
toastType = ToastificationType.success;
diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/home/mobile_home_page_header.dart b/frontend/appflowy_flutter/lib/mobile/presentation/home/mobile_home_page_header.dart
index a4c2ff2061..28fb8bac1b 100644
--- a/frontend/appflowy_flutter/lib/mobile/presentation/home/mobile_home_page_header.dart
+++ b/frontend/appflowy_flutter/lib/mobile/presentation/home/mobile_home_page_header.dart
@@ -1,3 +1,4 @@
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/base/animated_gesture.dart';
@@ -9,7 +10,6 @@ import 'package:appflowy/shared/icon_emoji_picker/tab.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/util/built_in_svgs.dart';
import 'package:appflowy/workspace/application/user/settings_user_bloc.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/workspace/_sidebar_workspace_icon.dart';
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
import 'package:easy_localization/easy_localization.dart';
@@ -116,7 +116,7 @@ class _MobileWorkspace extends StatelessWidget {
alignment: Alignment.centerLeft,
onTapUp: () {
context.read<UserWorkspaceBloc>().add(
- const UserWorkspaceEvent.fetchWorkspaces(),
+ UserWorkspaceEvent.fetchWorkspaces(),
);
_showSwitchWorkspacesBottomSheet(context);
},
@@ -133,8 +133,8 @@ class _MobileWorkspace extends StatelessWidget {
borderRadius: 12.0,
onSelected: (result) => context.read<UserWorkspaceBloc>().add(
UserWorkspaceEvent.updateWorkspaceIcon(
- currentWorkspace.workspaceId,
- result.emoji,
+ workspaceId: currentWorkspace.workspaceId,
+ icon: result.emoji,
),
),
),
@@ -192,8 +192,8 @@ class _MobileWorkspace extends StatelessWidget {
context.read<UserWorkspaceBloc>().add(
UserWorkspaceEvent.openWorkspace(
- workspace.workspaceId,
- workspace.workspaceType,
+ workspaceId: workspace.workspaceId,
+ workspaceType: workspace.workspaceType,
),
);
},
diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/home/mobile_home_setting_page.dart b/frontend/appflowy_flutter/lib/mobile/presentation/home/mobile_home_setting_page.dart
index 0b160c9a8e..b92b8693a4 100644
--- a/frontend/appflowy_flutter/lib/mobile/presentation/home/mobile_home_setting_page.dart
+++ b/frontend/appflowy_flutter/lib/mobile/presentation/home/mobile_home_setting_page.dart
@@ -1,5 +1,7 @@
import 'package:appflowy/env/cloud_env.dart';
import 'package:appflowy/env/env.dart';
+import 'package:appflowy/features/workspace/data/repositories/rust_workspace_repository_impl.dart';
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/base/app_bar/app_bar.dart';
import 'package:appflowy/mobile/presentation/presentation.dart';
@@ -7,6 +9,7 @@ import 'package:appflowy/mobile/presentation/setting/ai/ai_settings_group.dart';
import 'package:appflowy/mobile/presentation/setting/cloud/cloud_setting_group.dart';
import 'package:appflowy/mobile/presentation/setting/user_session_setting_group.dart';
import 'package:appflowy/mobile/presentation/setting/workspace/workspace_setting_group.dart';
+import 'package:appflowy/mobile/presentation/widgets/flowy_mobile_state_container.dart';
import 'package:appflowy/mobile/presentation/widgets/widgets.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/user/application/auth/auth_service.dart';
@@ -72,8 +75,12 @@ class _MobileHomeSettingPageState extends State<MobileHomeSettingPage> {
Widget _buildSettingsWidget(UserProfilePB userProfile) {
return BlocProvider(
- create: (context) => UserWorkspaceBloc(userProfile: userProfile)
- ..add(const UserWorkspaceEvent.initial()),
+ create: (context) => UserWorkspaceBloc(
+ userProfile: userProfile,
+ repository: RustWorkspaceRepositoryImpl(
+ userId: userProfile.id,
+ ),
+ )..add(UserWorkspaceEvent.initialize()),
child: BlocBuilder<UserWorkspaceBloc, UserWorkspaceState>(
builder: (context, state) {
final currentWorkspaceId = state.currentWorkspace?.workspaceId ?? '';
diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/home/recent_folder/mobile_home_recent_views.dart b/frontend/appflowy_flutter/lib/mobile/presentation/home/recent_folder/mobile_home_recent_views.dart
index 661a422e0c..9e5f62409a 100644
--- a/frontend/appflowy_flutter/lib/mobile/presentation/home/recent_folder/mobile_home_recent_views.dart
+++ b/frontend/appflowy_flutter/lib/mobile/presentation/home/recent_folder/mobile_home_recent_views.dart
@@ -1,10 +1,10 @@
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet.dart';
import 'package:appflowy/mobile/presentation/home/recent_folder/mobile_recent_view.dart';
import 'package:appflowy/mobile/presentation/widgets/widgets.dart';
import 'package:appflowy/workspace/application/recent/prelude.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/protobuf.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/theme_extension.dart';
diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/home/tab/mobile_space_tab.dart b/frontend/appflowy_flutter/lib/mobile/presentation/home/tab/mobile_space_tab.dart
index fd87a5cc6d..56ad1b86df 100644
--- a/frontend/appflowy_flutter/lib/mobile/presentation/home/tab/mobile_space_tab.dart
+++ b/frontend/appflowy_flutter/lib/mobile/presentation/home/tab/mobile_space_tab.dart
@@ -1,3 +1,4 @@
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/mobile/application/mobile_router.dart';
import 'package:appflowy/mobile/presentation/home/favorite_folder/favorite_space.dart';
import 'package:appflowy/mobile/presentation/home/home_space/home_space.dart';
@@ -10,7 +11,6 @@ import 'package:appflowy/shared/icon_emoji_picker/tab.dart';
import 'package:appflowy/workspace/application/menu/sidebar_sections_bloc.dart';
import 'package:appflowy/workspace/application/sidebar/folder/folder_bloc.dart';
import 'package:appflowy/workspace/application/sidebar/space/space_bloc.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
@@ -216,6 +216,6 @@ class _MobileSpaceTabState extends State<MobileSpaceTab>
}
context
.read<UserWorkspaceBloc>()
- .add(UserWorkspaceEvent.leaveWorkspace(workspaceId));
+ .add(UserWorkspaceEvent.leaveWorkspace(workspaceId: workspaceId));
}
}
diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/home/workspaces/workspace_menu_bottom_sheet.dart b/frontend/appflowy_flutter/lib/mobile/presentation/home/workspaces/workspace_menu_bottom_sheet.dart
index ea7ea0a560..dd62372ded 100644
--- a/frontend/appflowy_flutter/lib/mobile/presentation/home/workspaces/workspace_menu_bottom_sheet.dart
+++ b/frontend/appflowy_flutter/lib/mobile/presentation/home/workspaces/workspace_menu_bottom_sheet.dart
@@ -1,3 +1,4 @@
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/base/animated_gesture.dart';
@@ -5,7 +6,6 @@ import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet.dart';
import 'package:appflowy/mobile/presentation/widgets/widgets.dart';
import 'package:appflowy/util/navigator_context_extension.dart';
import 'package:appflowy/util/theme_extension.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/workspace/_sidebar_workspace_icon.dart';
import 'package:appflowy/workspace/presentation/settings/widgets/members/workspace_member_bloc.dart';
import 'package:appflowy_backend/log.dart';
@@ -122,8 +122,8 @@ class _CreateWorkspaceButton extends StatelessWidget {
context.read<UserWorkspaceBloc>().add(
UserWorkspaceEvent.createWorkspace(
- name,
- WorkspaceTypePB.ServerW,
+ name: name,
+ workspaceType: WorkspaceTypePB.ServerW,
),
);
},
@@ -285,8 +285,8 @@ class _WorkspaceMenuItemIcon extends StatelessWidget {
borderRadius: 12.0,
onSelected: (result) => context.read<UserWorkspaceBloc>().add(
UserWorkspaceEvent.updateWorkspaceIcon(
- workspace.workspaceId,
- result.emoji,
+ workspaceId: workspace.workspaceId,
+ icon: result.emoji,
),
),
),
@@ -407,8 +407,8 @@ class _WorkspaceMenuItemTrailing extends StatelessWidget {
context.read<UserWorkspaceBloc>().add(
UserWorkspaceEvent.renameWorkspace(
- workspace.workspaceId,
- name,
+ workspaceId: workspace.workspaceId,
+ name: name,
),
);
},
@@ -428,7 +428,7 @@ class _WorkspaceMenuItemTrailing extends StatelessWidget {
(_) async {
context.read<UserWorkspaceBloc>().add(
UserWorkspaceEvent.deleteWorkspace(
- workspace.workspaceId,
+ workspaceId: workspace.workspaceId,
),
);
context.popToHome();
@@ -447,7 +447,7 @@ class _WorkspaceMenuItemTrailing extends StatelessWidget {
(_) async {
context.read<UserWorkspaceBloc>().add(
UserWorkspaceEvent.leaveWorkspace(
- workspace.workspaceId,
+ workspaceId: workspace.workspaceId,
),
);
context.popToHome();
diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/setting/workspace/workspace_setting_group.dart b/frontend/appflowy_flutter/lib/mobile/presentation/setting/workspace/workspace_setting_group.dart
index 0bc7b9c3c5..240f812cb7 100644
--- a/frontend/appflowy_flutter/lib/mobile/presentation/setting/workspace/workspace_setting_group.dart
+++ b/frontend/appflowy_flutter/lib/mobile/presentation/setting/workspace/workspace_setting_group.dart
@@ -1,6 +1,6 @@
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/setting/widgets/mobile_setting_trailing.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:collection/collection.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
diff --git a/frontend/appflowy_flutter/lib/plugins/database/board/presentation/board_page.dart b/frontend/appflowy_flutter/lib/plugins/database/board/presentation/board_page.dart
index 70d00bcd25..ab781eaa57 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/board/presentation/board_page.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/board/presentation/board_page.dart
@@ -1,5 +1,6 @@
import 'dart:io';
+import 'package:appflowy/features/page_access_level/logic/page_access_level_bloc.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/database/board/mobile_board_page.dart';
@@ -16,8 +17,7 @@ import 'package:appflowy/plugins/database/widgets/row/row_detail.dart';
import 'package:appflowy/shared/conditional_listenable_builder.dart';
import 'package:appflowy/shared/flowy_error_page.dart';
import 'package:appflowy/util/field_type_extension.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
-import 'package:appflowy/workspace/application/view/view_lock_status_bloc.dart';
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/protobuf.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:appflowy_board/appflowy_board.dart';
@@ -397,14 +397,15 @@ class _BoardContentState extends State<_BoardContent> {
value: cardContext.read<BoardActionsCubit>(),
),
BlocProvider(
- create: (_) => ViewLockStatusBloc(view: widget.view)
- ..add(ViewLockStatusEvent.initial()),
+ create: (_) => PageAccessLevelBloc(view: widget.view)
+ ..add(PageAccessLevelEvent.initial()),
),
],
- child: BlocBuilder<ViewLockStatusBloc, ViewLockStatusState>(
+ child:
+ BlocBuilder<PageAccessLevelBloc, PageAccessLevelState>(
builder: (lockStatusContext, state) {
return IgnorePointer(
- ignoring: state.isLocked,
+ ignoring: !state.isEditable,
child: _BoardCard(
afGroupData: column,
groupItem: columnItem as GroupItem,
diff --git a/frontend/appflowy_flutter/lib/plugins/database/board/presentation/widgets/board_hidden_groups.dart b/frontend/appflowy_flutter/lib/plugins/database/board/presentation/widgets/board_hidden_groups.dart
index a87f140a1b..8404e5f7d8 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/board/presentation/widgets/board_hidden_groups.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/board/presentation/widgets/board_hidden_groups.dart
@@ -1,5 +1,6 @@
import 'dart:io';
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/database/application/cell/cell_controller.dart';
@@ -13,7 +14,6 @@ import 'package:appflowy/plugins/database/tab_bar/tab_bar_view.dart';
import 'package:appflowy/plugins/database/widgets/cell/card_cell_builder.dart';
import 'package:appflowy/plugins/database/widgets/cell/card_cell_skeleton/text_card_cell.dart';
import 'package:appflowy/plugins/database/widgets/row/row_detail.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/protobuf.dart';
import 'package:collection/collection.dart';
import 'package:easy_localization/easy_localization.dart';
diff --git a/frontend/appflowy_flutter/lib/plugins/database/calendar/presentation/calendar_event_card.dart b/frontend/appflowy_flutter/lib/plugins/database/calendar/presentation/calendar_event_card.dart
index 5ef2e2c327..39ac9fb913 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/calendar/presentation/calendar_event_card.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/calendar/presentation/calendar_event_card.dart
@@ -1,3 +1,4 @@
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/mobile/presentation/database/card/card_detail/mobile_card_detail_screen.dart';
import 'package:appflowy/plugins/database/application/database_controller.dart';
import 'package:appflowy/plugins/database/application/row/row_cache.dart';
@@ -7,7 +8,6 @@ import 'package:appflowy/plugins/database/widgets/cell/card_cell_builder.dart';
import 'package:appflowy/plugins/database/widgets/cell/card_cell_style_maps/calendar_card_cell_style.dart';
import 'package:appflowy/plugins/database/widgets/row/row_detail.dart';
import 'package:appflowy/workspace/application/view/view_bloc.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:flowy_infra/size.dart';
import 'package:flowy_infra/theme_extension.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
diff --git a/frontend/appflowy_flutter/lib/plugins/database/calendar/presentation/calendar_page.dart b/frontend/appflowy_flutter/lib/plugins/database/calendar/presentation/calendar_page.dart
index e99d374f5b..80eac76393 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/calendar/presentation/calendar_page.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/calendar/presentation/calendar_page.dart
@@ -1,3 +1,4 @@
+import 'package:appflowy/features/page_access_level/logic/page_access_level_bloc.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet.dart';
@@ -10,8 +11,7 @@ import 'package:appflowy/plugins/database/grid/presentation/grid_page.dart';
import 'package:appflowy/plugins/database/grid/presentation/layout/sizes.dart';
import 'package:appflowy/plugins/database/tab_bar/desktop/setting_menu.dart';
import 'package:appflowy/plugins/database/tab_bar/tab_bar_view.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
-import 'package:appflowy/workspace/application/view/view_lock_status_bloc.dart';
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/protobuf.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:calendar_view/calendar_view.dart';
@@ -128,9 +128,9 @@ class _CalendarPageState extends State<CalendarPage> {
value: _calendarBloc,
),
BlocProvider(
- create: (context) => ViewLockStatusBloc(view: widget.view)
+ create: (context) => PageAccessLevelBloc(view: widget.view)
..add(
- ViewLockStatusEvent.initial(),
+ PageAccessLevelEvent.initial(),
),
),
],
@@ -382,11 +382,10 @@ class _CalendarPageState extends State<CalendarPage> {
// is implemnted in the develop branch(WIP). Will be replaced with that.
final events = calenderEvents.map((value) => value.event!).toList()
..sort((a, b) => a.event.timestamp.compareTo(b.event.timestamp));
- final isLocked =
- context.watch<ViewLockStatusBloc?>()?.state.isLocked ?? false;
-
+ final isEditable =
+ context.watch<PageAccessLevelBloc?>()?.state.isEditable ?? false;
return IgnorePointer(
- ignoring: isLocked,
+ ignoring: !isEditable,
child: CalendarDayCard(
viewId: widget.view.id,
isToday: isToday,
diff --git a/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/grid_page.dart b/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/grid_page.dart
index 8a40279332..eb18cb0b38 100755
--- a/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/grid_page.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/grid_page.dart
@@ -1,5 +1,6 @@
import 'dart:async';
+import 'package:appflowy/features/page_access_level/logic/page_access_level_bloc.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/database/application/row/row_service.dart';
import 'package:appflowy/plugins/database/application/tab_bar_bloc.dart';
@@ -11,8 +12,7 @@ import 'package:appflowy/plugins/database/widgets/cell/editable_cell_builder.dar
import 'package:appflowy/shared/flowy_error_page.dart';
import 'package:appflowy/workspace/application/action_navigation/action_navigation_bloc.dart';
import 'package:appflowy/workspace/application/action_navigation/navigation_action.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
-import 'package:appflowy/workspace/application/view/view_lock_status_bloc.dart';
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
@@ -145,8 +145,8 @@ class _GridPageState extends State<GridPage> {
create: (_) => gridBloc,
),
BlocProvider(
- create: (context) => ViewLockStatusBloc(view: widget.view)
- ..add(ViewLockStatusEvent.initial()),
+ create: (context) => PageAccessLevelBloc(view: widget.view)
+ ..add(PageAccessLevelEvent.initial()),
),
],
child: BlocListener<ActionNavigationBloc, ActionNavigationState>(
@@ -297,7 +297,7 @@ class _GridPageContentState extends State<GridPageContent> {
children: [
_GridHeader(
headerScrollController: headerScrollController,
- editable: !context.read<ViewLockStatusBloc>().state.isLocked,
+ editable: context.read<PageAccessLevelBloc>().state.isEditable,
shrinkWrap: widget.shrinkWrap,
),
_GridRows(
@@ -568,7 +568,7 @@ class _GridRowsState extends State<_GridRows> {
children: footer,
);
- if (context.read<ViewLockStatusBloc>().state.isLocked) {
+ if (!context.read<PageAccessLevelBloc>().state.isEditable) {
return IgnorePointer(
key: const Key('grid_footer'),
child: child,
@@ -610,7 +610,7 @@ class _GridRowsState extends State<_GridRows> {
rowId: rowId,
viewId: viewId,
index: index,
- editable: !context.watch<ViewLockStatusBloc>().state.isLocked,
+ editable: context.watch<PageAccessLevelBloc>().state.isEditable,
rowController: RowController(
viewId: viewId,
rowMeta: rowMeta,
diff --git a/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/mobile_grid_page.dart b/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/mobile_grid_page.dart
index 17e4c0ed1d..83002ccb8a 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/mobile_grid_page.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/mobile_grid_page.dart
@@ -1,3 +1,4 @@
+import 'package:appflowy/features/page_access_level/logic/page_access_level_bloc.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/database/card/card_detail/mobile_card_detail_screen.dart';
@@ -9,7 +10,6 @@ import 'package:appflowy/plugins/database/tab_bar/tab_bar_view.dart';
import 'package:appflowy/shared/flowy_error_page.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/workspace/application/action_navigation/action_navigation_bloc.dart';
-import 'package:appflowy/workspace/application/view/view_lock_status_bloc.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/protobuf.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/protobuf.dart';
@@ -183,8 +183,8 @@ class _GridPageContentState extends State<GridPageContent> {
@override
Widget build(BuildContext context) {
- final isLocked =
- context.read<ViewLockStatusBloc?>()?.state.isLocked ?? false;
+ final isEditable =
+ context.read<PageAccessLevelBloc?>()?.state.isEditable ?? false;
return BlocListener<GridBloc, GridState>(
listenWhen: (previous, current) =>
previous.createdRow != current.createdRow,
@@ -218,7 +218,7 @@ class _GridPageContentState extends State<GridPageContent> {
),
],
),
- if (!widget.shrinkWrap && !isLocked)
+ if (!widget.shrinkWrap && isEditable)
Positioned(
bottom: 16,
right: 16,
@@ -382,9 +382,9 @@ class _GridRows extends StatelessWidget {
);
}
- final isLocked =
- context.read<ViewLockStatusBloc?>()?.state.isLocked ?? false;
- if (isLocked) {
+ final isEditable =
+ context.read<PageAccessLevelBloc?>()?.state.isEditable ?? false;
+ if (!isEditable) {
child = IgnorePointer(
child: child,
);
diff --git a/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/widgets/header/mobile_grid_header.dart b/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/widgets/header/mobile_grid_header.dart
index 369bdeb523..d58a40faac 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/widgets/header/mobile_grid_header.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/widgets/header/mobile_grid_header.dart
@@ -1,3 +1,4 @@
+import 'package:appflowy/features/page_access_level/logic/page_access_level_bloc.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/database/field/mobile_field_bottom_sheets.dart';
@@ -5,7 +6,6 @@ import 'package:appflowy/plugins/database/application/field/field_controller.dar
import 'package:appflowy/plugins/database/application/field/field_info.dart';
import 'package:appflowy/plugins/database/grid/application/grid_bloc.dart';
import 'package:appflowy/plugins/database/grid/application/grid_header_bloc.dart';
-import 'package:appflowy/workspace/application/view/view_lock_status_bloc.dart';
import 'package:collection/collection.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/theme_extension.dart';
@@ -40,8 +40,8 @@ class _MobileGridHeaderState extends State<MobileGridHeader> {
Widget build(BuildContext context) {
final fieldController =
context.read<GridBloc>().databaseController.fieldController;
- final isLocked =
- context.read<ViewLockStatusBloc?>()?.state.isLocked ?? false;
+ final isEditable =
+ context.read<PageAccessLevelBloc?>()?.state.isEditable ?? false;
return BlocProvider(
create: (context) {
return GridHeaderBloc(
@@ -80,7 +80,7 @@ class _MobileGridHeaderState extends State<MobileGridHeader> {
},
),
IgnorePointer(
- ignoring: isLocked,
+ ignoring: !isEditable,
child: SizedBox(
height: _kGridHeaderHeight,
child: _GridHeader(
diff --git a/frontend/appflowy_flutter/lib/plugins/database/widgets/cell/desktop_grid/desktop_grid_relation_cell.dart b/frontend/appflowy_flutter/lib/plugins/database/widgets/cell/desktop_grid/desktop_grid_relation_cell.dart
index dda3183b59..806ab1452c 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/widgets/cell/desktop_grid/desktop_grid_relation_cell.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/widgets/cell/desktop_grid/desktop_grid_relation_cell.dart
@@ -1,9 +1,9 @@
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/database/application/cell/bloc/relation_cell_bloc.dart';
import 'package:appflowy/plugins/database/grid/presentation/layout/sizes.dart';
import 'package:appflowy/plugins/database/widgets/cell_editor/relation_cell_editor.dart';
import 'package:appflowy/plugins/database/widgets/row/cells/cell_container.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/protobuf.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
diff --git a/frontend/appflowy_flutter/lib/plugins/database/widgets/cell/desktop_row_detail/desktop_row_detail_relation_cell.dart b/frontend/appflowy_flutter/lib/plugins/database/widgets/cell/desktop_row_detail/desktop_row_detail_relation_cell.dart
index d760d3ac29..a1257c1588 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/widgets/cell/desktop_row_detail/desktop_row_detail_relation_cell.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/widgets/cell/desktop_row_detail/desktop_row_detail_relation_cell.dart
@@ -1,8 +1,8 @@
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/database/application/cell/bloc/relation_cell_bloc.dart';
import 'package:appflowy/plugins/database/widgets/cell_editor/relation_cell_editor.dart';
import 'package:appflowy/plugins/database/widgets/row/cells/cell_container.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/protobuf.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
diff --git a/frontend/appflowy_flutter/lib/plugins/database/widgets/cell_editor/relation_cell_editor.dart b/frontend/appflowy_flutter/lib/plugins/database/widgets/cell_editor/relation_cell_editor.dart
index 7f6960de9d..713cdc6fba 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/widgets/cell_editor/relation_cell_editor.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/widgets/cell_editor/relation_cell_editor.dart
@@ -1,3 +1,4 @@
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/database/application/field/type_option/relation_type_option_cubit.dart';
import 'package:appflowy/plugins/database/grid/presentation/layout/sizes.dart';
@@ -6,7 +7,6 @@ import 'package:appflowy/plugins/database/tab_bar/tab_bar_view.dart';
import 'package:appflowy/plugins/database/widgets/row/relation_row_detail.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/workspace/application/tabs/tabs_bloc.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy/workspace/application/view/view_ext.dart';
import 'package:appflowy_backend/dispatch/dispatch.dart';
import 'package:appflowy_backend/log.dart';
diff --git a/frontend/appflowy_flutter/lib/plugins/database/widgets/row/relation_row_detail.dart b/frontend/appflowy_flutter/lib/plugins/database/widgets/row/relation_row_detail.dart
index 1260641fdf..22053cb73a 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/widgets/row/relation_row_detail.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/widgets/row/relation_row_detail.dart
@@ -1,5 +1,5 @@
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/plugins/database/application/row/related_row_detail_bloc.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
diff --git a/frontend/appflowy_flutter/lib/plugins/document/document_page.dart b/frontend/appflowy_flutter/lib/plugins/document/document_page.dart
index 0a717b4d60..cc28324756 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/document_page.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/document_page.dart
@@ -1,3 +1,4 @@
+import 'package:appflowy/features/page_access_level/logic/page_access_level_bloc.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/application/page_style/document_page_style_bloc.dart';
import 'package:appflowy/plugins/document/application/document_appearance_cubit.dart';
@@ -18,7 +19,6 @@ import 'package:appflowy/workspace/application/action_navigation/action_navigati
import 'package:appflowy/workspace/application/action_navigation/navigation_action.dart';
import 'package:appflowy/workspace/application/view/prelude.dart';
import 'package:appflowy/workspace/application/view/view_ext.dart';
-import 'package:appflowy/workspace/application/view/view_lock_status_bloc.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
@@ -88,8 +88,8 @@ class _DocumentPageState extends State<DocumentPage>
BlocProvider.value(value: getIt<ActionNavigationBloc>()),
BlocProvider.value(value: documentBloc),
BlocProvider.value(
- value: ViewLockStatusBloc(view: widget.view)
- ..add(ViewLockStatusEvent.initial()),
+ value: PageAccessLevelBloc(view: widget.view)
+ ..add(PageAccessLevelEvent.initial()),
),
BlocProvider(
create: (context) =>
@@ -97,15 +97,19 @@ class _DocumentPageState extends State<DocumentPage>
lazy: false,
),
],
- child: BlocConsumer<ViewLockStatusBloc, ViewLockStatusState>(
- listenWhen: (prev, curr) => curr.isLocked != prev.isLocked,
- listener: (context, lockStatusState) {
- if (lockStatusState.isLoadingLockStatus) {
+ child: BlocConsumer<PageAccessLevelBloc, PageAccessLevelState>(
+ listenWhen: (prev, curr) =>
+ curr.isLocked != prev.isLocked ||
+ curr.accessLevel != prev.accessLevel ||
+ curr.isLoadingLockStatus != prev.isLoadingLockStatus,
+ listener: (context, pageAccessLevelState) {
+ if (pageAccessLevelState.isLoadingLockStatus) {
return;
}
- editorState?.editable = !lockStatusState.isLocked;
+
+ editorState?.editable = pageAccessLevelState.isEditable;
},
- builder: (context, lockStatusState) {
+ builder: (context, pageAccessLevelState) {
return BlocBuilder<DocumentBloc, DocumentState>(
buildWhen: shouldRebuildDocument,
builder: (context, state) {
@@ -130,9 +134,10 @@ class _DocumentPageState extends State<DocumentPage>
return MultiBlocListener(
listeners: [
- BlocListener<ViewLockStatusBloc, ViewLockStatusState>(
- listener: (context, state) =>
- editorState.editable = !state.isLocked,
+ BlocListener<PageAccessLevelBloc, PageAccessLevelState>(
+ listener: (context, state) {
+ editorState.editable = state.isEditable;
+ },
),
BlocListener<ActionNavigationBloc, ActionNavigationState>(
listenWhen: (_, curr) => curr.action != null,
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart
index edb19232be..404f087c59 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart
@@ -1,6 +1,7 @@
import 'dart:ui' as ui;
import 'package:appflowy/core/helpers/url_launcher.dart';
+import 'package:appflowy/features/page_access_level/logic/page_access_level_bloc.dart';
import 'package:appflowy/plugins/document/application/document_bloc.dart';
import 'package:appflowy/plugins/document/presentation/editor_configuration.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/background_color/theme_background_color.dart';
@@ -16,7 +17,6 @@ import 'package:appflowy/shared/feature_flags.dart';
import 'package:appflowy/workspace/application/settings/appearance/appearance_cubit.dart';
import 'package:appflowy/workspace/application/settings/shortcuts/settings_shortcuts_service.dart';
import 'package:appflowy/workspace/application/view/view_bloc.dart';
-import 'package:appflowy/workspace/application/view/view_lock_status_bloc.dart';
import 'package:appflowy/workspace/application/view_info/view_info_bloc.dart';
import 'package:appflowy/workspace/presentation/home/af_focus_manager.dart';
import 'package:appflowy_editor/appflowy_editor.dart' hide QuoteBlockKeys;
@@ -349,16 +349,16 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage>
);
final isViewDeleted = context.read<DocumentBloc>().state.isDeleted;
- final isLocked =
- context.read<ViewLockStatusBloc?>()?.state.isLocked ?? false;
+ final isEditable =
+ context.read<PageAccessLevelBloc?>()?.state.isEditable ?? true;
final editor = Directionality(
textDirection: textDirection,
child: AppFlowyEditor(
editorState: widget.editorState,
- editable: !isViewDeleted && !isLocked,
- disableSelectionService: UniversalPlatform.isMobile && isLocked,
- disableKeyboardService: UniversalPlatform.isMobile && isLocked,
+ editable: !isViewDeleted && isEditable,
+ disableSelectionService: UniversalPlatform.isMobile && !isEditable,
+ disableKeyboardService: UniversalPlatform.isMobile && !isEditable,
editorScrollController: editorScrollController,
// setup the auto focus parameters
autoFocus: widget.autoFocus ?? autoFocus,
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_create_menu.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_create_menu.dart
index 56b959a302..3acd81b96a 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_create_menu.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_create_menu.dart
@@ -1,7 +1,7 @@
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/toolbar_item/custom_link_toolbar_item.dart';
import 'package:appflowy/plugins/shared/share/constants.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_ui/appflowy_ui.dart';
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/header/document_cover_widget.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/header/document_cover_widget.dart
index 16605367ca..7c8287e550 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/header/document_cover_widget.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/header/document_cover_widget.dart
@@ -155,46 +155,49 @@ class _DocumentCoverWidgetState extends State<DocumentCoverWidget> {
@override
Widget build(BuildContext context) {
- return LayoutBuilder(
- builder: (context, constraints) {
- final offset = _calculateIconLeft(context, constraints);
- return Column(
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Stack(
- children: [
- SizedBox(
- height: _calculateOverallHeight(),
- child: DocumentHeaderToolbar(
- onIconOrCoverChanged: _saveIconOrCover,
- node: widget.node,
- editorState: widget.editorState,
- hasCover: hasCover,
- hasIcon: hasIcon,
- offset: offset,
- isCoverTitleHovered: isCoverTitleHovered,
- documentId: view.id,
- tabs: widget.tabs,
- ),
- ),
- if (hasCover)
- DocumentCover(
- view: view,
- editorState: widget.editorState,
- node: widget.node,
- coverType: coverType,
- coverDetails: coverDetails,
- onChangeCover: (type, details) =>
- _saveIconOrCover(cover: (type, details)),
+ return IgnorePointer(
+ ignoring: !widget.editorState.editable,
+ child: LayoutBuilder(
+ builder: (context, constraints) {
+ final offset = _calculateIconLeft(context, constraints);
+ return Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Stack(
+ children: [
+ SizedBox(
+ height: _calculateOverallHeight(),
+ child: DocumentHeaderToolbar(
+ onIconOrCoverChanged: _saveIconOrCover,
+ node: widget.node,
+ editorState: widget.editorState,
+ hasCover: hasCover,
+ hasIcon: hasIcon,
+ offset: offset,
+ isCoverTitleHovered: isCoverTitleHovered,
+ documentId: view.id,
+ tabs: widget.tabs,
+ ),
),
- _buildAlignedCoverIcon(context),
- ],
- ),
- _buildAlignedTitle(context),
- ],
- );
- },
+ if (hasCover)
+ DocumentCover(
+ view: view,
+ editorState: widget.editorState,
+ node: widget.node,
+ coverType: coverType,
+ coverDetails: coverDetails,
+ onChangeCover: (type, details) =>
+ _saveIconOrCover(cover: (type, details)),
+ ),
+ _buildAlignedCoverIcon(context),
+ ],
+ ),
+ _buildAlignedTitle(context),
+ ],
+ );
+ },
+ ),
);
}
@@ -301,6 +304,10 @@ class _DocumentCoverWidgetState extends State<DocumentCoverWidget> {
(CoverType, String?)? cover,
EmojiIconData? icon,
}) async {
+ if (!widget.editorState.editable) {
+ return;
+ }
+
final transaction = widget.editorState.transaction;
final coverType = widget.node.attributes[DocumentHeaderBlockKeys.coverType];
final coverDetails =
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/custom_image_block_component/image_menu.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/custom_image_block_component/image_menu.dart
index 0e270a5a08..81d7bb2587 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/custom_image_block_component/image_menu.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/custom_image_block_component/image_menu.dart
@@ -1,5 +1,6 @@
import 'dart:ui';
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/application/document_bloc.dart';
@@ -9,7 +10,6 @@ import 'package:appflowy/plugins/document/presentation/editor_plugins/image/comm
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/resizeable_image.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
import 'package:appflowy/startup/startup.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';
import 'package:appflowy/workspace/presentation/widgets/image_viewer/image_provider.dart';
import 'package:appflowy/workspace/presentation/widgets/image_viewer/interactive_image_viewer.dart';
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/multi_image_block_component/layouts/image_browser_layout.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/multi_image_block_component/layouts/image_browser_layout.dart
index a8637c9c2c..6508549973 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/multi_image_block_component/layouts/image_browser_layout.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/multi_image_block_component/layouts/image_browser_layout.dart
@@ -1,5 +1,6 @@
import 'dart:io';
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/application/document_bloc.dart';
@@ -9,7 +10,6 @@ import 'package:appflowy/plugins/document/presentation/editor_plugins/image/mult
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/multi_image_block_component/multi_image_block_component.dart';
import 'package:appflowy/shared/appflowy_network_image.dart';
import 'package:appflowy/shared/patterns/file_type_patterns.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy/workspace/presentation/widgets/image_viewer/image_provider.dart';
import 'package:appflowy/workspace/presentation/widgets/image_viewer/interactive_image_viewer.dart';
import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pb.dart';
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/resizeable_image.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/resizeable_image.dart
index 7a458add6e..64980190db 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/resizeable_image.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/resizeable_image.dart
@@ -1,12 +1,12 @@
import 'dart:io';
import 'dart:math';
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/application/prelude.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/common.dart';
import 'package:appflowy/shared/appflowy_network_image.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:easy_localization/easy_localization.dart';
diff --git a/frontend/appflowy_flutter/lib/plugins/shared/share/_shared.dart b/frontend/appflowy_flutter/lib/plugins/shared/share/_shared.dart
index 7cadebe1d4..41eede73f3 100644
--- a/frontend/appflowy_flutter/lib/plugins/shared/share/_shared.dart
+++ b/frontend/appflowy_flutter/lib/plugins/shared/share/_shared.dart
@@ -1,10 +1,10 @@
import 'package:appflowy/features/share_tab/data/models/models.dart';
-import 'package:appflowy/features/share_tab/logic/share_with_user_bloc.dart';
+import 'package:appflowy/features/share_tab/logic/share_tab_bloc.dart';
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/database/application/tab_bar_bloc.dart';
import 'package:appflowy/plugins/shared/share/share_bloc.dart';
import 'package:appflowy/plugins/shared/share/share_menu.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy_ui/appflowy_ui.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
@@ -49,7 +49,7 @@ class _ShareMenuButtonState extends State<ShareMenuButton> {
final shareBloc = context.read<ShareBloc>();
final databaseBloc = context.read<DatabaseTabBarBloc?>();
final userWorkspaceBloc = context.read<UserWorkspaceBloc>();
- final shareWithUserBloc = context.read<ShareWithUserBloc>();
+ final shareWithUserBloc = context.read<ShareTabBloc>();
// final animationDuration = const Duration(milliseconds: 120);
return BlocBuilder<ShareBloc, ShareState>(
@@ -79,7 +79,7 @@ class _ShareMenuButtonState extends State<ShareMenuButton> {
popover: (_) {
return ConstrainedBox(
constraints: const BoxConstraints(
- maxWidth: 414,
+ maxWidth: 460,
),
child: MultiBlocProvider(
providers: [
@@ -107,9 +107,7 @@ class _ShareMenuButtonState extends State<ShareMenuButton> {
popoverController.show();
/// Fetch the shared users when the popover is shown
- context
- .read<ShareWithUserBloc>()
- .add(const ShareWithUserEvent.getSharedUsers());
+ context.read<ShareTabBloc>().add(ShareTabEvent.loadSharedUsers());
},
),
);
diff --git a/frontend/appflowy_flutter/lib/plugins/shared/share/share_button.dart b/frontend/appflowy_flutter/lib/plugins/shared/share/share_button.dart
index 6fda185bd2..fec15eb219 100644
--- a/frontend/appflowy_flutter/lib/plugins/shared/share/share_button.dart
+++ b/frontend/appflowy_flutter/lib/plugins/shared/share/share_button.dart
@@ -1,12 +1,12 @@
-import 'package:appflowy/features/share_tab/data/repositories/rust_share_with_user_repository.dart';
-import 'package:appflowy/features/share_tab/logic/share_with_user_bloc.dart';
+import 'package:appflowy/features/share_tab/data/repositories/rust_share_with_user_repository_impl.dart';
+import 'package:appflowy/features/share_tab/logic/share_tab_bloc.dart';
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/database/application/tab_bar_bloc.dart';
import 'package:appflowy/plugins/shared/share/_shared.dart';
import 'package:appflowy/plugins/shared/share/share_bloc.dart';
import 'package:appflowy/plugins/shared/share/share_menu.dart';
import 'package:appflowy/startup/startup.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy/workspace/application/view/view_ext.dart';
import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
@@ -43,11 +43,11 @@ class ShareButton extends StatelessWidget {
)..add(const DatabaseTabBarEvent.initial()),
),
BlocProvider(
- create: (context) => ShareWithUserBloc(
- repository: RustShareWithUserRepository(),
+ create: (context) => ShareTabBloc(
+ repository: RustShareWithUserRepositoryImpl(),
pageId: view.id,
workspaceId: workspaceId,
- )..add(const ShareWithUserEvent.init()),
+ )..add(ShareTabEvent.initialize()),
),
],
child: BlocListener<ShareBloc, ShareState>(
diff --git a/frontend/appflowy_flutter/lib/plugins/shared/share/share_menu.dart b/frontend/appflowy_flutter/lib/plugins/shared/share/share_menu.dart
index 4b743de6f2..7e4840dde1 100644
--- a/frontend/appflowy_flutter/lib/plugins/shared/share/share_menu.dart
+++ b/frontend/appflowy_flutter/lib/plugins/shared/share/share_menu.dart
@@ -1,5 +1,6 @@
import 'package:appflowy/features/share_tab/presentation/share_tab.dart'
as share_section;
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/home/tab/_round_underline_tab_indicator.dart';
@@ -130,9 +131,16 @@ class _ShareMenuState extends State<ShareMenu>
return const ExportTab();
case ShareMenuTab.share:
if (FeatureFlag.sharedSection.isOn) {
+ final workspace =
+ context.read<UserWorkspaceBloc>().state.currentWorkspace;
+ final workspaceId = workspace?.workspaceId ??
+ context.read<ShareBloc>().state.workspaceId;
+ final pageId = context.read<ShareBloc>().state.viewId;
return share_section.ShareTab(
- workspaceId: context.read<ShareBloc>().state.workspaceId,
- pageId: context.read<ShareBloc>().state.viewId,
+ workspaceId: workspaceId,
+ pageId: pageId,
+ workspaceName: workspace?.name ?? '',
+ workspaceIcon: workspace?.icon ?? '',
);
}
diff --git a/frontend/appflowy_flutter/lib/shared/settings/show_settings.dart b/frontend/appflowy_flutter/lib/shared/settings/show_settings.dart
index 81831346e9..eeb7fe2ba6 100644
--- a/frontend/appflowy_flutter/lib/shared/settings/show_settings.dart
+++ b/frontend/appflowy_flutter/lib/shared/settings/show_settings.dart
@@ -1,7 +1,7 @@
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/plugins/document/application/document_appearance_cubit.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/workspace/application/settings/settings_dialog_bloc.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy/workspace/presentation/home/af_focus_manager.dart';
import 'package:appflowy/workspace/presentation/settings/settings_dialog.dart';
import 'package:appflowy_backend/log.dart';
diff --git a/frontend/appflowy_flutter/lib/workspace/application/user/user_workspace_bloc.dart b/frontend/appflowy_flutter/lib/workspace/application/user/user_workspace_bloc.dart
index 0bb6cb5598..0a3b4725ca 100644
--- a/frontend/appflowy_flutter/lib/workspace/application/user/user_workspace_bloc.dart
+++ b/frontend/appflowy_flutter/lib/workspace/application/user/user_workspace_bloc.dart
@@ -1,765 +1 @@
-import 'dart:async';
-
-import 'package:appflowy/generated/locale_keys.g.dart';
-import 'package:appflowy/shared/feature_flags.dart';
-import 'package:appflowy/startup/startup.dart';
-import 'package:appflowy/user/application/reminder/reminder_bloc.dart';
-import 'package:appflowy/user/application/user_listener.dart';
-import 'package:appflowy/user/application/user_service.dart';
-import 'package:appflowy/workspace/presentation/settings/widgets/setting_appflowy_cloud.dart';
-import 'package:appflowy_backend/log.dart';
-import 'package:appflowy_backend/protobuf/flowy-error/code.pbenum.dart';
-import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
-import 'package:appflowy_backend/protobuf/flowy-folder/protobuf.dart';
-import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
-import 'package:appflowy_result/appflowy_result.dart';
-import 'package:collection/collection.dart';
-import 'package:easy_localization/easy_localization.dart';
-import 'package:flutter/foundation.dart';
-import 'package:flutter_bloc/flutter_bloc.dart';
-import 'package:freezed_annotation/freezed_annotation.dart';
-import 'package:protobuf/protobuf.dart';
-
-part 'user_workspace_bloc.freezed.dart';
-
-class UserWorkspaceBloc extends Bloc<UserWorkspaceEvent, UserWorkspaceState> {
- UserWorkspaceBloc({
- required UserProfilePB userProfile,
- this.initialWorkspaceId,
- }) : _userService = UserBackendService(userId: userProfile.id),
- _listener = UserListener(userProfile: userProfile),
- super(UserWorkspaceState.initial(userProfile)) {
- on<UserWorkspaceEvent>(
- (event, emit) async {
- await event.when(
- initial: () async {
- _setupListeners();
- await _initializeWorkspaces(emit);
- },
- fetchWorkspaces: (initialWorkspaceId) async {
- await _handleFetchWorkspaces(emit, initialWorkspaceId);
- },
- createWorkspace: (name, workspaceType) async {
- await _handleCreateWorkspace(emit, name, workspaceType);
- },
- deleteWorkspace: (workspaceId) async {
- await _handleDeleteWorkspace(emit, workspaceId);
- },
- openWorkspace: (workspaceId, workspaceType) async {
- await _handleOpenWorkspace(emit, workspaceId, workspaceType);
- },
- renameWorkspace: (workspaceId, name) async {
- await _handleRenameWorkspace(emit, workspaceId, name);
- },
- updateWorkspaceIcon: (workspaceId, icon) async {
- await _handleUpdateWorkspaceIcon(emit, workspaceId, icon);
- },
- leaveWorkspace: (workspaceId) async {
- await _handleLeaveWorkspace(emit, workspaceId);
- },
- updateWorkspaces: (workspaces) async {
- emit(
- state.copyWith(
- workspaces: _sortWorkspaces(workspaces.items),
- ),
- );
- },
- updateCurrentWorkspace: (workspace) async {
- _handleUpdateCurrentWorkspace(emit, workspace);
- },
- updateUserProfile: (newUserProfile) {
- emit(
- state.copyWith(
- userProfile: newUserProfile,
- ),
- );
- },
- fetchWorkspaceSubscriptionInfo: (workspaceId) async {
- await _handleFetchWorkspaceSubscriptionInfo(emit, workspaceId);
- },
- updateWorkspaceSubscriptionInfo: (workspaceSubscriptionInfo) {
- emit(
- state.copyWith(
- workspaceSubscriptionInfo: workspaceSubscriptionInfo,
- ),
- );
- },
- );
- },
- );
- }
-
- final UserBackendService _userService;
- final UserListener _listener;
- final String? initialWorkspaceId;
-
- @override
- Future<void> close() {
- _listener.stop();
- return super.close();
- }
-
- void _setupListeners() {
- _listener.start(
- onProfileUpdated: (result) {
- if (!isClosed) {
- result.fold(
- (newProfile) =>
- add(UserWorkspaceEvent.updateUserProfile(newProfile)),
- (error) => Log.error("Failed to get user profile: $error"),
- );
- }
- },
- onUserWorkspaceListUpdated: (workspaces) =>
- add(UserWorkspaceEvent.updateWorkspaces(workspaces)),
- onUserWorkspaceUpdated: (workspace) {
- if (!isClosed) {
- final currentWorkspace = state.currentWorkspace;
- if (currentWorkspace?.workspaceId == workspace.workspaceId) {
- add(UserWorkspaceEvent.updateCurrentWorkspace(workspace));
- }
- }
- },
- );
- }
-
- Future<void> _handleFetchWorkspaceSubscriptionInfo(
- Emitter<UserWorkspaceState> emit,
- String workspaceId,
- ) async {
- final enabled = await isBillingEnabled();
- // If billing is not enabled, we don't need to fetch the workspace subscription info
- if (!enabled) {
- return;
- }
-
- unawaited(
- UserBackendService.getWorkspaceSubscriptionInfo(workspaceId).fold(
- (workspaceSubscriptionInfo) {
- if (isClosed) {
- return;
- }
-
- if (state.currentWorkspace?.workspaceId != workspaceId) {
- return;
- }
-
- Log.debug(
- 'fetch workspace subscription info: $workspaceId, $workspaceSubscriptionInfo',
- );
-
- add(
- UserWorkspaceEvent.updateWorkspaceSubscriptionInfo(
- workspaceSubscriptionInfo,
- ),
- );
- },
- (e) => Log.error('fetch workspace subscription info error: $e'),
- ),
- );
- }
-
- Future<void> _initializeWorkspaces(Emitter<UserWorkspaceState> emit) async {
- final result = await _fetchWorkspaces(
- initialWorkspaceId: initialWorkspaceId,
- );
- final currentWorkspace = result.$1;
- final workspaces = result.$2;
- final isCollabWorkspaceOn =
- state.userProfile.userAuthType == AuthTypePB.Server &&
- FeatureFlag.collaborativeWorkspace.isOn;
-
- Log.info(
- 'init workspace, current workspace: ${currentWorkspace?.workspaceId}, '
- 'workspaces: ${workspaces.map((e) => e.workspaceId)}, isCollabWorkspaceOn: $isCollabWorkspaceOn',
- );
-
- if (currentWorkspace != null) {
- add(
- UserWorkspaceEvent.fetchWorkspaceSubscriptionInfo(
- currentWorkspace.workspaceId,
- ),
- );
- }
-
- if (currentWorkspace != null && result.$3 == true) {
- Log.info('init open workspace: ${currentWorkspace.workspaceId}');
- await _userService.openWorkspace(
- currentWorkspace.workspaceId,
- currentWorkspace.workspaceType,
- );
- }
-
- emit(
- state.copyWith(
- currentWorkspace: currentWorkspace,
- workspaces: workspaces,
- isCollabWorkspaceOn: isCollabWorkspaceOn,
- actionResult: null,
- ),
- );
- }
-
- Future<void> _handleFetchWorkspaces(
- Emitter<UserWorkspaceState> emit,
- String? initialWorkspaceId,
- ) async {
- final result = await _fetchWorkspaces(
- initialWorkspaceId: initialWorkspaceId,
- );
-
- final currentWorkspace = result.$1;
- final workspaces = result.$2;
- Log.info(
- 'fetch workspaces: current workspace: ${currentWorkspace?.workspaceId}, workspaces: ${workspaces.map((e) => e.workspaceId)}',
- );
-
- emit(
- state.copyWith(
- workspaces: workspaces,
- ),
- );
-
- if (currentWorkspace != null &&
- currentWorkspace.workspaceId != state.currentWorkspace?.workspaceId) {
- Log.info(
- 'fetch workspaces: try to open workspace: ${currentWorkspace.workspaceId}',
- );
- add(
- OpenWorkspace(
- currentWorkspace.workspaceId,
- currentWorkspace.workspaceType,
- ),
- );
- }
- }
-
- Future<void> _handleCreateWorkspace(
- Emitter<UserWorkspaceState> emit,
- String name,
- WorkspaceTypePB workspaceType,
- ) async {
- emit(
- state.copyWith(
- actionResult: const UserWorkspaceActionResult(
- actionType: UserWorkspaceActionType.create,
- isLoading: true,
- result: null,
- ),
- ),
- );
-
- final result = await _userService.createUserWorkspace(
- name,
- workspaceType,
- );
-
- final workspaces = result.fold(
- (s) => [...state.workspaces, s],
- (e) => state.workspaces,
- );
-
- emit(
- state.copyWith(
- workspaces: _sortWorkspaces(workspaces),
- actionResult: UserWorkspaceActionResult(
- actionType: UserWorkspaceActionType.create,
- isLoading: false,
- result: result,
- ),
- ),
- );
-
- result
- ..onSuccess((s) {
- Log.info('create workspace success: $s');
- add(
- OpenWorkspace(
- s.workspaceId,
- s.workspaceType,
- ),
- );
- })
- ..onFailure((f) {
- Log.error('create workspace error: $f');
- });
- }
-
- Future<void> _handleDeleteWorkspace(
- Emitter<UserWorkspaceState> emit,
- String workspaceId,
- ) async {
- Log.info('try to delete workspace: $workspaceId');
- emit(
- state.copyWith(
- actionResult: const UserWorkspaceActionResult(
- actionType: UserWorkspaceActionType.delete,
- isLoading: true,
- result: null,
- ),
- ),
- );
-
- final remoteWorkspaces = await _fetchWorkspaces().then(
- (value) => value.$2,
- );
-
- if (state.workspaces.length <= 1 || remoteWorkspaces.length <= 1) {
- final result = FlowyResult.failure(
- FlowyError(
- code: ErrorCode.Internal,
- msg: LocaleKeys.workspace_cannotDeleteTheOnlyWorkspace.tr(),
- ),
- );
- return emit(
- state.copyWith(
- actionResult: UserWorkspaceActionResult(
- actionType: UserWorkspaceActionType.delete,
- result: result,
- isLoading: false,
- ),
- ),
- );
- }
-
- final result = await _userService.deleteWorkspaceById(workspaceId);
- final workspacesResult = await _fetchWorkspaces();
- final workspaces = workspacesResult.$2;
- final containsDeletedWorkspace =
- _findWorkspaceById(workspaceId, workspaces) != null;
-
- result
- ..onSuccess((_) {
- Log.info('delete workspace success: $workspaceId');
- final firstWorkspace = workspaces.firstOrNull;
- assert(
- firstWorkspace != null,
- 'the first workspace must not be null',
- );
- if (state.currentWorkspace?.workspaceId == workspaceId &&
- firstWorkspace != null) {
- Log.info(
- 'delete workspace: open the first workspace: ${firstWorkspace.workspaceId}',
- );
- add(
- OpenWorkspace(
- firstWorkspace.workspaceId,
- firstWorkspace.workspaceType,
- ),
- );
- }
- })
- ..onFailure((f) {
- Log.error('delete workspace error: $f');
- if (!containsDeletedWorkspace && workspaces.isNotEmpty) {
- add(
- OpenWorkspace(
- workspaces.first.workspaceId,
- workspaces.first.workspaceType,
- ),
- );
- }
- });
-
- emit(
- state.copyWith(
- workspaces: workspaces,
- actionResult: UserWorkspaceActionResult(
- actionType: UserWorkspaceActionType.delete,
- result: result,
- isLoading: false,
- ),
- ),
- );
- }
-
- Future<void> _handleOpenWorkspace(
- Emitter<UserWorkspaceState> emit,
- String workspaceId,
- WorkspaceTypePB workspaceType,
- ) async {
- emit(
- state.copyWith(
- actionResult: const UserWorkspaceActionResult(
- actionType: UserWorkspaceActionType.open,
- isLoading: true,
- result: null,
- ),
- ),
- );
-
- final result = await _userService.openWorkspace(
- workspaceId,
- workspaceType,
- );
-
- final currentWorkspace = result.fold(
- (s) => _findWorkspaceById(workspaceId),
- (e) => state.currentWorkspace,
- );
-
- result
- ..onSuccess((s) {
- add(
- UserWorkspaceEvent.fetchWorkspaceSubscriptionInfo(
- workspaceId,
- ),
- );
-
- Log.info(
- 'open workspace success: $workspaceId, current workspace: ${currentWorkspace?.toProto3Json()}',
- );
- })
- ..onFailure((f) {
- Log.error('open workspace error: $f');
- });
-
- emit(
- state.copyWith(
- currentWorkspace: currentWorkspace,
- actionResult: UserWorkspaceActionResult(
- actionType: UserWorkspaceActionType.open,
- isLoading: false,
- result: result,
- ),
- ),
- );
-
- getIt<ReminderBloc>().add(ReminderEvent.started());
- }
-
- Future<void> _handleRenameWorkspace(
- Emitter<UserWorkspaceState> emit,
- String workspaceId,
- String name,
- ) async {
- final result = await _userService.renameWorkspace(workspaceId, name);
-
- final workspaces = result.fold(
- (s) => _updateWorkspaceInList(workspaceId, (workspace) {
- workspace.freeze();
- return workspace.rebuild((p0) {
- p0.name = name;
- });
- }),
- (f) => state.workspaces,
- );
-
- final currentWorkspace = _findWorkspaceById(
- state.currentWorkspace?.workspaceId ?? '',
- workspaces,
- );
-
- Log.info('rename workspace: $workspaceId, name: $name');
-
- result.onFailure((f) {
- Log.error('rename workspace error: $f');
- });
-
- emit(
- state.copyWith(
- workspaces: workspaces,
- currentWorkspace: currentWorkspace,
- actionResult: UserWorkspaceActionResult(
- actionType: UserWorkspaceActionType.rename,
- isLoading: false,
- result: result,
- ),
- ),
- );
- }
-
- Future<void> _handleUpdateWorkspaceIcon(
- Emitter<UserWorkspaceState> emit,
- String workspaceId,
- String icon,
- ) async {
- final workspace = _findWorkspaceById(workspaceId);
- if (workspace == null) {
- Log.error('workspace not found: $workspaceId');
- return;
- }
-
- if (icon == workspace.icon) {
- Log.info('ignore same icon update');
- return;
- }
-
- final result = await _userService.updateWorkspaceIcon(
- workspaceId,
- icon,
- );
-
- final workspaces = result.fold(
- (s) => _updateWorkspaceInList(workspaceId, (workspace) {
- workspace.freeze();
- return workspace.rebuild((p0) {
- p0.icon = icon;
- });
- }),
- (f) => state.workspaces,
- );
-
- final currentWorkspace = _findWorkspaceById(
- state.currentWorkspace?.workspaceId ?? '',
- workspaces,
- );
-
- Log.info('update workspace icon: $workspaceId, icon: $icon');
-
- result.onFailure((f) {
- Log.error('update workspace icon error: $f');
- });
-
- emit(
- state.copyWith(
- workspaces: workspaces,
- currentWorkspace: currentWorkspace,
- actionResult: UserWorkspaceActionResult(
- actionType: UserWorkspaceActionType.updateIcon,
- isLoading: false,
- result: result,
- ),
- ),
- );
- }
-
- Future<void> _handleLeaveWorkspace(
- Emitter<UserWorkspaceState> emit,
- String workspaceId,
- ) async {
- final result = await _userService.leaveWorkspace(workspaceId);
-
- final workspaces = result.fold(
- (s) =>
- state.workspaces.where((e) => e.workspaceId != workspaceId).toList(),
- (e) => state.workspaces,
- );
-
- result
- ..onSuccess((_) {
- Log.info('leave workspace success: $workspaceId');
- if (state.currentWorkspace?.workspaceId == workspaceId &&
- workspaces.isNotEmpty) {
- add(
- OpenWorkspace(
- workspaces.first.workspaceId,
- workspaces.first.workspaceType,
- ),
- );
- }
- })
- ..onFailure((f) {
- Log.error('leave workspace error: $f');
- });
-
- emit(
- state.copyWith(
- workspaces: _sortWorkspaces(workspaces),
- actionResult: UserWorkspaceActionResult(
- actionType: UserWorkspaceActionType.leave,
- isLoading: false,
- result: result,
- ),
- ),
- );
- }
-
- void _handleUpdateCurrentWorkspace(
- Emitter<UserWorkspaceState> emit,
- UserWorkspacePB workspace,
- ) {
- final workspaces = _updateWorkspaceInList(
- workspace.workspaceId,
- (_) => workspace,
- );
-
- emit(
- state.copyWith(
- currentWorkspace: workspace,
- workspaces: _sortWorkspaces(workspaces),
- ),
- );
- }
-
- // Helper methods
- List<UserWorkspacePB> _sortWorkspaces(List<UserWorkspacePB> workspaces) {
- final sorted = [...workspaces];
- sorted.sort((a, b) => a.createdAtTimestamp.compareTo(b.createdAtTimestamp));
- return sorted;
- }
-
- UserWorkspacePB? _findWorkspaceById(
- String id, [
- List<UserWorkspacePB>? workspacesList,
- ]) {
- final workspaces = workspacesList ?? state.workspaces;
- return workspaces.firstWhereOrNull((e) => e.workspaceId == id);
- }
-
- List<UserWorkspacePB> _updateWorkspaceInList(
- String workspaceId,
- UserWorkspacePB Function(UserWorkspacePB workspace) updater,
- ) {
- final workspaces = [...state.workspaces];
- final index = workspaces.indexWhere((e) => e.workspaceId == workspaceId);
- if (index != -1) {
- workspaces[index] = updater(workspaces[index]);
- }
- return workspaces;
- }
-
- Future<(UserWorkspacePB?, List<UserWorkspacePB>, bool)> _fetchWorkspaces({
- String? initialWorkspaceId,
- }) async {
- try {
- final currentWorkspaceResult =
- await UserBackendService.getCurrentWorkspace();
- final currentWorkspace = currentWorkspaceResult.fold(
- (s) => s,
- (e) => null,
- );
- final currentWorkspaceId = initialWorkspaceId ?? currentWorkspace?.id;
- final workspaces = await _userService.getWorkspaces().getOrThrow();
-
- if (workspaces.isEmpty && currentWorkspace != null) {
- workspaces.add(convertWorkspacePBToUserWorkspace(currentWorkspace));
- }
-
- final currentWorkspaceInList = _findWorkspaceById(
- currentWorkspaceId ?? '',
- workspaces,
- ) ??
- workspaces.firstOrNull;
-
- final sortedWorkspaces = _sortWorkspaces(workspaces);
-
- Log.info(
- 'fetch workspaces: current workspace: ${currentWorkspaceInList?.workspaceId}, sorted workspaces: ${sortedWorkspaces.map((e) => '${e.name}: ${e.workspaceId}')}',
- );
-
- return (
- currentWorkspaceInList,
- sortedWorkspaces,
- currentWorkspaceInList?.workspaceId != currentWorkspaceId,
- );
- } catch (e) {
- Log.error('fetch workspace error: $e');
- return (state.currentWorkspace, state.workspaces, false);
- }
- }
-
- UserWorkspacePB convertWorkspacePBToUserWorkspace(WorkspacePB workspace) {
- return UserWorkspacePB.create()
- ..workspaceId = workspace.id
- ..name = workspace.name
- ..createdAtTimestamp = workspace.createTime;
- }
-}
-
-@freezed
-class UserWorkspaceEvent with _$UserWorkspaceEvent {
- const factory UserWorkspaceEvent.initial() = Initial;
- const factory UserWorkspaceEvent.fetchWorkspaces({
- String? initialWorkspaceId,
- }) = FetchWorkspaces;
- const factory UserWorkspaceEvent.createWorkspace(
- String name,
- WorkspaceTypePB workspaceType,
- ) = CreateWorkspace;
- const factory UserWorkspaceEvent.deleteWorkspace(String workspaceId) =
- DeleteWorkspace;
- const factory UserWorkspaceEvent.openWorkspace(
- String workspaceId,
- WorkspaceTypePB workspaceType,
- ) = OpenWorkspace;
- const factory UserWorkspaceEvent.renameWorkspace(
- String workspaceId,
- String name,
- ) = _RenameWorkspace;
- const factory UserWorkspaceEvent.updateWorkspaceIcon(
- String workspaceId,
- String icon,
- ) = _UpdateWorkspaceIcon;
- const factory UserWorkspaceEvent.leaveWorkspace(String workspaceId) =
- LeaveWorkspace;
- const factory UserWorkspaceEvent.updateWorkspaces(
- RepeatedUserWorkspacePB workspaces,
- ) = UpdateWorkspaces;
- const factory UserWorkspaceEvent.updateCurrentWorkspace(
- UserWorkspacePB workspace,
- ) = UpdateCurrentWorkspace;
- const factory UserWorkspaceEvent.updateUserProfile(
- UserProfilePB userProfile,
- ) = UpdateUserProfile;
- const factory UserWorkspaceEvent.fetchWorkspaceSubscriptionInfo(
- String workspaceId,
- ) = FetchWorkspaceSubscriptionInfo;
- const factory UserWorkspaceEvent.updateWorkspaceSubscriptionInfo(
- WorkspaceSubscriptionInfoPB workspaceSubscriptionInfo,
- ) = UpdateWorkspaceSubscriptionInfo;
-}
-
-enum UserWorkspaceActionType {
- none,
- create,
- delete,
- open,
- rename,
- updateIcon,
- fetchWorkspaces,
- leave;
-}
-
-class UserWorkspaceActionResult {
- const UserWorkspaceActionResult({
- required this.actionType,
- required this.isLoading,
- required this.result,
- });
-
- final UserWorkspaceActionType actionType;
- final bool isLoading;
- final FlowyResult<void, FlowyError>? result;
-
- @override
- String toString() {
- return 'UserWorkspaceActionResult(actionType: $actionType, isLoading: $isLoading, result: $result)';
- }
-}
-
-@freezed
-class UserWorkspaceState with _$UserWorkspaceState {
- const UserWorkspaceState._();
-
- const factory UserWorkspaceState({
- @Default(null) UserWorkspacePB? currentWorkspace,
- @Default([]) List<UserWorkspacePB> workspaces,
- @Default(null) UserWorkspaceActionResult? actionResult,
- @Default(false) bool isCollabWorkspaceOn,
- required UserProfilePB userProfile,
- @Default(null) WorkspaceSubscriptionInfoPB? workspaceSubscriptionInfo,
- }) = _UserWorkspaceState;
-
- factory UserWorkspaceState.initial(UserProfilePB userProfile) =>
- UserWorkspaceState(
- userProfile: userProfile,
- );
-
- @override
- int get hashCode => runtimeType.hashCode;
-
- final DeepCollectionEquality _deepCollectionEquality =
- const DeepCollectionEquality();
-
- @override
- bool operator ==(Object other) {
- if (identical(this, other)) return true;
-
- return other is UserWorkspaceState &&
- other.currentWorkspace == currentWorkspace &&
- _deepCollectionEquality.equals(other.workspaces, workspaces) &&
- identical(other.actionResult, actionResult) &&
- other.userProfile == userProfile;
- }
-}
+export 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
diff --git a/frontend/appflowy_flutter/lib/workspace/application/view/view_lock_status_bloc.dart b/frontend/appflowy_flutter/lib/workspace/application/view/view_lock_status_bloc.dart
deleted file mode 100644
index 251131d849..0000000000
--- a/frontend/appflowy_flutter/lib/workspace/application/view/view_lock_status_bloc.dart
+++ /dev/null
@@ -1,123 +0,0 @@
-import 'dart:async';
-
-import 'package:appflowy/workspace/application/view/view_listener.dart';
-import 'package:appflowy/workspace/application/view/view_service.dart';
-import 'package:appflowy_backend/protobuf/flowy-folder/protobuf.dart';
-import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
-import 'package:flutter_bloc/flutter_bloc.dart';
-import 'package:freezed_annotation/freezed_annotation.dart';
-import 'package:protobuf/protobuf.dart';
-
-part 'view_lock_status_bloc.freezed.dart';
-
-class ViewLockStatusBloc
- extends Bloc<ViewLockStatusEvent, ViewLockStatusState> {
- ViewLockStatusBloc({
- required this.view,
- }) : viewBackendSvc = ViewBackendService(),
- listener = ViewListener(viewId: view.id),
- super(ViewLockStatusState.init(view)) {
- on<ViewLockStatusEvent>(
- (event, emit) async {
- await event.when(
- initial: () async {
- listener.start(
- onViewUpdated: (view) async {
- add(ViewLockStatusEvent.updateLockStatus(view.isLocked));
- },
- );
-
- final result = await ViewBackendService.getView(view.id);
- final latestView = result.fold(
- (view) => view,
- (_) => view,
- );
- emit(
- state.copyWith(
- view: latestView,
- isLocked: latestView.isLocked,
- isLoadingLockStatus: false,
- ),
- );
- },
- lock: () async {
- final result = await ViewBackendService.lockView(view.id);
- final isLocked = result.fold(
- (_) => true,
- (_) => false,
- );
- add(
- ViewLockStatusEvent.updateLockStatus(
- isLocked,
- ),
- );
- },
- unlock: () async {
- final result = await ViewBackendService.unlockView(view.id);
- final isLocked = result.fold(
- (_) => false,
- (_) => true,
- );
- add(
- ViewLockStatusEvent.updateLockStatus(
- isLocked,
- lockCounter: state.lockCounter + 1,
- ),
- );
- },
- updateLockStatus: (isLocked, lockCounter) {
- state.view.freeze();
- final updatedView = state.view.rebuild(
- (update) => update.isLocked = isLocked,
- );
- emit(
- state.copyWith(
- view: updatedView,
- isLocked: isLocked,
- lockCounter: lockCounter ?? state.lockCounter,
- ),
- );
- },
- );
- },
- );
- }
-
- final ViewPB view;
- final ViewBackendService viewBackendSvc;
- final ViewListener listener;
-
- @override
- Future<void> close() async {
- await listener.stop();
-
- return super.close();
- }
-}
-
-@freezed
-class ViewLockStatusEvent with _$ViewLockStatusEvent {
- const factory ViewLockStatusEvent.initial() = Initial;
- const factory ViewLockStatusEvent.lock() = Lock;
- const factory ViewLockStatusEvent.unlock() = Unlock;
- const factory ViewLockStatusEvent.updateLockStatus(
- bool isLocked, {
- int? lockCounter,
- }) = UpdateLockStatus;
-}
-
-@freezed
-class ViewLockStatusState with _$ViewLockStatusState {
- const factory ViewLockStatusState({
- required ViewPB view,
- required bool isLocked,
- required int lockCounter,
- @Default(true) bool isLoadingLockStatus,
- }) = _ViewLockStatusState;
-
- factory ViewLockStatusState.init(ViewPB view) => ViewLockStatusState(
- view: view,
- isLocked: false,
- lockCounter: 0,
- );
-}
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/command_palette.dart b/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/command_palette.dart
index efe2cb4261..778e6c26a6 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/command_palette.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/command_palette.dart
@@ -1,3 +1,4 @@
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/startup/plugin/plugin.dart';
@@ -5,7 +6,6 @@ import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/workspace/application/command_palette/command_palette_bloc.dart';
import 'package:appflowy/workspace/application/sidebar/space/space_bloc.dart';
import 'package:appflowy/workspace/application/tabs/tabs_bloc.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy/workspace/presentation/command_palette/widgets/recent_views_list.dart';
import 'package:appflowy/workspace/presentation/command_palette/widgets/search_field.dart';
import 'package:appflowy/workspace/presentation/command_palette/widgets/search_results_list.dart';
@@ -252,8 +252,9 @@ class CommandPaletteModal extends StatelessWidget {
// Show a loading indicator when searching
Expanded(
child: Center(
- child:
- Center(child: CircularProgressIndicator.adaptive()),
+ child: Center(
+ child: CircularProgressIndicator.adaptive(),
+ ),
),
),
],
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/page_preview.dart b/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/page_preview.dart
index 8ee3997afa..60f044af35 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/page_preview.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/page_preview.dart
@@ -1,5 +1,6 @@
import 'dart:io';
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/application/page_style/document_page_style_bloc.dart';
@@ -13,7 +14,6 @@ import 'package:appflowy/util/int64_extension.dart';
import 'package:appflowy/util/theme_extension.dart';
import 'package:appflowy/workspace/application/settings/appearance/appearance_cubit.dart';
import 'package:appflowy/workspace/application/settings/date_time/date_format_ext.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy/workspace/application/view/view_ext.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/recent_views_list.dart b/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/recent_views_list.dart
index 3d95c5d1ac..7d2d37184e 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/recent_views_list.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/recent_views_list.dart
@@ -1,6 +1,6 @@
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/workspace/application/recent/recent_views_bloc.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy/workspace/presentation/command_palette/navigation_bloc_extension.dart';
import 'package:appflowy/workspace/presentation/command_palette/widgets/search_icon.dart';
import 'package:appflowy/workspace/presentation/command_palette/widgets/search_recent_view_cell.dart';
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/search_field.dart b/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/search_field.dart
index 8e6d3e3f2c..02b5b900a6 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/search_field.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/search_field.dart
@@ -1,14 +1,13 @@
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
-import 'package:appflowy_ui/appflowy_ui.dart';
-import 'package:flutter/material.dart';
-import 'package:flutter/services.dart';
-
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/workspace/application/command_palette/command_palette_bloc.dart';
+import 'package:appflowy_ui/appflowy_ui.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/style_widget/text_field.dart';
import 'package:flowy_infra_ui/widget/flowy_tooltip.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class SearchField extends StatefulWidget {
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/search_results_list.dart b/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/search_results_list.dart
index 02b04b24af..1305ca5eec 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/search_results_list.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/command_palette/widgets/search_results_list.dart
@@ -1,18 +1,18 @@
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
+import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/workspace/application/command_palette/command_palette_bloc.dart';
import 'package:appflowy/workspace/application/command_palette/search_result_list_bloc.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy/workspace/presentation/command_palette/navigation_bloc_extension.dart';
import 'package:appflowy/workspace/presentation/command_palette/widgets/search_ask_ai_entrance.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
+import 'package:appflowy_backend/protobuf/flowy-search/result.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-user/workspace.pbenum.dart';
import 'package:appflowy_ui/appflowy_ui.dart';
-import 'package:flutter/material.dart';
-
-import 'package:appflowy/generated/locale_keys.g.dart';
-import 'package:appflowy_backend/protobuf/flowy-search/result.pb.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
+import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
+
import 'page_preview.dart';
import 'search_result_cell.dart';
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/desktop_home_screen.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/desktop_home_screen.dart
index e658baa544..ea96ea1db7 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/desktop_home_screen.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/desktop_home_screen.dart
@@ -1,3 +1,5 @@
+import 'package:appflowy/features/workspace/data/repositories/rust_workspace_repository_impl.dart';
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/plugins/blank/blank.dart';
import 'package:appflowy/startup/plugin/plugin.dart';
import 'package:appflowy/startup/startup.dart';
@@ -127,8 +129,12 @@ class DesktopHomeScreen extends StatelessWidget {
child: BlocBuilder<HomeSettingBloc, HomeSettingState>(
buildWhen: (previous, current) => previous != current,
builder: (context, state) => BlocProvider(
- create: (_) => UserWorkspaceBloc(userProfile: userProfile)
- ..add(const UserWorkspaceEvent.initial()),
+ create: (_) => UserWorkspaceBloc(
+ userProfile: userProfile,
+ repository: RustWorkspaceRepositoryImpl(
+ userId: userProfile.id,
+ ),
+ )..add(UserWorkspaceEvent.initialize()),
child: BlocListener<UserWorkspaceBloc, UserWorkspaceState>(
listenWhen: (previous, current) =>
previous.currentWorkspace != current.currentWorkspace,
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/favorites/favorite_folder.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/favorites/favorite_folder.dart
index ca0773bf72..e4516a14a6 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/favorites/favorite_folder.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/favorites/favorite_folder.dart
@@ -10,6 +10,7 @@ import 'package:appflowy/workspace/presentation/home/menu/sidebar/favorites/favo
import 'package:appflowy/workspace/presentation/home/menu/sidebar/favorites/favorite_pin_action.dart';
import 'package:appflowy/workspace/presentation/home/menu/view/view_item.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
+import 'package:appflowy_ui/appflowy_ui.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart';
@@ -163,21 +164,21 @@ class FavoriteHeader extends StatelessWidget {
@override
Widget build(BuildContext context) {
- return SizedBox(
- height: HomeSizes.newPageSectionHeight,
- child: FlowyButton(
- onTap: onPressed,
- margin: const EdgeInsets.symmetric(horizontal: 4.0, vertical: 3.0),
- leftIcon: const FlowySvg(
- FlowySvgs.favorite_header_icon_m,
- blendMode: null,
- ),
- leftIconSize: const Size.square(24.0),
- iconPadding: 8.0,
- text: FlowyText.regular(
- LocaleKeys.sideBar_favorites.tr(),
- lineHeight: 1.15,
- ),
+ final theme = AppFlowyTheme.of(context);
+ return AFGhostIconTextButton.primary(
+ text: LocaleKeys.sideBar_favorites.tr(),
+ mainAxisAlignment: MainAxisAlignment.start,
+ size: AFButtonSize.l,
+ onTap: onPressed,
+ // todo: ask the designer to provide the token.
+ padding: EdgeInsets.symmetric(
+ horizontal: 4,
+ vertical: 6,
+ ),
+ borderRadius: theme.borderRadius.s,
+ iconBuilder: (context, isHover, disabled) => const FlowySvg(
+ FlowySvgs.favorite_header_m,
+ blendMode: null,
),
);
}
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/folder/_section_folder.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/folder/_section_folder.dart
index a8717e28bc..f28f12c015 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/folder/_section_folder.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/folder/_section_folder.dart
@@ -1,7 +1,7 @@
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/workspace/application/menu/sidebar_sections_bloc.dart';
import 'package:appflowy/workspace/application/sidebar/folder/folder_bloc.dart';
import 'package:appflowy/workspace/application/tabs/tabs_bloc.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy/workspace/presentation/home/home_sizes.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/folder/_folder_header.dart';
import 'package:appflowy/workspace/presentation/home/menu/view/view_item.dart';
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/footer/sidebar_toast.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/footer/sidebar_toast.dart
index bce00d9792..b870d0dc89 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/footer/sidebar_toast.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/footer/sidebar_toast.dart
@@ -1,12 +1,12 @@
import 'dart:io';
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/shared/af_role_pb_extension.dart';
import 'package:appflowy/workspace/application/settings/plan/workspace_subscription_ext.dart';
import 'package:appflowy/workspace/application/settings/settings_dialog_bloc.dart';
import 'package:appflowy/workspace/application/sidebar/billing/sidebar_plan_bloc.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/shared/sidebar_setting.dart';
import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';
import 'package:appflowy_backend/log.dart';
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/header/sidebar_user.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/header/sidebar_user.dart
index 0b70dd88c7..21d83a9cf9 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/header/sidebar_user.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/header/sidebar_user.dart
@@ -1,6 +1,6 @@
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/workspace/application/menu/menu_user_bloc.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/shared/sidebar_setting.dart';
import 'package:appflowy/workspace/presentation/notifications/widgets/notification_button.dart';
import 'package:appflowy/workspace/presentation/widgets/user_avatar.dart';
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/shared/sidebar_folder.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/shared/sidebar_folder.dart
index c27f259b68..3ea3ebfaf6 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/shared/sidebar_folder.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/shared/sidebar_folder.dart
@@ -1,9 +1,9 @@
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/workspace/application/favorite/favorite_bloc.dart';
import 'package:appflowy/workspace/application/menu/sidebar_sections_bloc.dart';
import 'package:appflowy/workspace/application/sidebar/folder/folder_bloc.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy/workspace/presentation/home/menu/menu_shared_state.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/favorites/favorite_folder.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/folder/_section_folder.dart';
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/shared/sidebar_new_page_button.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/shared/sidebar_new_page_button.dart
index d35c4cd148..253bfb44f9 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/shared/sidebar_new_page_button.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/shared/sidebar_new_page_button.dart
@@ -1,8 +1,8 @@
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/workspace/application/menu/sidebar_sections_bloc.dart';
import 'package:appflowy/workspace/application/sidebar/space/space_bloc.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy/workspace/presentation/home/home_sizes.dart';
import 'package:appflowy/workspace/presentation/home/hotkeys.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/shared/sidebar_setting.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/shared/sidebar_setting.dart
index 8986cc63fd..42d47676ed 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/shared/sidebar_setting.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/shared/sidebar_setting.dart
@@ -1,10 +1,10 @@
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/application/document_appearance_cubit.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/user/application/password/password_bloc.dart';
import 'package:appflowy/workspace/application/settings/settings_dialog_bloc.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy/workspace/presentation/home/af_focus_manager.dart';
import 'package:appflowy/workspace/presentation/home/hotkeys.dart';
import 'package:appflowy/workspace/presentation/settings/settings_dialog.dart';
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/sidebar.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/sidebar.dart
index 65c6122ab0..c55a1852e3 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/sidebar.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/sidebar.dart
@@ -1,6 +1,7 @@
import 'dart:async';
import 'dart:io';
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/search/view_ancestor_cache.dart';
@@ -21,7 +22,6 @@ import 'package:appflowy/workspace/application/recent/cached_recent_service.dart
import 'package:appflowy/workspace/application/sidebar/billing/sidebar_plan_bloc.dart';
import 'package:appflowy/workspace/application/sidebar/space/space_bloc.dart';
import 'package:appflowy/workspace/application/tabs/tabs_bloc.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy/workspace/application/view/view_ext.dart';
import 'package:appflowy/workspace/application/view/view_service.dart';
import 'package:appflowy/workspace/presentation/command_palette/command_palette.dart';
@@ -183,9 +183,9 @@ class HomeSideBar extends StatelessWidget {
listener: (context, state) {
final actionType = state.actionResult?.actionType;
- if (actionType == UserWorkspaceActionType.create ||
- actionType == UserWorkspaceActionType.delete ||
- actionType == UserWorkspaceActionType.open) {
+ if (actionType == WorkspaceActionType.create ||
+ actionType == WorkspaceActionType.delete ||
+ actionType == WorkspaceActionType.open) {
if (context.read<SpaceBloc>().state.spaces.isEmpty) {
context.read<SidebarSectionsBloc>().add(
SidebarSectionsEvent.reload(
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/space/sidebar_space.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/space/sidebar_space.dart
index 23d8ba7866..1614b992bf 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/space/sidebar_space.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/space/sidebar_space.dart
@@ -1,10 +1,10 @@
import 'package:appflowy/features/shared_section/presentation/shared_section.dart';
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/shared/feature_flags.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/workspace/application/favorite/favorite_bloc.dart';
import 'package:appflowy/workspace/application/sidebar/space/space_bloc.dart';
import 'package:appflowy/workspace/application/tabs/tabs_bloc.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy/workspace/presentation/home/hotkeys.dart';
import 'package:appflowy/workspace/presentation/home/menu/menu_shared_state.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/favorites/favorite_folder.dart';
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/space/space_more_popup.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/space/space_more_popup.dart
index 4b13062c3e..4bc63bfba5 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/space/space_more_popup.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/space/space_more_popup.dart
@@ -1,10 +1,10 @@
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/shared/af_role_pb_extension.dart';
import 'package:appflowy/shared/icon_emoji_picker/flowy_icon_emoji_picker.dart';
import 'package:appflowy/shared/icon_emoji_picker/tab.dart';
import 'package:appflowy/workspace/application/sidebar/space/space_bloc.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/space/space_action_type.dart';
import 'package:appflowy/workspace/presentation/widgets/pop_up_action.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/workspace/_sidebar_workspace_actions.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/workspace/_sidebar_workspace_actions.dart
index 44f558fc17..3bb5fd388a 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/workspace/_sidebar_workspace_actions.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/workspace/_sidebar_workspace_actions.dart
@@ -1,7 +1,7 @@
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/shared/af_role_pb_extension.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy/workspace/presentation/settings/widgets/members/workspace_member_bloc.dart';
import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';
import 'package:appflowy/workspace/presentation/widgets/pop_up_action.dart';
@@ -148,7 +148,9 @@ class _WorkspaceMoreActionWrapper extends CustomActionCell {
description: LocaleKeys.workspace_deleteWorkspaceHintText.tr(),
onConfirm: () {
workspaceBloc.add(
- UserWorkspaceEvent.deleteWorkspace(workspace.workspaceId),
+ UserWorkspaceEvent.deleteWorkspace(
+ workspaceId: workspace.workspaceId,
+ ),
);
},
);
@@ -161,8 +163,8 @@ class _WorkspaceMoreActionWrapper extends CustomActionCell {
onConfirm: (name, context) async {
workspaceBloc.add(
UserWorkspaceEvent.renameWorkspace(
- workspace.workspaceId,
- name,
+ workspaceId: workspace.workspaceId,
+ name: name,
),
);
},
@@ -176,7 +178,9 @@ class _WorkspaceMoreActionWrapper extends CustomActionCell {
confirmLabel: LocaleKeys.button_yes.tr(),
onConfirm: () {
workspaceBloc.add(
- UserWorkspaceEvent.leaveWorkspace(workspace.workspaceId),
+ UserWorkspaceEvent.leaveWorkspace(
+ workspaceId: workspace.workspaceId,
+ ),
);
},
);
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/workspace/_sidebar_workspace_menu.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/workspace/_sidebar_workspace_menu.dart
index 0a21e7452a..f4fa23138c 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/workspace/_sidebar_workspace_menu.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/workspace/_sidebar_workspace_menu.dart
@@ -1,10 +1,11 @@
import 'package:appflowy/core/helpers/url_launcher.dart';
+import 'package:appflowy/features/share_tab/presentation/widgets/guest_tag.dart';
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/user/application/auth/auth_service.dart';
import 'package:appflowy/workspace/application/tabs/tabs_bloc.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/workspace/_sidebar_workspace_actions.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/workspace/_sidebar_workspace_icon.dart';
import 'package:appflowy/workspace/presentation/settings/widgets/members/workspace_member_bloc.dart';
@@ -208,8 +209,8 @@ class _WorkspaceMenuItemState extends State<WorkspaceMenuItem> {
isEditable: true,
onSelected: (result) => context.read<UserWorkspaceBloc>().add(
UserWorkspaceEvent.updateWorkspaceIcon(
- widget.workspace.workspaceId,
- result.emoji,
+ workspaceId: widget.workspace.workspaceId,
+ icon: result.emoji,
),
),
),
@@ -272,29 +273,42 @@ class _WorkspaceInfo extends StatelessWidget {
leftIconSize: const Size.square(32),
leftIcon: const SizedBox.square(dimension: 32),
rightIcon: const HSpace(32.0),
- text: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- mainAxisAlignment: MainAxisAlignment.center,
+ text: Row(
children: [
- // workspace name
- FlowyText.medium(
- workspace.name,
- fontSize: 14.0,
- figmaLineHeight: 17.0,
- overflow: TextOverflow.ellipsis,
- withTooltip: true,
- ),
- // workspace members count
- FlowyText.regular(
- memberCount == 0
- ? ''
- : LocaleKeys.settings_appearance_members_membersCount.plural(
- memberCount,
+ Flexible(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ // workspace name
+ FlowyText.medium(
+ workspace.name,
+ fontSize: 14.0,
+ figmaLineHeight: 17.0,
+ overflow: TextOverflow.ellipsis,
+ withTooltip: true,
+ ),
+ if (workspace.role != AFRolePB.Guest) ...[
+ // workspace members count
+ FlowyText.regular(
+ memberCount == 0
+ ? ''
+ : LocaleKeys.settings_appearance_members_membersCount
+ .plural(
+ memberCount,
+ ),
+ fontSize: 10.0,
+ figmaLineHeight: 12.0,
+ color: Theme.of(context).hintColor,
),
- fontSize: 10.0,
- figmaLineHeight: 12.0,
- color: Theme.of(context).hintColor,
+ ],
+ ],
+ ),
),
+ if (workspace.role == AFRolePB.Guest) ...[
+ const HSpace(6.0),
+ GuestTag(),
+ ],
],
),
);
@@ -309,8 +323,8 @@ class _WorkspaceInfo extends StatelessWidget {
context.read<UserWorkspaceBloc>().add(
UserWorkspaceEvent.openWorkspace(
- workspace.workspaceId,
- workspace.workspaceType,
+ workspaceId: workspace.workspaceId,
+ workspaceType: workspace.workspaceType,
),
);
@@ -389,8 +403,8 @@ class _CreateWorkspaceButton extends StatelessWidget {
onConfirm: (name) {
workspaceBloc.add(
UserWorkspaceEvent.createWorkspace(
- name,
- WorkspaceTypePB.ServerW,
+ name: name,
+ workspaceType: WorkspaceTypePB.ServerW,
),
);
},
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/workspace/sidebar_workspace.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/workspace/sidebar_workspace.dart
index 27a76525a5..ef9bbe72c8 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/workspace/sidebar_workspace.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/workspace/sidebar_workspace.dart
@@ -1,8 +1,8 @@
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/shared/loading.dart';
import 'package:appflowy/workspace/application/home/home_setting_bloc.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/shared/sidebar_setting.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/workspace/_sidebar_workspace_icon.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/workspace/_sidebar_workspace_menu.dart';
@@ -136,7 +136,7 @@ class _SidebarWorkspaceState extends State<SidebarWorkspace> {
});
// show a confirmation dialog if the action is create and the result is LimitExceeded failure
- if (actionType == UserWorkspaceActionType.create &&
+ if (actionType == WorkspaceActionType.create &&
result.isFailure &&
result.getFailure().code == ErrorCode.WorkspaceLimitExceeded) {
showDialog(
@@ -150,41 +150,42 @@ class _SidebarWorkspaceState extends State<SidebarWorkspace> {
final String? message;
switch (actionType) {
- case UserWorkspaceActionType.create:
+ case WorkspaceActionType.create:
message = result.fold(
(s) => LocaleKeys.workspace_createSuccess.tr(),
(e) => '${LocaleKeys.workspace_createFailed.tr()}: ${e.msg}',
);
break;
- case UserWorkspaceActionType.delete:
+ case WorkspaceActionType.delete:
message = result.fold(
(s) => LocaleKeys.workspace_deleteSuccess.tr(),
(e) => '${LocaleKeys.workspace_deleteFailed.tr()}: ${e.msg}',
);
break;
- case UserWorkspaceActionType.open:
+ case WorkspaceActionType.open:
message = result.fold(
(s) => LocaleKeys.workspace_openSuccess.tr(),
(e) => '${LocaleKeys.workspace_openFailed.tr()}: ${e.msg}',
);
break;
- case UserWorkspaceActionType.updateIcon:
+ case WorkspaceActionType.updateIcon:
message = result.fold(
(s) => LocaleKeys.workspace_updateIconSuccess.tr(),
(e) => '${LocaleKeys.workspace_updateIconFailed.tr()}: ${e.msg}',
);
break;
- case UserWorkspaceActionType.rename:
+ case WorkspaceActionType.rename:
message = result.fold(
(s) => LocaleKeys.workspace_renameSuccess.tr(),
(e) => '${LocaleKeys.workspace_renameFailed.tr()}: ${e.msg}',
);
break;
- case UserWorkspaceActionType.fetchWorkspaces:
- case UserWorkspaceActionType.none:
- case UserWorkspaceActionType.leave:
+ case WorkspaceActionType.fetchWorkspaces:
+ case WorkspaceActionType.none:
+ case WorkspaceActionType.leave:
+ case WorkspaceActionType.fetchSubscriptionInfo:
message = null;
break;
}
@@ -264,8 +265,8 @@ class _SidebarWorkspaceState extends State<SidebarWorkspace> {
context.read<UserWorkspaceBloc>().add(
UserWorkspaceEvent.openWorkspace(
- workspaceId,
- openWorkspace.workspaceType,
+ workspaceId: workspaceId,
+ workspaceType: openWorkspace.workspaceType,
),
);
@@ -309,7 +310,7 @@ class _SidebarSwitchWorkspaceButtonState
onOpen: () {
context
.read<UserWorkspaceBloc>()
- .add(const UserWorkspaceEvent.fetchWorkspaces());
+ .add(UserWorkspaceEvent.fetchWorkspaces());
},
popupBuilder: (_) {
return BlocProvider<UserWorkspaceBloc>.value(
@@ -357,7 +358,7 @@ class _SideBarSwitchWorkspaceButtonChild extends StatelessWidget {
child: GestureDetector(
onTap: () {
context.read<UserWorkspaceBloc>().add(
- const UserWorkspaceEvent.fetchWorkspaces(),
+ UserWorkspaceEvent.fetchWorkspaces(),
);
popoverController.show();
},
@@ -379,8 +380,8 @@ class _SideBarSwitchWorkspaceButtonChild extends StatelessWidget {
figmaLineHeight: 18.0,
onSelected: (result) => context.read<UserWorkspaceBloc>().add(
UserWorkspaceEvent.updateWorkspaceIcon(
- currentWorkspace.workspaceId,
- result.emoji,
+ workspaceId: currentWorkspace.workspaceId,
+ icon: result.emoji,
),
),
),
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/view/view_action_type.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/view/view_action_type.dart
index d4f91b67d9..253c22e282 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/view/view_action_type.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/view/view_action_type.dart
@@ -17,7 +17,8 @@ enum ViewMoreActionType {
divider,
lastModified,
created,
- lockPage;
+ lockPage,
+ leaveSharedPage;
static const disableInLockedView = [
delete,
@@ -52,6 +53,8 @@ extension ViewMoreActionTypeExtension on ViewMoreActionType {
return LocaleKeys.disclosureAction_collapseAllPages.tr();
case ViewMoreActionType.lockPage:
return LocaleKeys.disclosureAction_lockPage.tr();
+ case ViewMoreActionType.leaveSharedPage:
+ return 'Leave';
case ViewMoreActionType.divider:
case ViewMoreActionType.lastModified:
case ViewMoreActionType.created:
@@ -81,6 +84,8 @@ extension ViewMoreActionTypeExtension on ViewMoreActionType {
return FlowySvgs.collapse_all_page_s;
case ViewMoreActionType.lockPage:
return FlowySvgs.lock_page_s;
+ case ViewMoreActionType.leaveSharedPage:
+ return FlowySvgs.leave_workspace_s;
case ViewMoreActionType.divider:
case ViewMoreActionType.lastModified:
case ViewMoreActionType.copyLink:
@@ -105,6 +110,7 @@ extension ViewMoreActionTypeExtension on ViewMoreActionType {
case ViewMoreActionType.lastModified:
case ViewMoreActionType.created:
case ViewMoreActionType.lockPage:
+ case ViewMoreActionType.leaveSharedPage:
return const SizedBox.shrink();
}
}
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/settings_workspace_view.dart b/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/settings_workspace_view.dart
index 58efb1ae59..5793f8f7ad 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/settings_workspace_view.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/settings_workspace_view.dart
@@ -1,5 +1,6 @@
import 'dart:async';
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/application/document_appearance_cubit.dart';
@@ -13,7 +14,6 @@ import 'package:appflowy/workspace/application/settings/appearance/base_appearan
import 'package:appflowy/workspace/application/settings/date_time/date_format_ext.dart';
import 'package:appflowy/workspace/application/settings/date_time/time_format_ext.dart';
import 'package:appflowy/workspace/application/settings/workspace/workspace_settings_bloc.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/space/shared_widget.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/workspace/_sidebar_workspace_icon.dart';
import 'package:appflowy/workspace/presentation/home/toast.dart';
@@ -67,7 +67,7 @@ class SettingsWorkspaceView extends StatelessWidget {
if (state.deleteWorkspace) {
context.read<UserWorkspaceBloc>().add(
UserWorkspaceEvent.deleteWorkspace(
- state.workspace!.workspaceId,
+ workspaceId: state.workspace!.workspaceId,
),
);
Navigator.of(context).pop();
@@ -75,7 +75,7 @@ class SettingsWorkspaceView extends StatelessWidget {
if (state.leaveWorkspace) {
context.read<UserWorkspaceBloc>().add(
UserWorkspaceEvent.leaveWorkspace(
- state.workspace!.workspaceId,
+ workspaceId: state.workspace!.workspaceId,
),
);
Navigator.of(context).pop();
@@ -347,7 +347,10 @@ class LanguageDropdown extends StatelessWidget {
}
class _WorkspaceIconSetting extends StatelessWidget {
- const _WorkspaceIconSetting({required this.enableEdit, this.workspace});
+ const _WorkspaceIconSetting({
+ required this.enableEdit,
+ this.workspace,
+ });
final bool enableEdit;
final UserWorkspacePB? workspace;
@@ -362,7 +365,7 @@ class _WorkspaceIconSetting extends StatelessWidget {
);
}
- return WorkspaceIcon(
+ Widget child = WorkspaceIcon(
workspaceIcon: workspace!.icon,
workspaceName: workspace!.name,
iconSize: 64.0,
@@ -375,6 +378,14 @@ class _WorkspaceIconSetting extends StatelessWidget {
.read<WorkspaceSettingsBloc>()
.add(WorkspaceSettingsEvent.updateWorkspaceIcon(r.emoji)),
);
+
+ if (!enableEdit) {
+ child = IgnorePointer(
+ child: child,
+ );
+ }
+
+ return child;
}
}
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/sites/domain/domain_item.dart b/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/sites/domain/domain_item.dart
index 0641782d78..91f68383d7 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/sites/domain/domain_item.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/sites/domain/domain_item.dart
@@ -1,10 +1,10 @@
import 'package:appflowy/core/helpers/url_launcher.dart';
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/shared/share/constants.dart';
import 'package:appflowy/shared/af_role_pb_extension.dart';
import 'package:appflowy/shared/colors.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy/workspace/presentation/settings/pages/sites/constants.dart';
import 'package:appflowy/workspace/presentation/settings/pages/sites/domain/domain_more_action.dart';
import 'package:appflowy/workspace/presentation/settings/pages/sites/domain/home_page_menu.dart';
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/sites/domain/domain_more_action.dart b/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/sites/domain/domain_more_action.dart
index 9c506b22ff..253d138acd 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/sites/domain/domain_more_action.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/sites/domain/domain_more_action.dart
@@ -1,7 +1,7 @@
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/shared/af_role_pb_extension.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy/workspace/presentation/settings/pages/sites/constants.dart';
import 'package:appflowy/workspace/presentation/settings/pages/sites/domain/domain_settings_dialog.dart';
import 'package:appflowy/workspace/presentation/settings/pages/sites/settings_sites_bloc.dart';
@@ -29,7 +29,7 @@ class _DomainMoreActionState extends State<DomainMoreAction> {
super.initState();
// update the current workspace to ensure the owner check is correct
- context.read<UserWorkspaceBloc>().add(const UserWorkspaceEvent.initial());
+ context.read<UserWorkspaceBloc>().add(UserWorkspaceEvent.initialize());
}
@override
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/sites/settings_sites_view.dart b/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/sites/settings_sites_view.dart
index f3845b0896..fc9fe482c9 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/sites/settings_sites_view.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/sites/settings_sites_view.dart
@@ -1,5 +1,6 @@
+import 'package:appflowy/features/workspace/data/repositories/rust_workspace_repository_impl.dart';
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy/workspace/presentation/settings/pages/sites/constants.dart';
import 'package:appflowy/workspace/presentation/settings/pages/sites/domain/domain_header.dart';
import 'package:appflowy/workspace/presentation/settings/pages/sites/domain/domain_item.dart';
@@ -37,8 +38,12 @@ class SettingsSitesPage extends StatelessWidget {
)..add(const SettingsSitesEvent.initial()),
),
BlocProvider<UserWorkspaceBloc>(
- create: (context) => UserWorkspaceBloc(userProfile: user)
- ..add(const UserWorkspaceEvent.initial()),
+ create: (context) => UserWorkspaceBloc(
+ userProfile: user,
+ repository: RustWorkspaceRepositoryImpl(
+ userId: user.id,
+ ),
+ )..add(UserWorkspaceEvent.initialize()),
),
],
child: const _SettingsSitesPageView(),
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/settings/settings_dialog.dart b/frontend/appflowy_flutter/lib/workspace/presentation/settings/settings_dialog.dart
index 8c8123b8d0..0cf3d4bf5b 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/settings/settings_dialog.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/settings/settings_dialog.dart
@@ -1,4 +1,5 @@
import 'package:appflowy/env/cloud_env.dart';
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/shared/share/constants.dart';
import 'package:appflowy/shared/appflowy_cache_manager.dart';
@@ -7,7 +8,6 @@ import 'package:appflowy/util/share_log_files.dart';
import 'package:appflowy/workspace/application/settings/appearance/appearance_cubit.dart';
import 'package:appflowy/workspace/application/settings/appflowy_cloud_urls_bloc.dart';
import 'package:appflowy/workspace/application/settings/settings_dialog_bloc.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy/workspace/presentation/settings/pages/setting_ai_view/settings_ai_view.dart';
import 'package:appflowy/workspace/presentation/settings/pages/settings_account_view.dart';
import 'package:appflowy/workspace/presentation/settings/pages/settings_billing_view.dart';
@@ -62,10 +62,12 @@ class SettingsDialog extends StatelessWidget {
Widget build(BuildContext context) {
final width = MediaQuery.of(context).size.width * 0.6;
final theme = AppFlowyTheme.of(context);
+ final currentWorkspaceMemberRole =
+ context.read<UserWorkspaceBloc>().state.currentWorkspace?.role;
return BlocProvider<SettingsDialogBloc>(
create: (context) => SettingsDialogBloc(
user,
- context.read<UserWorkspaceBloc>().state.currentWorkspace?.role,
+ currentWorkspaceMemberRole,
initPage: initPage,
)..add(const SettingsDialogEvent.initial()),
child: BlocBuilder<SettingsDialogBloc, SettingsDialogState>(
@@ -87,6 +89,7 @@ class SettingsDialog extends StatelessWidget {
.add(SettingsDialogEvent.setSelectedPage(index)),
currentPage:
context.read<SettingsDialogBloc>().state.page,
+ currentUserRole: currentWorkspaceMemberRole,
isBillingEnabled: state.isBillingEnabled,
),
),
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/settings_menu.dart b/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/settings_menu.dart
index b159b2ccd8..6176a0fee1 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/settings_menu.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/settings_menu.dart
@@ -17,12 +17,14 @@ class SettingsMenu extends StatelessWidget {
required this.currentPage,
required this.userProfile,
required this.isBillingEnabled,
+ required this.currentUserRole,
});
final Function changeSelectedPage;
final SettingsPage currentPage;
final UserProfilePB userProfile;
final bool isBillingEnabled;
+ final AFRolePB? currentUserRole;
@override
Widget build(BuildContext context) {
@@ -60,7 +62,9 @@ class SettingsMenu extends StatelessWidget {
changeSelectedPage: changeSelectedPage,
),
if (FeatureFlag.membersSettings.isOn &&
- userProfile.workspaceType == WorkspaceTypePB.ServerW)
+ userProfile.workspaceType == WorkspaceTypePB.ServerW &&
+ currentUserRole != null &&
+ currentUserRole != AFRolePB.Guest)
SettingsMenuElement(
page: SettingsPage.member,
selectedPage: currentPage,
@@ -105,7 +109,9 @@ class SettingsMenu extends StatelessWidget {
),
changeSelectedPage: changeSelectedPage,
),
- if (userProfile.workspaceType == WorkspaceTypePB.ServerW)
+ if (userProfile.workspaceType == WorkspaceTypePB.ServerW &&
+ currentUserRole != null &&
+ currentUserRole != AFRolePB.Guest)
SettingsMenuElement(
page: SettingsPage.sites,
selectedPage: currentPage,
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/widgets/more_view_actions/more_view_actions.dart b/frontend/appflowy_flutter/lib/workspace/presentation/widgets/more_view_actions/more_view_actions.dart
index 2d302613ed..ba6fc360cf 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/widgets/more_view_actions/more_view_actions.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/widgets/more_view_actions/more_view_actions.dart
@@ -1,11 +1,12 @@
+import 'package:appflowy/features/page_access_level/logic/page_access_level_bloc.dart';
+import 'package:appflowy/features/share_tab/data/models/share_access_level.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/workspace/application/settings/appearance/appearance_cubit.dart';
import 'package:appflowy/workspace/application/sidebar/space/space_bloc.dart';
-import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
import 'package:appflowy/workspace/application/view/view_bloc.dart';
import 'package:appflowy/workspace/application/view/view_ext.dart';
-import 'package:appflowy/workspace/application/view/view_lock_status_bloc.dart';
import 'package:appflowy/workspace/application/view_info/view_info_bloc.dart';
import 'package:appflowy/workspace/presentation/home/menu/view/view_action_type.dart';
import 'package:appflowy/workspace/presentation/widgets/more_view_actions/widgets/common_view_action.dart';
@@ -79,8 +80,8 @@ class _MoreViewActionsState extends State<MoreViewActions> {
),
),
BlocProvider(
- create: (_) => ViewLockStatusBloc(view: widget.view)
- ..add(ViewLockStatusEvent.initial()),
+ create: (_) => PageAccessLevelBloc(view: widget.view)
+ ..add(PageAccessLevelEvent.initial()),
),
BlocProvider(
create: (context) => SpaceBloc(
@@ -120,17 +121,23 @@ class _MoreViewActionsState extends State<MoreViewActions> {
}
List<Widget> _buildActions(BuildContext context, ViewInfoState state) {
- final view = context.watch<ViewLockStatusBloc>().state.view;
+ final pageAccessLevelBloc = context.watch<PageAccessLevelBloc>();
+ final pageAccessLevelState = pageAccessLevelBloc.state;
+ final view = pageAccessLevelState.view;
final appearanceSettings = context.watch<AppearanceSettingsCubit>().state;
final dateFormat = appearanceSettings.dateFormat;
final timeFormat = appearanceSettings.timeFormat;
- final viewMoreActionTypes = [
- if (widget.view.layout != ViewLayoutPB.Chat) ViewMoreActionType.duplicate,
- ViewMoreActionType.moveTo,
- ViewMoreActionType.delete,
- ViewMoreActionType.divider,
- ];
+ final viewMoreActionTypes = switch (pageAccessLevelState.accessLevel) {
+ ShareAccessLevel.readOnly => [],
+ _ => [
+ if (widget.view.layout != ViewLayoutPB.Chat)
+ ViewMoreActionType.duplicate,
+ ViewMoreActionType.moveTo,
+ ViewMoreActionType.delete,
+ ViewMoreActionType.divider,
+ ],
+ };
final actions = [
...widget.customActions,
@@ -143,7 +150,8 @@ class _MoreViewActionsState extends State<MoreViewActions> {
),
],
if (state.workspaceType == WorkspaceTypePB.ServerW &&
- (widget.view.isDocument || widget.view.isDatabase)) ...[
+ (widget.view.isDocument || widget.view.isDatabase) &&
+ !pageAccessLevelState.isReadOnly) ...[
LockPageAction(
view: view,
),
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/widgets/more_view_actions/widgets/lock_page_action.dart b/frontend/appflowy_flutter/lib/workspace/presentation/widgets/more_view_actions/widgets/lock_page_action.dart
index 6ee7b8566a..77c0439b38 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/widgets/more_view_actions/widgets/lock_page_action.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/widgets/more_view_actions/widgets/lock_page_action.dart
@@ -1,6 +1,6 @@
+import 'package:appflowy/features/page_access_level/logic/page_access_level_bloc.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
-import 'package:appflowy/workspace/application/view/view_lock_status_bloc.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:easy_localization/easy_localization.dart';
@@ -27,11 +27,11 @@ class _LockPageActionState extends State<LockPageAction> {
@override
Widget build(BuildContext context) {
return BlocProvider(
- create: (context) => ViewLockStatusBloc(view: widget.view)
+ create: (context) => PageAccessLevelBloc(view: widget.view)
..add(
- ViewLockStatusEvent.initial(),
+ PageAccessLevelEvent.initial(),
),
- child: BlocBuilder<ViewLockStatusBloc, ViewLockStatusState>(
+ child: BlocBuilder<PageAccessLevelBloc, PageAccessLevelState>(
builder: (context, state) {
return _buildTextButton(context);
},
@@ -65,7 +65,7 @@ class _LockPageActionState extends State<LockPageAction> {
}
Widget _buildSwitch(BuildContext context) {
- final lockState = context.read<ViewLockStatusBloc>().state;
+ final lockState = context.read<PageAccessLevelBloc>().state;
if (lockState.isLoadingLockStatus) {
return SizedBox.shrink();
}
@@ -86,10 +86,12 @@ class _LockPageActionState extends State<LockPageAction> {
}
Future<void> _toggle(BuildContext context) async {
- final isLocked = context.read<ViewLockStatusBloc>().state.isLocked;
+ final isLocked = context.read<PageAccessLevelBloc>().state.isLocked;
- context.read<ViewLockStatusBloc>().add(
- isLocked ? ViewLockStatusEvent.unlock() : ViewLockStatusEvent.lock(),
+ context.read<PageAccessLevelBloc>().add(
+ isLocked
+ ? PageAccessLevelEvent.unlock()
+ : PageAccessLevelEvent.lock(),
);
Log.info('update page(${widget.view.id}) lock status: $isLocked');
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/widgets/view_title_bar.dart b/frontend/appflowy_flutter/lib/workspace/presentation/widgets/view_title_bar.dart
index 13799fbbcd..d81bf25836 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/widgets/view_title_bar.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/widgets/view_title_bar.dart
@@ -1,3 +1,4 @@
+import 'package:appflowy/features/page_access_level/logic/page_access_level_bloc.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/shared/icon_emoji_picker/tab.dart';
@@ -5,7 +6,6 @@ import 'package:appflowy/startup/plugin/plugin.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/workspace/application/tabs/tabs_bloc.dart';
import 'package:appflowy/workspace/application/view/view_ext.dart';
-import 'package:appflowy/workspace/application/view/view_lock_status_bloc.dart';
import 'package:appflowy/workspace/application/view_title/view_title_bar_bloc.dart';
import 'package:appflowy/workspace/application/view_title/view_title_bloc.dart';
import 'package:appflowy/workspace/presentation/home/menu/menu_shared_state.dart';
@@ -35,31 +35,38 @@ class ViewTitleBar extends StatelessWidget {
providers: [
BlocProvider(create: (_) => ViewTitleBarBloc(view: view)),
BlocProvider(
- create: (_) => ViewLockStatusBloc(view: view)
- ..add(const ViewLockStatusEvent.initial()),
+ create: (_) => PageAccessLevelBloc(view: view)
+ ..add(const PageAccessLevelEvent.initial()),
),
],
- child: BlocBuilder<ViewTitleBarBloc, ViewTitleBarState>(
- builder: (context, state) {
- final ancestors = state.ancestors;
- if (ancestors.isEmpty) {
- return const SizedBox.shrink();
- }
- return SingleChildScrollView(
- scrollDirection: Axis.horizontal,
- child: SizedBox(
- height: 24,
- child: Row(
- children: [
- ..._buildViewTitles(
- context,
- ancestors,
- state.isDeleted,
+ child: BlocBuilder<PageAccessLevelBloc, PageAccessLevelState>(
+ buildWhen: (previous, current) =>
+ previous.isLoadingLockStatus != current.isLoadingLockStatus,
+ builder: (context, pageAccessLevelState) {
+ return BlocBuilder<ViewTitleBarBloc, ViewTitleBarState>(
+ builder: (context, state) {
+ final ancestors = state.ancestors;
+ if (ancestors.isEmpty) {
+ return const SizedBox.shrink();
+ }
+ return SingleChildScrollView(
+ scrollDirection: Axis.horizontal,
+ child: SizedBox(
+ height: 24,
+ child: Row(
+ children: [
+ ..._buildViewTitles(
+ context,
+ ancestors,
+ state.isDeleted,
+ pageAccessLevelState.isEditable,
+ ),
+ _buildLockPageStatus(context),
+ ],
),
- _buildLockPageStatus(context),
- ],
- ),
- ),
+ ),
+ );
+ },
);
},
),
@@ -67,7 +74,7 @@ class ViewTitleBar extends StatelessWidget {
}
Widget _buildLockPageStatus(BuildContext context) {
- return BlocConsumer<ViewLockStatusBloc, ViewLockStatusState>(
+ return BlocConsumer<PageAccessLevelBloc, PageAccessLevelState>(
listenWhen: (previous, current) =>
previous.isLoadingLockStatus == current.isLoadingLockStatus &&
current.isLoadingLockStatus == false,
@@ -93,6 +100,7 @@ class ViewTitleBar extends StatelessWidget {
BuildContext context,
List<ViewPB> views,
bool isDeleted,
+ bool isEditable,
) {
if (isDeleted) {
return _buildDeletedTitle(context, views.last);
@@ -132,7 +140,7 @@ class ViewTitleBar extends StatelessWidget {
message: view.name,
child: ViewTitle(
view: view,
- behavior: i == views.length - 1 && !view.isLocked
+ behavior: i == views.length - 1 && !view.isLocked && isEditable
? ViewTitleBehavior.editable // only the last one is editable
: ViewTitleBehavior.uneditable, // others are not editable
onUpdated: () {
@@ -420,8 +428,8 @@ class LockedPageStatus extends StatelessWidget {
FlowySvgs.lock_page_fill_s,
blendMode: null,
),
- onTap: () => context.read<ViewLockStatusBloc>().add(
- const ViewLockStatusEvent.unlock(),
+ onTap: () => context.read<PageAccessLevelBloc>().add(
+ const PageAccessLevelEvent.unlock(),
),
),
),
@@ -459,8 +467,8 @@ class ReLockedPageStatus extends StatelessWidget {
color: iconColor,
blendMode: null,
),
- onTap: () => context.read<ViewLockStatusBloc>().add(
- const ViewLockStatusEvent.lock(),
+ onTap: () => context.read<PageAccessLevelBloc>().add(
+ const PageAccessLevelEvent.lock(),
),
),
);
diff --git a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/component/button/ghost_button/ghost_icon_text_button.dart b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/component/button/ghost_button/ghost_icon_text_button.dart
index 2daba294d4..1ca56ffa73 100644
--- a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/component/button/ghost_button/ghost_icon_text_button.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/component/button/ghost_button/ghost_icon_text_button.dart
@@ -20,6 +20,7 @@ class AFGhostIconTextButton extends StatelessWidget {
this.padding,
this.borderRadius,
this.disabled = false,
+ this.mainAxisAlignment = MainAxisAlignment.center,
});
/// Primary ghost text button.
@@ -32,6 +33,7 @@ class AFGhostIconTextButton extends StatelessWidget {
EdgeInsetsGeometry? padding,
double? borderRadius,
bool disabled = false,
+ MainAxisAlignment mainAxisAlignment = MainAxisAlignment.center,
}) {
return AFGhostIconTextButton(
key: key,
@@ -42,6 +44,7 @@ class AFGhostIconTextButton extends StatelessWidget {
padding: padding,
borderRadius: borderRadius,
disabled: disabled,
+ mainAxisAlignment: mainAxisAlignment,
backgroundColor: (context, isHovering, disabled) {
final theme = AppFlowyTheme.of(context);
if (disabled) {
@@ -70,6 +73,7 @@ class AFGhostIconTextButton extends StatelessWidget {
AFButtonSize size = AFButtonSize.m,
EdgeInsetsGeometry? padding,
double? borderRadius,
+ MainAxisAlignment mainAxisAlignment = MainAxisAlignment.center,
}) {
return AFGhostIconTextButton(
key: key,
@@ -80,6 +84,7 @@ class AFGhostIconTextButton extends StatelessWidget {
padding: padding,
borderRadius: borderRadius,
disabled: true,
+ mainAxisAlignment: mainAxisAlignment,
backgroundColor: (context, isHovering, disabled) {
return Colors.transparent;
},
@@ -102,6 +107,8 @@ class AFGhostIconTextButton extends StatelessWidget {
final AFBaseButtonColorBuilder? textColor;
final AFBaseButtonColorBuilder? backgroundColor;
+ final MainAxisAlignment mainAxisAlignment;
+
@override
Widget build(BuildContext context) {
final theme = AppFlowyTheme.of(context);
@@ -119,7 +126,7 @@ class AFGhostIconTextButton extends StatelessWidget {
final textColor = this.textColor?.call(context, isHovering, disabled) ??
theme.textColorScheme.primary;
return Row(
- mainAxisAlignment: MainAxisAlignment.center,
+ mainAxisAlignment: mainAxisAlignment,
children: [
iconBuilder(
context,
diff --git a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/component/button/outlined_button/outlined_text_button.dart b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/component/button/outlined_button/outlined_text_button.dart
index e7c3c1c47f..40983e8a78 100644
--- a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/component/button/outlined_button/outlined_text_button.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/component/button/outlined_button/outlined_text_button.dart
@@ -29,6 +29,7 @@ class AFOutlinedTextButton extends AFBaseTextButton {
bool disabled = false,
Alignment? alignment,
TextStyle? textStyle,
+ AFBaseButtonColorBuilder? backgroundColor,
}) {
return AFOutlinedTextButton._(
key: key,
@@ -50,16 +51,17 @@ class AFOutlinedTextButton extends AFBaseTextButton {
}
return theme.borderColorScheme.primary;
},
- backgroundColor: (context, isHovering, disabled) {
- final theme = AppFlowyTheme.of(context);
- if (disabled) {
- return theme.fillColorScheme.content;
- }
- if (isHovering) {
- return theme.fillColorScheme.contentHover;
- }
- return theme.fillColorScheme.content;
- },
+ backgroundColor: backgroundColor ??
+ (context, isHovering, disabled) {
+ final theme = AppFlowyTheme.of(context);
+ if (disabled) {
+ return theme.fillColorScheme.content;
+ }
+ if (isHovering) {
+ return theme.fillColorScheme.contentHover;
+ }
+ return theme.fillColorScheme.content;
+ },
textColor: (context, isHovering, disabled) {
final theme = AppFlowyTheme.of(context);
if (disabled) {
diff --git a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/component/menu/menu.dart b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/component/menu/menu.dart
index 7dcad90e17..b9768f59f7 100644
--- a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/component/menu/menu.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/component/menu/menu.dart
@@ -11,6 +11,7 @@ class AFMenu extends StatelessWidget {
super.key,
required this.children,
this.width,
+ this.backgroundColor,
});
/// The list of widgets to display in the menu (sections or menu items).
@@ -19,12 +20,14 @@ class AFMenu extends StatelessWidget {
/// The width of the menu.
final double? width;
+ final Color? backgroundColor;
+
@override
Widget build(BuildContext context) {
final theme = AppFlowyTheme.of(context);
return Container(
decoration: BoxDecoration(
- color: theme.surfaceColorScheme.primary,
+ color: backgroundColor ?? theme.surfaceColorScheme.primary,
borderRadius: BorderRadius.circular(theme.borderRadius.l),
border: Border.all(
color: theme.borderColorScheme.primary,
diff --git a/frontend/appflowy_flutter/test/bloc_test/lib/features/share_section/shared_section_bloc_test.dart b/frontend/appflowy_flutter/test/bloc_test/lib/features/share_section/shared_section_bloc_test.dart
index b58a4eeb0d..d3d6ebcd93 100644
--- a/frontend/appflowy_flutter/test/bloc_test/lib/features/share_section/shared_section_bloc_test.dart
+++ b/frontend/appflowy_flutter/test/bloc_test/lib/features/share_section/shared_section_bloc_test.dart
@@ -1,5 +1,5 @@
import 'package:appflowy/features/share_tab/data/models/share_access_level.dart';
-import 'package:appflowy/features/shared_section/data/share_pages_repository.dart';
+import 'package:appflowy/features/shared_section/data/repositories/shared_pages_repository.dart';
import 'package:appflowy/features/shared_section/logic/shared_section_bloc.dart';
import 'package:appflowy/features/shared_section/models/shared_page.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/protobuf.dart';
@@ -8,7 +8,7 @@ import 'package:bloc_test/bloc_test.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
-class MockSharePagesRepository extends Mock implements SharePagesRepository {}
+class MockSharePagesRepository extends Mock implements SharedPagesRepository {}
void main() {
late MockSharePagesRepository repository;
@@ -30,8 +30,8 @@ void main() {
when(() => repository.getSharedPages())
.thenAnswer((_) async => FlowyResult.success(initialPages));
bloc = SharedSectionBloc(
- repository: repository,
workspaceId: workspaceId,
+ repository: repository,
)..add(const SharedSectionEvent.init());
});
diff --git a/frontend/appflowy_flutter/test/bloc_test/lib/features/share_tab/share_with_user_bloc_test.dart b/frontend/appflowy_flutter/test/bloc_test/lib/features/share_tab/share_tab_bloc_test.dart
similarity index 79%
rename from frontend/appflowy_flutter/test/bloc_test/lib/features/share_tab/share_with_user_bloc_test.dart
rename to frontend/appflowy_flutter/test/bloc_test/lib/features/share_tab/share_tab_bloc_test.dart
index c950f9ac59..d9e7e6de19 100644
--- a/frontend/appflowy_flutter/test/bloc_test/lib/features/share_tab/share_with_user_bloc_test.dart
+++ b/frontend/appflowy_flutter/test/bloc_test/lib/features/share_tab/share_tab_bloc_test.dart
@@ -1,18 +1,18 @@
import 'package:appflowy/features/share_tab/data/models/models.dart';
-import 'package:appflowy/features/share_tab/data/repositories/local_share_with_user_repository.dart';
-import 'package:appflowy/features/share_tab/logic/share_with_user_bloc.dart';
+import 'package:appflowy/features/share_tab/data/repositories/local_share_with_user_repository_impl.dart';
+import 'package:appflowy/features/share_tab/logic/share_tab_bloc.dart';
import 'package:bloc_test/bloc_test.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
const pageId = 'test_page_id';
const workspaceId = 'test_workspace_id';
- late LocalShareWithUserRepository repository;
- late ShareWithUserBloc bloc;
+ late LocalShareWithUserRepositoryImpl repository;
+ late ShareTabBloc bloc;
setUp(() {
- repository = LocalShareWithUserRepository();
- bloc = ShareWithUserBloc(
+ repository = LocalShareWithUserRepositoryImpl();
+ bloc = ShareTabBloc(
repository: repository,
pageId: pageId,
workspaceId: workspaceId,
@@ -25,12 +25,12 @@ void main() {
const email = '[email protected]';
- group('ShareWithUserBloc', () {
- blocTest<ShareWithUserBloc, ShareWithUserState>(
+ group('ShareTabBloc', () {
+ blocTest<ShareTabBloc, ShareTabState>(
'shares page with user',
build: () => bloc,
act: (bloc) => bloc.add(
- const ShareWithUserEvent.share(
+ ShareTabEvent.inviteUsers(
emails: [email],
accessLevel: ShareAccessLevel.readOnly,
),
@@ -38,13 +38,13 @@ void main() {
wait: const Duration(milliseconds: 100),
expect: () => [
// First state: shareResult is null
- isA<ShareWithUserState>().having(
+ isA<ShareTabState>().having(
(s) => s.shareResult,
'shareResult',
isNull,
),
// Second state: shareResult is Success and users updated
- isA<ShareWithUserState>()
+ isA<ShareTabState>()
.having((s) => s.shareResult, 'shareResult', isNotNull)
.having(
(s) => s.users.any((u) => u.email == email),
@@ -54,21 +54,21 @@ void main() {
],
);
- blocTest<ShareWithUserBloc, ShareWithUserState>(
+ blocTest<ShareTabBloc, ShareTabState>(
'removes user from page',
build: () => bloc,
act: (bloc) => bloc.add(
- const ShareWithUserEvent.remove(
+ ShareTabEvent.removeUsers(
emails: [email],
),
),
wait: const Duration(milliseconds: 100),
expect: () => [
// First state: removeResult is null
- isA<ShareWithUserState>()
+ isA<ShareTabState>()
.having((s) => s.removeResult, 'removeResult', isNull),
// Second state: removeResult is Success and users updated
- isA<ShareWithUserState>()
+ isA<ShareTabState>()
.having((s) => s.removeResult, 'removeResult', isNotNull)
.having(
(s) => s.users.any((u) => u.email == email),
@@ -78,11 +78,11 @@ void main() {
],
);
- blocTest<ShareWithUserBloc, ShareWithUserState>(
+ blocTest<ShareTabBloc, ShareTabState>(
'updates access level for user',
build: () => bloc,
act: (bloc) => bloc.add(
- const ShareWithUserEvent.updateAccessLevel(
+ ShareTabEvent.updateUserAccessLevel(
email: email,
accessLevel: ShareAccessLevel.fullAccess,
),
@@ -90,13 +90,13 @@ void main() {
wait: const Duration(milliseconds: 100),
expect: () => [
// First state: updateAccessLevelResult is null
- isA<ShareWithUserState>().having(
+ isA<ShareTabState>().having(
(s) => s.updateAccessLevelResult,
'updateAccessLevelResult',
isNull,
),
// Second state: updateAccessLevelResult is Success and users updated
- isA<ShareWithUserState>()
+ isA<ShareTabState>()
.having(
(s) => s.updateAccessLevelResult,
'updateAccessLevelResult',
@@ -111,31 +111,31 @@ void main() {
);
final guestEmail = '[email protected]';
- blocTest<ShareWithUserBloc, ShareWithUserState>(
+ blocTest<ShareTabBloc, ShareTabState>(
'turns user into member',
build: () => bloc,
act: (bloc) => bloc
..add(
- ShareWithUserEvent.share(
+ ShareTabEvent.inviteUsers(
emails: [guestEmail],
accessLevel: ShareAccessLevel.readOnly,
),
)
..add(
- ShareWithUserEvent.turnIntoMember(
+ ShareTabEvent.convertToMember(
email: guestEmail,
),
),
wait: const Duration(milliseconds: 100),
expect: () => [
// First state: shareResult is null
- isA<ShareWithUserState>().having(
+ isA<ShareTabState>().having(
(s) => s.shareResult,
'shareResult',
isNull,
),
// Second state: shareResult is Success and users updated
- isA<ShareWithUserState>()
+ isA<ShareTabState>()
.having(
(s) => s.shareResult,
'shareResult',
@@ -147,7 +147,7 @@ void main() {
isTrue,
),
// Third state: turnIntoMemberResult is Success and users updated
- isA<ShareWithUserState>()
+ isA<ShareTabState>()
.having(
(s) => s.turnIntoMemberResult,
'turnIntoMemberResult',
diff --git a/frontend/appflowy_flutter/test/bloc_test/workspace_test/workspace_bloc_test.dart b/frontend/appflowy_flutter/test/bloc_test/workspace_test/workspace_bloc_test.dart
new file mode 100644
index 0000000000..fd96e37396
--- /dev/null
+++ b/frontend/appflowy_flutter/test/bloc_test/workspace_test/workspace_bloc_test.dart
@@ -0,0 +1,749 @@
+import 'package:appflowy/features/workspace/data/repositories/workspace_repository.dart';
+import 'package:appflowy/features/workspace/logic/workspace_bloc.dart';
+import 'package:appflowy/startup/startup.dart';
+import 'package:appflowy/user/application/reminder/reminder_bloc.dart';
+import 'package:appflowy_backend/protobuf/flowy-error/code.pbenum.dart';
+import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
+import 'package:appflowy_backend/protobuf/flowy-folder/protobuf.dart';
+import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
+import 'package:appflowy_result/appflowy_result.dart';
+import 'package:bloc_test/bloc_test.dart';
+import 'package:fixnum/fixnum.dart' as fixnum;
+import 'package:flutter_test/flutter_test.dart';
+import 'package:mocktail/mocktail.dart';
+
+class MockWorkspaceRepository extends Mock implements WorkspaceRepository {}
+
+class MockReminderBloc extends Mock implements ReminderBloc {}
+
+class FakeWorkspaceTypePB extends Fake implements WorkspaceTypePB {}
+
+class FakeReminderEvent extends Fake implements ReminderEvent {}
+
+Future<bool> mockIsBillingEnabled() async => false;
+
+void main() {
+ TestWidgetsFlutterBinding.ensureInitialized();
+
+ setUpAll(() {
+ registerFallbackValue(FakeWorkspaceTypePB());
+ registerFallbackValue(FakeReminderEvent());
+ });
+
+ group('UserWorkspaceBloc', () {
+ late MockWorkspaceRepository mockRepository;
+ late MockReminderBloc mockReminderBloc;
+ late UserProfilePB userProfile;
+ UserWorkspaceBloc? bloc;
+
+ setUp(() {
+ mockRepository = MockWorkspaceRepository();
+ mockReminderBloc = MockReminderBloc();
+ userProfile = UserProfilePB()
+ ..id = fixnum.Int64(123)
+ ..name = 'Test User'
+ ..email = '[email protected]'
+ ..userAuthType = AuthTypePB.Local;
+
+ getIt.registerLazySingleton<ReminderBloc>(() => mockReminderBloc);
+
+ when(() => mockReminderBloc.add(any())).thenReturn(null);
+
+ when(() => mockRepository.getCurrentWorkspace()).thenAnswer(
+ (_) async => FlowyResult.failure(
+ FlowyError()..code = ErrorCode.Internal,
+ ),
+ );
+ when(() => mockRepository.getWorkspaces()).thenAnswer(
+ (_) async => FlowyResult.success(<UserWorkspacePB>[]),
+ );
+ when(
+ () => mockRepository.openWorkspace(
+ workspaceId: any(named: 'workspaceId'),
+ workspaceType: any(named: 'workspaceType'),
+ ),
+ ).thenAnswer(
+ (_) async => FlowyResult.success(null),
+ );
+ when(
+ () => mockRepository.getWorkspaceSubscriptionInfo(
+ workspaceId: any(named: 'workspaceId'),
+ ),
+ ).thenAnswer(
+ (_) async => FlowyResult.success(WorkspaceSubscriptionInfoPB()),
+ );
+ });
+
+ tearDown(() {
+ if (bloc != null && !bloc!.isClosed) {
+ bloc!.close();
+ }
+
+ if (getIt.isRegistered<ReminderBloc>()) {
+ getIt.unregister<ReminderBloc>();
+ }
+ });
+
+ UserWorkspacePB createTestWorkspace({
+ required String id,
+ required String name,
+ String icon = '',
+ WorkspaceTypePB workspaceType = WorkspaceTypePB.LocalW,
+ int createdAt = 1000,
+ }) {
+ return UserWorkspacePB()
+ ..workspaceId = id
+ ..name = name
+ ..icon = icon
+ ..workspaceType = workspaceType
+ ..createdAtTimestamp = fixnum.Int64(createdAt);
+ }
+
+ WorkspacePB createCurrentWorkspace({
+ required String id,
+ required String name,
+ int createdAt = 1000,
+ }) {
+ return WorkspacePB()
+ ..id = id
+ ..name = name
+ ..createTime = fixnum.Int64(createdAt);
+ }
+
+ group('initial state', () {
+ test('should have correct initial state', () {
+ bloc = UserWorkspaceBloc(
+ repository: mockRepository,
+ userProfile: userProfile,
+ );
+
+ expect(bloc!.state.userProfile, equals(userProfile));
+ expect(bloc!.state.workspaces, isEmpty);
+ expect(bloc!.state.currentWorkspace, isNull);
+ expect(bloc!.state.actionResult, isNull);
+ expect(bloc!.state.isCollabWorkspaceOn, isFalse);
+ expect(bloc!.state.workspaceSubscriptionInfo, isNull);
+ });
+ });
+
+ group('fetchWorkspaces', () {
+ blocTest<UserWorkspaceBloc, UserWorkspaceState>(
+ 'should fetch workspaces successfully when current workspace exists in list',
+ setUp: () {
+ final currentWorkspace = createCurrentWorkspace(
+ id: 'workspace-1',
+ name: 'Workspace 1',
+ );
+ final workspaces = [
+ createTestWorkspace(id: 'workspace-1', name: 'Workspace 1'),
+ createTestWorkspace(id: 'workspace-2', name: 'Workspace 2'),
+ ];
+
+ when(() => mockRepository.getCurrentWorkspace()).thenAnswer(
+ (_) async => FlowyResult.success(currentWorkspace),
+ );
+ when(() => mockRepository.getWorkspaces()).thenAnswer(
+ (_) async => FlowyResult.success(workspaces),
+ );
+ when(() => mockRepository.isBillingEnabled()).thenAnswer(
+ (_) async => true,
+ );
+ },
+ build: () => UserWorkspaceBloc(
+ repository: mockRepository,
+ userProfile: userProfile,
+ ),
+ act: (bloc) => bloc.add(UserWorkspaceEvent.fetchWorkspaces()),
+ expect: () => [
+ // First: workspaces are loaded
+ predicate<UserWorkspaceState>(
+ (state) =>
+ state.workspaces.length == 2 && state.currentWorkspace == null,
+ ),
+ // Second: opening workspace action starts
+ predicate<UserWorkspaceState>(
+ (state) =>
+ state.workspaces.length == 2 &&
+ state.actionResult?.actionType == WorkspaceActionType.open &&
+ state.actionResult?.isLoading == true,
+ ),
+ // Third: opening workspace action completes and currentWorkspace is set
+ predicate<UserWorkspaceState>(
+ (state) =>
+ state.workspaces.length == 2 &&
+ state.currentWorkspace != null &&
+ state.currentWorkspace?.workspaceId == 'workspace-1' &&
+ state.actionResult?.isLoading == false,
+ ),
+ // Fourth: subscription info is fetched
+ predicate<UserWorkspaceState>(
+ (state) =>
+ state.workspaces.length == 2 &&
+ state.currentWorkspace?.workspaceId == 'workspace-1' &&
+ state.workspaceSubscriptionInfo != null,
+ ),
+ ],
+ verify: (bloc) {
+ expect(bloc.state.workspaces.length, equals(2));
+ expect(
+ bloc.state.workspaces.first.workspaceId,
+ equals('workspace-1'),
+ );
+ expect(bloc.state.workspaces.last.workspaceId, equals('workspace-2'));
+ expect(
+ bloc.state.currentWorkspace?.workspaceId,
+ equals('workspace-1'),
+ );
+ },
+ );
+
+ blocTest<UserWorkspaceBloc, UserWorkspaceState>(
+ 'should handle error when fetching current workspace fails but workspaces succeed',
+ setUp: () {
+ final workspaces = [
+ createTestWorkspace(id: 'workspace-1', name: 'Workspace 1'),
+ createTestWorkspace(id: 'workspace-2', name: 'Workspace 2'),
+ ];
+
+ when(() => mockRepository.getCurrentWorkspace()).thenAnswer(
+ (_) async => FlowyResult.failure(
+ FlowyError()..code = ErrorCode.Internal,
+ ),
+ );
+ when(() => mockRepository.getWorkspaces()).thenAnswer(
+ (_) async => FlowyResult.success(workspaces),
+ );
+ when(() => mockRepository.isBillingEnabled()).thenAnswer(
+ (_) async => true,
+ );
+ },
+ build: () => UserWorkspaceBloc(
+ repository: mockRepository,
+ userProfile: userProfile,
+ ),
+ act: (bloc) => bloc.add(UserWorkspaceEvent.fetchWorkspaces()),
+ expect: () => [
+ // First: workspaces are loaded, first workspace becomes current
+ predicate<UserWorkspaceState>(
+ (state) =>
+ state.workspaces.length == 2 && state.currentWorkspace == null,
+ ),
+ // Second: opening workspace action starts
+ predicate<UserWorkspaceState>(
+ (state) =>
+ state.workspaces.length == 2 &&
+ state.actionResult?.actionType == WorkspaceActionType.open &&
+ state.actionResult?.isLoading == true,
+ ),
+ // Third: opening workspace action completes and currentWorkspace is set
+ predicate<UserWorkspaceState>(
+ (state) =>
+ state.workspaces.length == 2 &&
+ state.currentWorkspace != null &&
+ state.currentWorkspace?.workspaceId == 'workspace-1' &&
+ state.actionResult?.isLoading == false,
+ ),
+ // Fourth: subscription info is fetched
+ predicate<UserWorkspaceState>(
+ (state) =>
+ state.workspaces.length == 2 &&
+ state.currentWorkspace?.workspaceId == 'workspace-1' &&
+ state.workspaceSubscriptionInfo != null,
+ ),
+ ],
+ verify: (bloc) {
+ expect(bloc.state.workspaces.length, equals(2));
+ expect(
+ bloc.state.currentWorkspace?.workspaceId,
+ equals('workspace-1'),
+ );
+ },
+ );
+
+ blocTest<UserWorkspaceBloc, UserWorkspaceState>(
+ 'should handle error when fetching workspaces fails',
+ setUp: () {
+ when(() => mockRepository.getCurrentWorkspace()).thenAnswer(
+ (_) async => FlowyResult.failure(
+ FlowyError()..code = ErrorCode.Internal,
+ ),
+ );
+ when(() => mockRepository.getWorkspaces()).thenAnswer(
+ (_) async => FlowyResult.failure(
+ FlowyError()..code = ErrorCode.Internal,
+ ),
+ );
+ },
+ build: () => UserWorkspaceBloc(
+ repository: mockRepository,
+ userProfile: userProfile,
+ ),
+ act: (bloc) => bloc.add(UserWorkspaceEvent.fetchWorkspaces()),
+ verify: (bloc) {
+ expect(bloc.state.workspaces, isEmpty);
+ expect(bloc.state.currentWorkspace, isNull);
+
+ verifyNever(() => mockReminderBloc.add(any()));
+ },
+ );
+ });
+
+ group('createWorkspace', () {
+ blocTest<UserWorkspaceBloc, UserWorkspaceState>(
+ 'should create workspace successfully',
+ setUp: () {
+ final newWorkspace = createTestWorkspace(
+ id: 'new-workspace',
+ name: 'New Workspace',
+ );
+
+ when(
+ () => mockRepository.createWorkspace(
+ name: 'New Workspace',
+ workspaceType: WorkspaceTypePB.LocalW,
+ ),
+ ).thenAnswer(
+ (_) async => FlowyResult.success(newWorkspace),
+ );
+
+ when(() => mockRepository.isBillingEnabled()).thenAnswer(
+ (_) async => true,
+ );
+ },
+ build: () => UserWorkspaceBloc(
+ repository: mockRepository,
+ userProfile: userProfile,
+ ),
+ act: (bloc) => bloc.add(
+ UserWorkspaceEvent.createWorkspace(
+ name: 'New Workspace',
+ workspaceType: WorkspaceTypePB.LocalW,
+ ),
+ ),
+ expect: () => [
+ // First: create workspace action starts
+ predicate<UserWorkspaceState>(
+ (state) =>
+ state.actionResult?.actionType == WorkspaceActionType.create &&
+ state.actionResult?.isLoading == true,
+ ),
+ // Second: create workspace action completes, workspace is added
+ predicate<UserWorkspaceState>(
+ (state) =>
+ state.actionResult?.actionType == WorkspaceActionType.create &&
+ state.actionResult?.isLoading == false &&
+ state.actionResult?.result?.isSuccess == true &&
+ state.workspaces.isNotEmpty,
+ ),
+ // Third: opening workspace action starts
+ predicate<UserWorkspaceState>(
+ (state) =>
+ state.actionResult?.actionType == WorkspaceActionType.open &&
+ state.actionResult?.isLoading == true &&
+ state.workspaces.isNotEmpty,
+ ),
+ // Fourth: opening workspace action completes, currentWorkspace is set
+ predicate<UserWorkspaceState>(
+ (state) =>
+ state.actionResult?.actionType == WorkspaceActionType.open &&
+ state.actionResult?.isLoading == false &&
+ state.currentWorkspace != null &&
+ state.currentWorkspace?.workspaceId == 'new-workspace',
+ ),
+ // Fifth: subscription info is fetched
+ predicate<UserWorkspaceState>(
+ (state) =>
+ state.currentWorkspace?.workspaceId == 'new-workspace' &&
+ state.workspaceSubscriptionInfo != null,
+ ),
+ ],
+ verify: (bloc) {
+ expect(
+ bloc.state.workspaces.any((w) => w.workspaceId == 'new-workspace'),
+ isTrue,
+ );
+ },
+ );
+
+ blocTest<UserWorkspaceBloc, UserWorkspaceState>(
+ 'should handle error when creating workspace fails',
+ setUp: () {
+ when(
+ () => mockRepository.createWorkspace(
+ name: any(named: 'name'),
+ workspaceType: any(named: 'workspaceType'),
+ ),
+ ).thenAnswer(
+ (_) async => FlowyResult.failure(
+ FlowyError()..code = ErrorCode.Internal,
+ ),
+ );
+ },
+ build: () => UserWorkspaceBloc(
+ repository: mockRepository,
+ userProfile: userProfile,
+ ),
+ act: (bloc) => bloc.add(
+ UserWorkspaceEvent.createWorkspace(
+ name: 'New Workspace',
+ workspaceType: WorkspaceTypePB.LocalW,
+ ),
+ ),
+ expect: () => [
+ predicate<UserWorkspaceState>(
+ (state) =>
+ state.actionResult?.actionType == WorkspaceActionType.create &&
+ state.actionResult?.isLoading == true,
+ ),
+ predicate<UserWorkspaceState>(
+ (state) =>
+ state.actionResult?.actionType == WorkspaceActionType.create &&
+ state.actionResult?.isLoading == false &&
+ state.actionResult?.result?.isFailure == true,
+ ),
+ ],
+ verify: (bloc) {
+ verifyNever(() => mockReminderBloc.add(any()));
+ },
+ );
+ });
+
+ group('deleteWorkspace', () {
+ blocTest<UserWorkspaceBloc, UserWorkspaceState>(
+ 'should prevent deleting the only workspace',
+ setUp: () {
+ when(() => mockRepository.getCurrentWorkspace()).thenAnswer(
+ (_) async => FlowyResult.success(
+ createCurrentWorkspace(id: 'workspace-1', name: 'Workspace 1'),
+ ),
+ );
+
+ when(() => mockRepository.getWorkspaces()).thenAnswer(
+ (_) async => FlowyResult.success([
+ createTestWorkspace(id: 'workspace-1', name: 'Workspace 1'),
+ ]),
+ );
+ },
+ build: () {
+ final bloc = UserWorkspaceBloc(
+ repository: mockRepository,
+ userProfile: userProfile,
+ );
+
+ bloc.emit(
+ bloc.state.copyWith(
+ workspaces: [
+ createTestWorkspace(id: 'workspace-1', name: 'Workspace 1'),
+ ],
+ ),
+ );
+ return bloc;
+ },
+ act: (bloc) => bloc.add(
+ UserWorkspaceEvent.deleteWorkspace(workspaceId: 'workspace-1'),
+ ),
+ expect: () => [
+ predicate<UserWorkspaceState>(
+ (state) =>
+ state.actionResult?.actionType == WorkspaceActionType.delete &&
+ state.actionResult?.isLoading == true,
+ ),
+ predicate<UserWorkspaceState>(
+ (state) =>
+ state.actionResult?.actionType == WorkspaceActionType.delete &&
+ state.actionResult?.isLoading == false &&
+ state.actionResult?.result?.isFailure == true,
+ ),
+ ],
+ );
+
+ blocTest<UserWorkspaceBloc, UserWorkspaceState>(
+ 'should delete workspace successfully when more than one workspace exists',
+ setUp: () {
+ // Create a sequence of responses for getWorkspaces calls
+ var callCount = 0;
+ when(
+ () => mockRepository.deleteWorkspace(
+ workspaceId: any(named: 'workspaceId'),
+ ),
+ ).thenAnswer(
+ (_) async => FlowyResult.success(null),
+ );
+
+ when(() => mockRepository.getCurrentWorkspace()).thenAnswer(
+ (_) async => FlowyResult.success(
+ createCurrentWorkspace(id: 'workspace-1', name: 'Workspace 1'),
+ ),
+ );
+
+ // Return 2 workspaces on first call (for deletion validation)
+ // Return 1 workspace on second call (after deletion)
+ when(() => mockRepository.getWorkspaces()).thenAnswer(
+ (_) async {
+ callCount++;
+ if (callCount == 1) {
+ return FlowyResult.success([
+ createTestWorkspace(id: 'workspace-1', name: 'Workspace 1'),
+ createTestWorkspace(id: 'workspace-2', name: 'Workspace 2'),
+ ]);
+ } else {
+ return FlowyResult.success([
+ createTestWorkspace(id: 'workspace-1', name: 'Workspace 1'),
+ ]);
+ }
+ },
+ );
+
+ when(() => mockRepository.isBillingEnabled()).thenAnswer(
+ (_) async => true,
+ );
+ },
+ build: () {
+ final bloc = UserWorkspaceBloc(
+ repository: mockRepository,
+ userProfile: userProfile,
+ );
+
+ bloc.emit(
+ bloc.state.copyWith(
+ workspaces: [
+ createTestWorkspace(id: 'workspace-1', name: 'Workspace 1'),
+ createTestWorkspace(id: 'workspace-2', name: 'Workspace 2'),
+ ],
+ currentWorkspace: createTestWorkspace(
+ id: 'workspace-1',
+ name: 'Workspace 1',
+ ),
+ ),
+ );
+ return bloc;
+ },
+ act: (bloc) => bloc.add(
+ UserWorkspaceEvent.deleteWorkspace(workspaceId: 'workspace-2'),
+ ),
+ expect: () => [
+ predicate<UserWorkspaceState>(
+ (state) =>
+ state.actionResult?.actionType == WorkspaceActionType.delete &&
+ state.actionResult?.isLoading == true,
+ ),
+ predicate<UserWorkspaceState>(
+ (state) =>
+ state.actionResult?.actionType == WorkspaceActionType.delete &&
+ state.actionResult?.isLoading == false &&
+ state.actionResult?.result?.isSuccess == true,
+ ),
+ ],
+ verify: (bloc) {
+ expect(bloc.state.workspaces.length, equals(1));
+ expect(
+ bloc.state.workspaces.any((w) => w.workspaceId == 'workspace-2'),
+ isFalse,
+ );
+ },
+ );
+ });
+
+ group('renameWorkspace', () {
+ blocTest<UserWorkspaceBloc, UserWorkspaceState>(
+ 'should rename workspace successfully',
+ setUp: () {
+ when(
+ () => mockRepository.renameWorkspace(
+ workspaceId: 'workspace-1',
+ name: 'Renamed Workspace',
+ ),
+ ).thenAnswer(
+ (_) async => FlowyResult.success(null),
+ );
+ },
+ build: () {
+ final bloc = UserWorkspaceBloc(
+ repository: mockRepository,
+ userProfile: userProfile,
+ );
+
+ bloc.emit(
+ bloc.state.copyWith(
+ workspaces: [
+ createTestWorkspace(id: 'workspace-1', name: 'Original Name'),
+ ],
+ currentWorkspace: createTestWorkspace(
+ id: 'workspace-1',
+ name: 'Original Name',
+ ),
+ ),
+ );
+ return bloc;
+ },
+ act: (bloc) => bloc.add(
+ UserWorkspaceEvent.renameWorkspace(
+ workspaceId: 'workspace-1',
+ name: 'Renamed Workspace',
+ ),
+ ),
+ expect: () => [
+ predicate<UserWorkspaceState>(
+ (state) =>
+ state.actionResult?.actionType == WorkspaceActionType.rename &&
+ state.actionResult?.isLoading == false &&
+ state.workspaces.first.name == 'Renamed Workspace' &&
+ state.currentWorkspace?.name == 'Renamed Workspace',
+ ),
+ ],
+ );
+
+ blocTest<UserWorkspaceBloc, UserWorkspaceState>(
+ 'should handle error when renaming workspace fails',
+ setUp: () {
+ when(
+ () => mockRepository.renameWorkspace(
+ workspaceId: 'workspace-1',
+ name: 'Renamed Workspace',
+ ),
+ ).thenAnswer(
+ (_) async => FlowyResult.failure(
+ FlowyError()..code = ErrorCode.Internal,
+ ),
+ );
+ },
+ build: () {
+ final bloc = UserWorkspaceBloc(
+ repository: mockRepository,
+ userProfile: userProfile,
+ );
+
+ bloc.emit(
+ bloc.state.copyWith(
+ workspaces: [
+ createTestWorkspace(id: 'workspace-1', name: 'Original Name'),
+ ],
+ ),
+ );
+ return bloc;
+ },
+ act: (bloc) => bloc.add(
+ UserWorkspaceEvent.renameWorkspace(
+ workspaceId: 'workspace-1',
+ name: 'Renamed Workspace',
+ ),
+ ),
+ expect: () => [
+ predicate<UserWorkspaceState>(
+ (state) =>
+ state.actionResult?.actionType == WorkspaceActionType.rename &&
+ state.actionResult?.isLoading == false &&
+ state.actionResult?.result?.isFailure == true &&
+ state.workspaces.first.name == 'Original Name',
+ ),
+ ],
+ );
+ });
+
+ group('updateWorkspaceIcon', () {
+ blocTest<UserWorkspaceBloc, UserWorkspaceState>(
+ 'should update workspace icon successfully',
+ setUp: () {
+ when(
+ () => mockRepository.updateWorkspaceIcon(
+ workspaceId: 'workspace-1',
+ icon: 'πŸš€',
+ ),
+ ).thenAnswer(
+ (_) async => FlowyResult.success(null),
+ );
+ },
+ build: () {
+ final bloc = UserWorkspaceBloc(
+ repository: mockRepository,
+ userProfile: userProfile,
+ );
+
+ bloc.emit(
+ bloc.state.copyWith(
+ workspaces: [
+ createTestWorkspace(id: 'workspace-1', name: 'Workspace 1'),
+ ],
+ currentWorkspace: createTestWorkspace(
+ id: 'workspace-1',
+ name: 'Workspace 1',
+ ),
+ ),
+ );
+ return bloc;
+ },
+ act: (bloc) => bloc.add(
+ UserWorkspaceEvent.updateWorkspaceIcon(
+ workspaceId: 'workspace-1',
+ icon: 'πŸš€',
+ ),
+ ),
+ expect: () => [
+ predicate<UserWorkspaceState>(
+ (state) =>
+ state.actionResult?.actionType ==
+ WorkspaceActionType.updateIcon &&
+ state.actionResult?.isLoading == false &&
+ state.workspaces.first.icon == 'πŸš€' &&
+ state.currentWorkspace?.icon == 'πŸš€',
+ ),
+ ],
+ );
+
+ blocTest<UserWorkspaceBloc, UserWorkspaceState>(
+ 'should ignore updating to same icon',
+ build: () {
+ final bloc = UserWorkspaceBloc(
+ repository: mockRepository,
+ userProfile: userProfile,
+ );
+
+ bloc.emit(
+ bloc.state.copyWith(
+ workspaces: [
+ createTestWorkspace(
+ id: 'workspace-1',
+ name: 'Workspace 1',
+ icon: 'πŸš€',
+ ),
+ ],
+ ),
+ );
+ return bloc;
+ },
+ act: (bloc) => bloc.add(
+ UserWorkspaceEvent.updateWorkspaceIcon(
+ workspaceId: 'workspace-1',
+ icon: 'πŸš€',
+ ),
+ ),
+ expect: () => [],
+ );
+ });
+
+ group('updateWorkspaceSubscriptionInfo', () {
+ blocTest<UserWorkspaceBloc, UserWorkspaceState>(
+ 'should update subscription info',
+ build: () => UserWorkspaceBloc(
+ repository: mockRepository,
+ userProfile: userProfile,
+ ),
+ act: (bloc) {
+ final subscriptionInfo = WorkspaceSubscriptionInfoPB();
+
+ bloc.add(
+ UserWorkspaceEvent.updateWorkspaceSubscriptionInfo(
+ workspaceId: 'workspace-1',
+ subscriptionInfo: subscriptionInfo,
+ ),
+ );
+ },
+ expect: () => [
+ predicate<UserWorkspaceState>(
+ (state) => state.workspaceSubscriptionInfo != null,
+ ),
+ ],
+ );
+ });
+ });
+}
diff --git a/frontend/appflowy_flutter/test/widget_test/lib/features/share_section/shared_page_actions_button_test.dart b/frontend/appflowy_flutter/test/widget_test/lib/features/share_section/shared_page_actions_button_test.dart
index 4f381eb99f..12048e23ee 100644
--- a/frontend/appflowy_flutter/test/widget_test/lib/features/share_section/shared_page_actions_button_test.dart
+++ b/frontend/appflowy_flutter/test/widget_test/lib/features/share_section/shared_page_actions_button_test.dart
@@ -100,11 +100,15 @@ void main() {
await tester.tap(find.text('Actions'));
await tester.pumpAndSettle();
- // For read-only access, should only show favorite and open in new tab
- expect(find.byType(AFTextMenuItem), findsNWidgets(2));
+ // For read-only access, should only show favorite, leave shared page and open in new tab
+ expect(find.byType(AFTextMenuItem), findsNWidgets(3));
// Should find favorite action (since view is not favorited)
expect(find.text(ViewMoreActionType.favorite.name), findsOneWidget);
+ expect(
+ find.text(ViewMoreActionType.leaveSharedPage.name),
+ findsOneWidget,
+ );
// Should find open in new tab action
expect(find.text(ViewMoreActionType.openInNewTab.name), findsOneWidget);
diff --git a/frontend/appflowy_flutter/test/widget_test/lib/features/share_section/shared_section_header_test.dart b/frontend/appflowy_flutter/test/widget_test/lib/features/share_section/shared_section_header_test.dart
index 180b1f92c6..c157914fdc 100644
--- a/frontend/appflowy_flutter/test/widget_test/lib/features/share_section/shared_section_header_test.dart
+++ b/frontend/appflowy_flutter/test/widget_test/lib/features/share_section/shared_section_header_test.dart
@@ -10,7 +10,9 @@ void main() {
testWidgets('shows header title', (WidgetTester tester) async {
await tester.pumpWidget(
WidgetTestWrapper(
- child: const SharedSectionHeader(),
+ child: SharedSectionHeader(
+ onTap: () {},
+ ),
),
);
expect(find.text(LocaleKeys.shareSection_shared.tr()), findsOneWidget);
diff --git a/frontend/appflowy_flutter/test/widget_test/lib/features/share_tab/access_level_list_widget_test.dart b/frontend/appflowy_flutter/test/widget_test/lib/features/share_tab/access_level_list_widget_test.dart
index 937b6709b4..46fa3e49bf 100644
--- a/frontend/appflowy_flutter/test/widget_test/lib/features/share_tab/access_level_list_widget_test.dart
+++ b/frontend/appflowy_flutter/test/widget_test/lib/features/share_tab/access_level_list_widget_test.dart
@@ -21,6 +21,8 @@ void main() {
child: AccessLevelListWidget(
selectedAccessLevel: ShareAccessLevel.readAndWrite,
supportedAccessLevels: ShareAccessLevel.values,
+ additionalUserManagementOptions:
+ AdditionalUserManagementOptions.values,
callbacks: AccessLevelListCallbacks(
onSelectAccessLevel: (level) => selectedLevel = level,
onTurnIntoMember: () => turnedIntoMember = true,
diff --git a/frontend/appflowy_flutter/test/widget_test/lib/features/share_tab/copy_link_widget_test.dart b/frontend/appflowy_flutter/test/widget_test/lib/features/share_tab/copy_link_widget_test.dart
index 5a7f6541f0..270c7f617a 100644
--- a/frontend/appflowy_flutter/test/widget_test/lib/features/share_tab/copy_link_widget_test.dart
+++ b/frontend/appflowy_flutter/test/widget_test/lib/features/share_tab/copy_link_widget_test.dart
@@ -1,5 +1,5 @@
-import 'package:appflowy/features/share_tab/data/repositories/local_share_with_user_repository.dart';
-import 'package:appflowy/features/share_tab/logic/share_with_user_bloc.dart';
+import 'package:appflowy/features/share_tab/data/repositories/local_share_with_user_repository_impl.dart';
+import 'package:appflowy/features/share_tab/logic/share_tab_bloc.dart';
import 'package:appflowy/features/share_tab/presentation/widgets/copy_link_widget.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/clipboard_service.dart';
@@ -28,27 +28,24 @@ void main() {
(WidgetTester tester) async {
final mockClipboard = getIt<ClipboardService>() as _MockClipboardService;
when(() => mockClipboard.setData(any())).thenAnswer((_) async {});
- final bloc = ShareWithUserBloc(
- repository: LocalShareWithUserRepository(),
+ final bloc = ShareTabBloc(
+ repository: LocalShareWithUserRepositoryImpl(),
pageId: 'pageId',
workspaceId: 'workspaceId',
);
const testLink = 'https://test.link';
await tester.pumpWidget(
WidgetTestWrapper(
- child: BlocProvider<ShareWithUserBloc>.value(
+ child: BlocProvider<ShareTabBloc>.value(
value: bloc,
child: CopyLinkWidget(shareLink: testLink),
),
),
);
- expect(find.text(testLink), findsOneWidget);
expect(find.text(LocaleKeys.shareTab_copyLink.tr()), findsOneWidget);
await tester.tap(find.text(LocaleKeys.shareTab_copyLink.tr()));
await tester.pumpAndSettle();
- // Timer (duration: 0:00:03.000000, periodic: false), created:
- // #0 new FakeTimer._ (package:fake_async/fake_async.dart:308:62)
await tester.pump(const Duration(seconds: 4));
verify(() => mockClipboard.setData(any())).called(1);
diff --git a/frontend/appflowy_flutter/test/widget_test/lib/features/share_tab/edit_access_level_widget_test.dart b/frontend/appflowy_flutter/test/widget_test/lib/features/share_tab/edit_access_level_widget_test.dart
index 05bd144774..69101f5559 100644
--- a/frontend/appflowy_flutter/test/widget_test/lib/features/share_tab/edit_access_level_widget_test.dart
+++ b/frontend/appflowy_flutter/test/widget_test/lib/features/share_tab/edit_access_level_widget_test.dart
@@ -14,6 +14,8 @@ void main() {
child: EditAccessLevelWidget(
selectedAccessLevel: ShareAccessLevel.readOnly,
supportedAccessLevels: ShareAccessLevel.values,
+ additionalUserManagementOptions:
+ AdditionalUserManagementOptions.values,
callbacks: AccessLevelListCallbacks(
onSelectAccessLevel: (level) {},
onTurnIntoMember: () {},
diff --git a/frontend/appflowy_flutter/test/widget_test/lib/features/share_tab/general_access_section_test.dart b/frontend/appflowy_flutter/test/widget_test/lib/features/share_tab/general_access_section_test.dart
index 2468e4c878..a61b70cb64 100644
--- a/frontend/appflowy_flutter/test/widget_test/lib/features/share_tab/general_access_section_test.dart
+++ b/frontend/appflowy_flutter/test/widget_test/lib/features/share_tab/general_access_section_test.dart
@@ -1,3 +1,4 @@
+import 'package:appflowy/features/share_tab/data/models/shared_group.dart';
import 'package:appflowy/features/share_tab/presentation/widgets/general_access_section.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -9,7 +10,13 @@ void main() {
(WidgetTester tester) async {
await tester.pumpWidget(
WidgetTestWrapper(
- child: GeneralAccessSection(),
+ child: GeneralAccessSection(
+ group: SharedGroup(
+ id: '1',
+ name: 'Group 1',
+ icon: 'πŸ‘₯',
+ ),
+ ),
),
);
expect(find.text('General access'), findsOneWidget);
diff --git a/frontend/appflowy_flutter/test/widget_test/lib/features/share_tab/shared_group_widget_test.dart b/frontend/appflowy_flutter/test/widget_test/lib/features/share_tab/shared_group_widget_test.dart
index 26b0f1143a..ee68dcf68b 100644
--- a/frontend/appflowy_flutter/test/widget_test/lib/features/share_tab/shared_group_widget_test.dart
+++ b/frontend/appflowy_flutter/test/widget_test/lib/features/share_tab/shared_group_widget_test.dart
@@ -1,3 +1,4 @@
+import 'package:appflowy/features/share_tab/data/models/shared_group.dart';
import 'package:appflowy/features/share_tab/presentation/widgets/shared_group_widget.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:easy_localization/easy_localization.dart';
@@ -11,7 +12,13 @@ void main() {
(WidgetTester tester) async {
await tester.pumpWidget(
WidgetTestWrapper(
- child: SharedGroupWidget(),
+ child: SharedGroupWidget(
+ group: SharedGroup(
+ id: '1',
+ name: 'Group 1',
+ icon: 'πŸ‘₯',
+ ),
+ ),
),
);
expect(
diff --git a/frontend/resources/flowy_icons/20x/favorite_header.svg b/frontend/resources/flowy_icons/20x/favorite_header.svg
new file mode 100644
index 0000000000..c55073a9cf
--- /dev/null
+++ b/frontend/resources/flowy_icons/20x/favorite_header.svg
@@ -0,0 +1,3 @@
+<svg width="20" height="21" viewBox="0 0 20 21" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path d="M8.00721 6.35755C8.89385 4.76697 9.33716 3.97168 9.99999 3.97168C10.6628 3.97168 11.1061 4.76696 11.9928 6.35754L12.2221 6.76904C12.4741 7.22104 12.6001 7.44704 12.7966 7.59615C12.993 7.74527 13.2376 7.80062 13.7269 7.91132L14.1723 8.01211C15.8941 8.40168 16.755 8.59646 16.9598 9.2551C17.1646 9.91371 16.5777 10.6001 15.4039 11.9726L15.1003 12.3277C14.7667 12.7178 14.5999 12.9128 14.5249 13.1541C14.4499 13.3954 14.4751 13.6556 14.5255 14.176L14.5714 14.6498C14.7489 16.4811 14.8376 17.3968 14.3014 17.8038C13.7651 18.2109 12.9591 17.8398 11.347 17.0975L10.9299 16.9055C10.4719 16.6945 10.2428 16.5891 9.99999 16.5891C9.75716 16.5891 9.52812 16.6945 9.07004 16.9055L8.65298 17.0975C7.04087 17.8398 6.23482 18.2109 5.6986 17.8038C5.16238 17.3968 5.25111 16.4811 5.42858 14.6498L5.47448 14.176C5.52492 13.6556 5.55013 13.3954 5.4751 13.1541C5.40007 12.9128 5.2333 12.7178 4.89974 12.3277L4.59607 11.9726C3.42228 10.6001 2.83538 9.91371 3.0402 9.2551C3.24502 8.59646 4.1059 8.40168 5.82768 8.01211L6.27312 7.91132C6.76239 7.80062 7.00703 7.74527 7.20345 7.59615C7.39988 7.44704 7.52587 7.22104 7.77782 6.76904L8.00721 6.35755Z" fill="#FFBA00"/>
+</svg>
diff --git a/frontend/resources/flowy_icons/20x/shared_with_me.svg b/frontend/resources/flowy_icons/20x/shared_with_me.svg
new file mode 100644
index 0000000000..17ebacd10d
--- /dev/null
+++ b/frontend/resources/flowy_icons/20x/shared_with_me.svg
@@ -0,0 +1,6 @@
+<svg width="20" height="21" viewBox="0 0 20 21" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path d="M4.86927 6.05421C4.86927 6.89169 5.20196 7.69488 5.79415 8.28706C6.38634 8.87925 7.18952 9.21194 8.027 9.21194C8.86448 9.21194 9.66766 8.87925 10.2599 8.28706C10.852 7.69488 11.1847 6.89169 11.1847 6.05421C11.1847 5.21673 10.852 4.41355 10.2599 3.82136C9.66766 3.22917 8.86448 2.89648 8.027 2.89648C7.18952 2.89648 6.38634 3.22917 5.79415 3.82136C5.20196 4.41355 4.86927 5.21673 4.86927 6.05421Z" fill="#6F748C"/>
+<path d="M2.50098 14.7388C2.50098 15.1534 2.64391 15.5641 2.92162 15.9472C3.19933 16.3303 3.60637 16.6784 4.11951 16.9716C4.63265 17.2648 5.24183 17.4974 5.91228 17.6561C6.58273 17.8148 7.30131 17.8965 8.027 17.8965C8.75269 17.8965 9.47127 17.8148 10.1417 17.6561C10.8122 17.4974 11.4214 17.2648 11.9345 16.9716C12.4476 16.6784 12.8547 16.3303 13.1324 15.9472C13.4101 15.5641 13.553 15.1534 13.553 14.7388C13.553 14.3241 13.4101 13.9135 13.1324 13.5303C12.8547 13.1472 12.4476 12.7991 11.9345 12.5059C11.4214 12.2127 10.8122 11.9801 10.1417 11.8214C9.47127 11.6627 8.75269 11.581 8.027 11.581C7.30131 11.581 6.58273 11.6627 5.91228 11.8214C5.24183 11.9801 4.63265 12.2127 4.11951 12.5059C3.60637 12.7991 3.19933 13.1472 2.92162 13.5303C2.64391 13.9135 2.50098 14.3241 2.50098 14.7388Z" fill="#6F748C"/>
+<path d="M17.4991 14.7385C17.4991 16.0465 15.8922 17.1068 13.9302 17.1068C14.5082 16.475 14.9057 15.682 14.9057 14.7396C14.9057 13.7962 14.5073 13.0024 13.9282 12.3702C15.8901 12.3702 17.4991 13.4305 17.4991 14.7385Z" fill="#6F748C"/>
+<path d="M15.1308 6.05499C15.1308 7.36296 14.0705 8.42328 12.7625 8.42328C12.4773 8.42328 12.2039 8.37286 11.9506 8.28046C12.3241 7.62357 12.5374 6.86375 12.5374 6.0541C12.5374 5.24505 12.3244 4.48575 11.9514 3.82921C12.2044 3.73699 12.4776 3.68669 12.7625 3.68669C14.0705 3.68669 15.1308 4.74701 15.1308 6.05499Z" fill="#6F748C"/>
+</svg>
diff --git a/frontend/rust-lib/Cargo.lock b/frontend/rust-lib/Cargo.lock
index b6be35fcd3..6729ed9687 100644
--- a/frontend/rust-lib/Cargo.lock
+++ b/frontend/rust-lib/Cargo.lock
@@ -2549,6 +2549,7 @@ dependencies = [
"flowy-notification",
"flowy-search-pub",
"flowy-sqlite",
+ "flowy-user-pub",
"futures",
"lib-dispatch",
"lib-infra",
diff --git a/frontend/rust-lib/flowy-core/src/deps_resolve/folder_deps/mod.rs b/frontend/rust-lib/flowy-core/src/deps_resolve/folder_deps/mod.rs
index 39a749bfb0..a1391457b9 100644
--- a/frontend/rust-lib/flowy-core/src/deps_resolve/folder_deps/mod.rs
+++ b/frontend/rust-lib/flowy-core/src/deps_resolve/folder_deps/mod.rs
@@ -17,6 +17,7 @@ use flowy_sqlite::kv::KVStorePreferences;
use flowy_sqlite::DBConnection;
use flowy_user::services::authenticate_user::AuthenticateUser;
use flowy_user::services::data_import::load_collab_by_object_id;
+use flowy_user_pub::entities::UserWorkspace;
use std::str::FromStr;
use std::sync::{Arc, Weak};
@@ -107,6 +108,10 @@ impl FolderUser for FolderUserImpl {
fn sqlite_connection(&self, uid: i64) -> Result<DBConnection, FlowyError> {
self.upgrade_user()?.get_sqlite_connection(uid)
}
+
+ fn get_active_user_workspace(&self) -> FlowyResult<UserWorkspace> {
+ self.upgrade_user()?.get_active_user_workspace()
+ }
}
#[derive(Clone)]
diff --git a/frontend/rust-lib/flowy-folder/Cargo.toml b/frontend/rust-lib/flowy-folder/Cargo.toml
index aa92cd772f..d609d59ab9 100644
--- a/frontend/rust-lib/flowy-folder/Cargo.toml
+++ b/frontend/rust-lib/flowy-folder/Cargo.toml
@@ -12,6 +12,7 @@ collab-entity = { workspace = true }
collab-integrate = { workspace = true }
flowy-folder-pub = { workspace = true }
flowy-search-pub = { workspace = true }
+flowy-user-pub = { workspace = true }
flowy-sqlite = { workspace = true }
flowy-derive.workspace = true
flowy-notification = { workspace = true }
diff --git a/frontend/rust-lib/flowy-folder/src/manager.rs b/frontend/rust-lib/flowy-folder/src/manager.rs
index 0601516e96..0c05f4093f 100644
--- a/frontend/rust-lib/flowy-folder/src/manager.rs
+++ b/frontend/rust-lib/flowy-folder/src/manager.rs
@@ -47,6 +47,7 @@ use flowy_folder_pub::sql::workspace_shared_view_sql::{
};
use flowy_sqlite::DBConnection;
use flowy_sqlite::kv::KVStorePreferences;
+use flowy_user_pub::entities::{Role, UserWorkspace};
use futures::future;
use std::collections::HashMap;
use std::fmt::{Display, Formatter};
@@ -62,6 +63,7 @@ pub trait FolderUser: Send + Sync {
fn collab_db(&self, uid: i64) -> Result<Weak<CollabKVDB>, FlowyError>;
fn sqlite_connection(&self, uid: i64) -> Result<DBConnection, FlowyError>;
fn is_folder_exist_on_disk(&self, uid: i64, workspace_id: &Uuid) -> FlowyResult<bool>;
+ fn get_active_user_workspace(&self) -> FlowyResult<UserWorkspace>;
}
pub struct FolderManager {
@@ -662,6 +664,24 @@ impl FolderManager {
/// again using the ID of the child view you wish to access.
#[tracing::instrument(level = "debug", skip(self))]
pub async fn get_view_pb(&self, view_id: &str) -> FlowyResult<ViewPB> {
+ let workspace = self.user.get_active_user_workspace()?;
+ let role = workspace.role;
+
+ // If the user is a Guest, check if they have access to this view through shared views
+ if let Some(Role::Guest) = role {
+ let flatten_shared_views = self.get_flatten_shared_pages().await?;
+ let has_access = flatten_shared_views
+ .iter()
+ .any(|shared_view| shared_view.id == view_id);
+
+ if !has_access {
+ return Err(FlowyError::new(
+ ErrorCode::RecordNotFound,
+ format!("Guest user does not have access to view: {}", view_id),
+ ));
+ }
+ }
+
let view_id = view_id.to_string();
let lock = self
@@ -2143,6 +2163,9 @@ impl FolderManager {
}
/// Get the shared views of the workspace.
+ ///
+ /// This function will return the first level of the shared views. If the shared view has child
+ /// views, this function will not return the child views.
pub async fn get_shared_pages(&self) -> FlowyResult<RepeatedSharedViewResponsePB> {
let uid = self.user.user_id()?;
let conn = self.user.sqlite_connection(uid)?;
@@ -2150,6 +2173,17 @@ impl FolderManager {
let mut local_shared_views = vec![];
let all_views: Vec<Arc<View>> = self.get_all_views().await?;
+ let lock = self
+ .mutex_folder
+ .load_full()
+ .ok_or_else(folder_not_init_error)?;
+ let folder = lock.read().await;
+ // filter the views that are in the trash
+ let trash_ids = Self::get_all_trash_ids(&folder);
+ let all_views = all_views
+ .into_iter()
+ .filter(|view| !trash_ids.contains(&view.id))
+ .collect::<Vec<Arc<View>>>();
// 1. Get the data from the local database first
if let Ok(shared_views) =
@@ -2238,6 +2272,43 @@ impl FolderManager {
Ok(local_result)
}
+
+ /// Get all the shared views of the workspace.
+ ///
+ /// This function will return all the shared views of the workspace, including the child views of the shared views.
+ pub async fn get_flatten_shared_pages(&self) -> FlowyResult<Vec<ViewPB>> {
+ let shared_pages = self.get_shared_pages().await?;
+ let mut flattened_views = Vec::new();
+
+ for shared_view in shared_pages.shared_views {
+ // Add the parent view
+ let parent_view = shared_view.view;
+ let child_views = parent_view.child_views.clone();
+ flattened_views.push(ViewPB {
+ child_views: vec![], // Remove child views to flatten the structure
+ ..parent_view
+ });
+
+ // Recursively add all child views
+ Self::flatten_child_views(&child_views, &mut flattened_views);
+ }
+
+ Ok(flattened_views)
+ }
+
+ fn flatten_child_views(views: &[ViewPB], flattened_views: &mut Vec<ViewPB>) {
+ for view in views {
+ let child_views = view.child_views.clone();
+ flattened_views.push(ViewPB {
+ child_views: vec![],
+ ..view.clone()
+ });
+
+ if !child_views.is_empty() {
+ Self::flatten_child_views(&child_views, flattened_views);
+ }
+ }
+ }
}
/// Return the views that belong to the workspace. The views are filtered by the trash and all the private views.
diff --git a/frontend/rust-lib/flowy-user/src/services/authenticate_user.rs b/frontend/rust-lib/flowy-user/src/services/authenticate_user.rs
index 67ef4848b8..ee2a42dd4f 100644
--- a/frontend/rust-lib/flowy-user/src/services/authenticate_user.rs
+++ b/frontend/rust-lib/flowy-user/src/services/authenticate_user.rs
@@ -176,4 +176,11 @@ impl AuthenticateUser {
},
}
}
+
+ pub fn get_active_user_workspace(&self) -> FlowyResult<UserWorkspace> {
+ let session = self.get_session()?;
+ let mut conn = self.get_sqlite_connection(session.user_id)?;
+ let workspace = select_user_workspace(&session.workspace_id, &mut conn)?;
+ Ok(workspace.into())
+ }
}