diff --git a/frontend/appflowy_flutter/lib/plugins/document/application/document_share_bloc.dart b/frontend/appflowy_flutter/lib/plugins/document/application/document_share_bloc.dart index b1cc65a32a..a6e262293c 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/application/document_share_bloc.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/application/document_share_bloc.dart @@ -1,5 +1,6 @@ import 'dart:io'; +import 'package:appflowy/user/application/user_service.dart'; import 'package:appflowy/workspace/application/export/document_exporter.dart'; import 'package:appflowy/workspace/application/view/view_listener.dart'; import 'package:appflowy/workspace/application/view/view_service.dart'; @@ -7,6 +8,7 @@ import 'package:appflowy_backend/log.dart'; import 'package:appflowy_backend/protobuf/flowy-document/entities.pb.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/protobuf.dart'; import 'package:appflowy_result/appflowy_result.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; @@ -31,12 +33,18 @@ class DocumentShareBloc extends Bloc { ); final publishInfo = await ViewBackendService.getPublishInfo(view); + final enablePublish = + await UserBackendService.getCurrentUserProfile().fold( + (v) => v.authenticator == AuthenticatorPB.AppFlowyCloud, + (p) => false, + ); publishInfo.fold((s) { emit( state.copyWith( isPublished: true, url: '$_url/${s.namespace}/${s.publishName}', viewName: view.name, + enablePublish: enablePublish, ), ); }, (f) { @@ -45,6 +53,7 @@ class DocumentShareBloc extends Bloc { isPublished: false, url: '', viewName: view.name, + enablePublish: enablePublish, ), ); }); @@ -220,18 +229,20 @@ class DocumentShareEvent with _$DocumentShareEvent { @freezed class DocumentShareState with _$DocumentShareState { const factory DocumentShareState({ - required bool isLoading, - FlowyResult? exportResult, required bool isPublished, - FlowyResult? publishResult, - FlowyResult? unpublishResult, + required bool isLoading, required String url, required String viewName, + required bool enablePublish, + FlowyResult? exportResult, + FlowyResult? publishResult, + FlowyResult? unpublishResult, }) = _DocumentShareState; factory DocumentShareState.initial() => const DocumentShareState( isLoading: false, isPublished: false, + enablePublish: true, url: '', viewName: '', ); diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/share/export_tab.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/share/export_tab.dart index ab9669f8e8..c5bbecbe0b 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/share/export_tab.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/share/export_tab.dart @@ -6,7 +6,7 @@ import 'package:appflowy/startup/startup.dart'; import 'package:appflowy/util/string_extension.dart'; import 'package:appflowy/util/theme_extension.dart'; import 'package:appflowy/workspace/application/export/document_exporter.dart'; -import 'package:appflowy/workspace/presentation/home/toast.dart'; +import 'package:appflowy/workspace/presentation/widgets/dialogs.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flowy_infra/file_picker/file_picker_service.dart'; import 'package:flowy_infra_ui/flowy_infra_ui.dart'; @@ -81,9 +81,16 @@ class ExportTab extends StatelessWidget { DocumentExporter(context.read().view); final result = await documentExporter.export(DocumentExportType.markdown); result.fold( - (markdown) => getIt() - .setData(ClipboardServiceData(plainText: markdown)), - (error) => showMessageToast(error.msg), + (markdown) { + getIt().setData( + ClipboardServiceData(plainText: markdown), + ); + showToastNotification( + context, + message: LocaleKeys.grid_url_copiedNotification.tr(), + ); + }, + (error) => showToastNotification(context, message: error.msg), ); } } diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/share/share_button.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/share/share_button.dart index 4a78b83df9..78163fe3e3 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/share/share_button.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/share/share_button.dart @@ -43,6 +43,10 @@ class DocumentShareButton extends StatelessWidget { }, child: BlocBuilder( builder: (context, state) { + final tabs = [ + if (state.enablePublish) ShareMenuTab.publish, + ShareMenuTab.exportAs, + ]; final shareBloc = context.read(); return SizedBox( height: 32.0, @@ -55,12 +59,18 @@ class DocumentShareButton extends StatelessWidget { offset: const Offset(0, 8), popupBuilder: (context) => BlocProvider.value( value: shareBloc, - child: const ShareMenu(), + child: ShareMenu( + tabs: tabs, + ), ), child: RoundedTextButton( title: LocaleKeys.shareAction_buttonText.tr(), - padding: const EdgeInsets.symmetric(horizontal: 12.0), + padding: const EdgeInsets.symmetric(horizontal: 14.0), fontSize: 14.0, + fontWeight: FontWeight.w500, + borderRadius: const BorderRadius.all( + Radius.circular(10.0), + ), textColor: Theme.of(context).colorScheme.onPrimary, ), ), diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/share/share_menu.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/share/share_menu.dart index fa9670fe18..71cb0aea16 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/share/share_menu.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/share/share_menu.dart @@ -12,26 +12,25 @@ enum ShareMenuTab { publish, exportAs; - static List supportedTabs = [ - // ShareMenuTab.share, - ShareMenuTab.publish, - ShareMenuTab.exportAs, - ]; - String get i18n { switch (this) { case ShareMenuTab.share: - return 'Share'; + return LocaleKeys.shareAction_shareTab.tr(); case ShareMenuTab.publish: - return LocaleKeys.shareAction_publish; + return LocaleKeys.shareAction_publishTab.tr(); case ShareMenuTab.exportAs: - return 'Export as'; + return LocaleKeys.shareAction_exportAsTab.tr(); } } } class ShareMenu extends StatefulWidget { - const ShareMenu({super.key}); + const ShareMenu({ + super.key, + required this.tabs, + }); + + final List tabs; @override State createState() => _ShareMenuState(); @@ -39,15 +38,19 @@ class ShareMenu extends StatefulWidget { class _ShareMenuState extends State with SingleTickerProviderStateMixin { - ShareMenuTab selectedTab = ShareMenuTab.publish; + late ShareMenuTab selectedTab = widget.tabs.first; late final tabController = TabController( - length: ShareMenuTab.supportedTabs.length, + length: widget.tabs.length, vsync: this, - initialIndex: ShareMenuTab.supportedTabs.indexOf(selectedTab), + initialIndex: widget.tabs.indexOf(selectedTab), ); @override Widget build(BuildContext context) { + if (widget.tabs.isEmpty) { + return const SizedBox.shrink(); + } + return Column( mainAxisSize: MainAxisSize.min, children: [ @@ -79,7 +82,7 @@ class _ShareMenuState extends State Widget _buildTabBar(BuildContext context) { final children = [ - for (final tab in ShareMenuTab.supportedTabs) + for (final tab in widget.tabs) Padding( padding: const EdgeInsets.only(bottom: 10), child: _Segment( @@ -103,7 +106,7 @@ class _ShareMenuState extends State tabs: children, onTap: (index) { setState(() { - selectedTab = ShareMenuTab.supportedTabs[index]; + selectedTab = widget.tabs[index]; }); }, ); diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/widgets/dialogs.dart b/frontend/appflowy_flutter/lib/workspace/presentation/widgets/dialogs.dart index 89f44fcde7..8d1196b503 100644 --- a/frontend/appflowy_flutter/lib/workspace/presentation/widgets/dialogs.dart +++ b/frontend/appflowy_flutter/lib/workspace/presentation/widgets/dialogs.dart @@ -304,11 +304,10 @@ void showToastNotification( ) : null, alignment: Alignment.bottomCenter, - autoCloseDuration: const Duration(seconds: 4), + autoCloseDuration: const Duration(milliseconds: 3000), showProgressBar: false, backgroundColor: Theme.of(context).colorScheme.surface, borderSide: BorderSide( - width: 1.5, color: Colors.grey.withOpacity(0.4), ), ); diff --git a/frontend/resources/translations/en.json b/frontend/resources/translations/en.json index 6825bf687d..4f1cb27be5 100644 --- a/frontend/resources/translations/en.json +++ b/frontend/resources/translations/en.json @@ -111,7 +111,10 @@ "publishToTheWebHint": "Create a website with AppFlowy", "publish": "Publish", "unPublish": "Unpublish", - "visitSite": "Visit site" + "visitSite": "Visit site", + "exportAsTab": "Export as", + "publishTab": "Publish", + "shareTab": "Share" }, "moreAction": { "small": "small",