mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: disable publish in non-apppflowy-cloud user mode
This commit is contained in:
parent
bec7227cff
commit
f96218820d
@ -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<DocumentShareEvent, DocumentShareState> {
|
||||
);
|
||||
|
||||
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<DocumentShareEvent, DocumentShareState> {
|
||||
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<ExportDataPB, FlowyError>? exportResult,
|
||||
required bool isPublished,
|
||||
FlowyResult<void, FlowyError>? publishResult,
|
||||
FlowyResult<void, FlowyError>? unpublishResult,
|
||||
required bool isLoading,
|
||||
required String url,
|
||||
required String viewName,
|
||||
required bool enablePublish,
|
||||
FlowyResult<ExportDataPB, FlowyError>? exportResult,
|
||||
FlowyResult<void, FlowyError>? publishResult,
|
||||
FlowyResult<void, FlowyError>? unpublishResult,
|
||||
}) = _DocumentShareState;
|
||||
|
||||
factory DocumentShareState.initial() => const DocumentShareState(
|
||||
isLoading: false,
|
||||
isPublished: false,
|
||||
enablePublish: true,
|
||||
url: '',
|
||||
viewName: '',
|
||||
);
|
||||
|
@ -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<DocumentShareBloc>().view);
|
||||
final result = await documentExporter.export(DocumentExportType.markdown);
|
||||
result.fold(
|
||||
(markdown) => getIt<ClipboardService>()
|
||||
.setData(ClipboardServiceData(plainText: markdown)),
|
||||
(error) => showMessageToast(error.msg),
|
||||
(markdown) {
|
||||
getIt<ClipboardService>().setData(
|
||||
ClipboardServiceData(plainText: markdown),
|
||||
);
|
||||
showToastNotification(
|
||||
context,
|
||||
message: LocaleKeys.grid_url_copiedNotification.tr(),
|
||||
);
|
||||
},
|
||||
(error) => showToastNotification(context, message: error.msg),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +43,10 @@ class DocumentShareButton extends StatelessWidget {
|
||||
},
|
||||
child: BlocBuilder<DocumentShareBloc, DocumentShareState>(
|
||||
builder: (context, state) {
|
||||
final tabs = [
|
||||
if (state.enablePublish) ShareMenuTab.publish,
|
||||
ShareMenuTab.exportAs,
|
||||
];
|
||||
final shareBloc = context.read<DocumentShareBloc>();
|
||||
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,
|
||||
),
|
||||
),
|
||||
|
@ -12,26 +12,25 @@ enum ShareMenuTab {
|
||||
publish,
|
||||
exportAs;
|
||||
|
||||
static List<ShareMenuTab> 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<ShareMenuTab> tabs;
|
||||
|
||||
@override
|
||||
State<ShareMenu> createState() => _ShareMenuState();
|
||||
@ -39,15 +38,19 @@ class ShareMenu extends StatefulWidget {
|
||||
|
||||
class _ShareMenuState extends State<ShareMenu>
|
||||
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<ShareMenu>
|
||||
|
||||
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<ShareMenu>
|
||||
tabs: children,
|
||||
onTap: (index) {
|
||||
setState(() {
|
||||
selectedTab = ShareMenuTab.supportedTabs[index];
|
||||
selectedTab = widget.tabs[index];
|
||||
});
|
||||
},
|
||||
);
|
||||
|
@ -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),
|
||||
),
|
||||
);
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user