mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: refacotor export-as
This commit is contained in:
parent
2eeac030a5
commit
7dd4a52c61
frontend
appflowy_flutter/lib/plugins/document/presentation/share
resources/flowy_icons/16x
@ -0,0 +1,119 @@
|
||||
import 'package:appflowy/generated/flowy_svgs.g.dart';
|
||||
import 'package:appflowy/generated/locale_keys.g.dart';
|
||||
import 'package:appflowy/plugins/document/application/document_share_bloc.dart';
|
||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/clipboard_service.dart';
|
||||
import 'package:appflowy/startup/startup.dart';
|
||||
import 'package:appflowy/util/string_extension.dart';
|
||||
import 'package:appflowy/workspace/application/export/document_exporter.dart';
|
||||
import 'package:appflowy/workspace/presentation/home/toast.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';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
class ExportTab extends StatelessWidget {
|
||||
const ExportTab({
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
const VSpace(10),
|
||||
_ExportButton(
|
||||
title: LocaleKeys.shareAction_html.tr(),
|
||||
svg: FlowySvgs.export_html_s,
|
||||
onTap: () => _exportHTML(context),
|
||||
),
|
||||
const VSpace(10),
|
||||
_ExportButton(
|
||||
title: LocaleKeys.shareAction_markdown.tr(),
|
||||
svg: FlowySvgs.export_markdown_s,
|
||||
onTap: () => _exportMarkdown(context),
|
||||
),
|
||||
const VSpace(10),
|
||||
_ExportButton(
|
||||
title: LocaleKeys.shareAction_clipboard.tr(),
|
||||
svg: FlowySvgs.duplicate_s,
|
||||
onTap: () => _exportToClipboard(context),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _exportHTML(BuildContext context) async {
|
||||
final viewName = context.read<DocumentShareBloc>().state.viewName;
|
||||
final exportPath = await getIt<FilePickerService>().saveFile(
|
||||
dialogTitle: '',
|
||||
fileName: '${viewName.toFileName()}.html',
|
||||
);
|
||||
if (context.mounted && exportPath != null) {
|
||||
context.read<DocumentShareBloc>().add(
|
||||
DocumentShareEvent.share(
|
||||
DocumentShareType.html,
|
||||
exportPath,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _exportMarkdown(BuildContext context) async {
|
||||
final viewName = context.read<DocumentShareBloc>().state.viewName;
|
||||
final exportPath = await getIt<FilePickerService>().saveFile(
|
||||
dialogTitle: '',
|
||||
fileName: '${viewName.toFileName()}.md',
|
||||
);
|
||||
if (context.mounted && exportPath != null) {
|
||||
context.read<DocumentShareBloc>().add(
|
||||
DocumentShareEvent.share(
|
||||
DocumentShareType.markdown,
|
||||
exportPath,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _exportToClipboard(BuildContext context) async {
|
||||
final documentExporter =
|
||||
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),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ExportButton extends StatelessWidget {
|
||||
const _ExportButton({
|
||||
required this.title,
|
||||
required this.svg,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final FlowySvgData svg;
|
||||
final VoidCallback onTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final radius = BorderRadius.circular(10.0);
|
||||
return FlowyButton(
|
||||
margin: const EdgeInsets.symmetric(vertical: 10, horizontal: 14),
|
||||
iconPadding: 12,
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(
|
||||
color: const Color(0x1E14171B),
|
||||
),
|
||||
borderRadius: radius,
|
||||
),
|
||||
radius: radius,
|
||||
text: FlowyText(title),
|
||||
leftIcon: FlowySvg(svg),
|
||||
onTap: onTap,
|
||||
);
|
||||
}
|
||||
}
|
@ -100,10 +100,6 @@ class _PublishedWidgetState extends State<_PublishedWidget> {
|
||||
controller: controller,
|
||||
onCopy: (url) {
|
||||
AppFlowyClipboard.setData(text: url);
|
||||
showSnackBarMessage(
|
||||
context,
|
||||
LocaleKeys.document_inlineLink_copyLink.tr(),
|
||||
);
|
||||
},
|
||||
onSubmitted: (url) {},
|
||||
),
|
||||
|
@ -1,5 +1,6 @@
|
||||
import 'package:appflowy/generated/locale_keys.g.dart';
|
||||
import 'package:appflowy/mobile/presentation/home/tab/_round_underline_tab_indicator.dart';
|
||||
import 'package:appflowy/plugins/document/presentation/share/export_tab.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@ -112,10 +113,11 @@ class _ShareMenuState extends State<ShareMenu>
|
||||
switch (selectedTab) {
|
||||
case ShareMenuTab.publish:
|
||||
return const PublishTab();
|
||||
|
||||
case ShareMenuTab.exportAs:
|
||||
return const ExportTab();
|
||||
default:
|
||||
return const Center(
|
||||
child: FlowyText('coming soon'),
|
||||
child: FlowyText('🏡 under construction'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
4
frontend/resources/flowy_icons/16x/export_html.svg
Normal file
4
frontend/resources/flowy_icons/16x/export_html.svg
Normal file
@ -0,0 +1,4 @@
|
||||
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M2.73332 1.33337H13.2667C13.6667 1.33337 14 1.66671 13.9333 2.06671L12.7333 12.8667C12.7333 13.1334 12.5333 13.3334 12.2667 13.4667L8.19998 14.6C8.06665 14.6667 7.93332 14.6667 7.86665 14.6L3.79998 13.4667C3.53332 13.4 3.33332 13.2 3.33332 12.8667L2.06665 2.06671C2.06665 1.66671 2.33332 1.33337 2.73332 1.33337Z" stroke="#171717" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M10.8 4.53333H5.19995L5.46662 7.46666H10.5333L10.1333 10.8L7.86662 11.4667L5.46662 10.8V9.46666" stroke="#171717" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
</svg>
|
After (image error) Size: 710 B |
6
frontend/resources/flowy_icons/16x/export_markdown.svg
Normal file
6
frontend/resources/flowy_icons/16x/export_markdown.svg
Normal file
@ -0,0 +1,6 @@
|
||||
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M13.4071 4.26416L10.593 1.45009C10.0304 0.887482 9.26736 0.571411 8.47171 0.571411H3.71436C2.60979 0.571411 1.71436 1.46684 1.71436 2.57141V13.0938C1.71436 14.1984 2.60978 15.0938 3.71435 15.0938H12.2858C13.3904 15.0938 14.2858 14.1984 14.2858 13.0938V6.38548C14.2858 5.58983 13.9697 4.82677 13.4071 4.26416Z" stroke="#171717" stroke-width="0.995556" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M4.19995 12V7.70621C4.19995 7.55289 4.32425 7.42859 4.47757 7.42859C4.58683 7.42859 4.68593 7.49267 4.73075 7.5923L5.59171 9.50585C5.64879 9.63271 5.77497 9.7143 5.91409 9.7143C6.05319 9.7143 6.17936 9.63273 6.23644 9.50588L7.09768 7.59228C7.14252 7.49266 7.24161 7.42859 7.35085 7.42859C7.50419 7.42859 7.6285 7.55289 7.6285 7.70622V12" stroke="#171717" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M10.8572 7.42859V11.9999" stroke="#171717" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M9.5 10.8572L10.8 12.1572L12.1 10.8572" stroke="#171717" stroke-width="0.9" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
</svg>
|
After (image error) Size: 1.1 KiB |
Loading…
x
Reference in New Issue
Block a user