mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: call the publish event
This commit is contained in:
@ -23,30 +23,9 @@ class DocumentShareBloc extends Bloc<DocumentShareEvent, DocumentShareState> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
emit(
|
emit(state.copyWith(isLoading: true));
|
||||||
state.copyWith(isLoading: true),
|
|
||||||
);
|
|
||||||
|
|
||||||
final exporter = DocumentExporter(view);
|
final result = await _export(type, path);
|
||||||
final FlowyResult<ExportDataPB, FlowyError> result =
|
|
||||||
await exporter.export(type.exportType).then((value) {
|
|
||||||
return value.fold(
|
|
||||||
(s) {
|
|
||||||
if (path != null) {
|
|
||||||
switch (type) {
|
|
||||||
case DocumentShareType.markdown:
|
|
||||||
return FlowyResult.success(_saveMarkdownToPath(s, path));
|
|
||||||
case DocumentShareType.html:
|
|
||||||
return FlowyResult.success(_saveHTMLToPath(s, path));
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return FlowyResult.failure(FlowyError());
|
|
||||||
},
|
|
||||||
(f) => FlowyResult.failure(f),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
emit(
|
emit(
|
||||||
state.copyWith(
|
state.copyWith(
|
||||||
@ -55,11 +34,41 @@ class DocumentShareBloc extends Bloc<DocumentShareEvent, DocumentShareState> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
publish: (url) async {
|
||||||
|
emit(state.copyWith(isPublished: true));
|
||||||
|
},
|
||||||
|
unPublish: () async {
|
||||||
|
emit(state.copyWith(isPublished: false));
|
||||||
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
final ViewPB view;
|
final ViewPB view;
|
||||||
|
late final exporter = DocumentExporter(view);
|
||||||
|
|
||||||
|
Future<FlowyResult<ExportDataPB, FlowyError>> _export(
|
||||||
|
DocumentShareType type,
|
||||||
|
String? path,
|
||||||
|
) async {
|
||||||
|
final result = await exporter.export(type.exportType);
|
||||||
|
return result.fold(
|
||||||
|
(s) {
|
||||||
|
if (path != null) {
|
||||||
|
switch (type) {
|
||||||
|
case DocumentShareType.markdown:
|
||||||
|
return FlowySuccess(_saveMarkdownToPath(s, path));
|
||||||
|
case DocumentShareType.html:
|
||||||
|
return FlowySuccess(_saveHTMLToPath(s, path));
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return FlowyResult.failure(FlowyError());
|
||||||
|
},
|
||||||
|
(f) => FlowyResult.failure(f),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
ExportDataPB _saveMarkdownToPath(String markdown, String path) {
|
ExportDataPB _saveMarkdownToPath(String markdown, String path) {
|
||||||
File(path).writeAsStringSync(markdown);
|
File(path).writeAsStringSync(markdown);
|
||||||
@ -103,7 +112,9 @@ class DocumentShareEvent with _$DocumentShareEvent {
|
|||||||
const factory DocumentShareEvent.share(
|
const factory DocumentShareEvent.share(
|
||||||
DocumentShareType type,
|
DocumentShareType type,
|
||||||
String? path,
|
String? path,
|
||||||
) = Share;
|
) = _Share;
|
||||||
|
const factory DocumentShareEvent.publish(String url) = _Publish;
|
||||||
|
const factory DocumentShareEvent.unPublish() = _UnPublish;
|
||||||
}
|
}
|
||||||
|
|
||||||
@freezed
|
@freezed
|
||||||
@ -111,9 +122,12 @@ class DocumentShareState with _$DocumentShareState {
|
|||||||
const factory DocumentShareState({
|
const factory DocumentShareState({
|
||||||
required bool isLoading,
|
required bool isLoading,
|
||||||
FlowyResult<ExportDataPB, FlowyError>? exportResult,
|
FlowyResult<ExportDataPB, FlowyError>? exportResult,
|
||||||
|
required bool isPublished,
|
||||||
|
FlowyResult<void, FlowyError>? publishResult,
|
||||||
}) = _DocumentShareState;
|
}) = _DocumentShareState;
|
||||||
|
|
||||||
factory DocumentShareState.initial() => const DocumentShareState(
|
factory DocumentShareState.initial() => const DocumentShareState(
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
|
isPublished: false,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,31 @@
|
|||||||
import 'package:appflowy/generated/flowy_svgs.g.dart';
|
import 'package:appflowy/generated/flowy_svgs.g.dart';
|
||||||
import 'package:appflowy/generated/locale_keys.g.dart';
|
import 'package:appflowy/generated/locale_keys.g.dart';
|
||||||
|
import 'package:appflowy/plugins/document/application/document_share_bloc.dart';
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
|
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
|
||||||
import 'package:flowy_infra_ui/widget/rounded_button.dart';
|
import 'package:flowy_infra_ui/widget/rounded_button.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
|
||||||
class PublishTab extends StatefulWidget {
|
class PublishTab extends StatelessWidget {
|
||||||
const PublishTab({super.key});
|
const PublishTab({super.key});
|
||||||
|
|
||||||
@override
|
|
||||||
State<PublishTab> createState() => _PublishTabState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _PublishTabState extends State<PublishTab> {
|
|
||||||
bool isPublished = false;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return isPublished
|
return context.watch<DocumentShareBloc>().state.isPublished
|
||||||
? _PublishedWidget(onUnPublish: () {}, onVisitSite: () {})
|
? _PublishedWidget(
|
||||||
: _UnPublishWidget(onPublish: () => setState(() => isPublished = true));
|
onUnPublish: () {
|
||||||
|
context
|
||||||
|
.read<DocumentShareBloc>()
|
||||||
|
.add(const DocumentShareEvent.unPublish());
|
||||||
|
},
|
||||||
|
onVisitSite: () {},
|
||||||
|
)
|
||||||
|
: _UnPublishWidget(
|
||||||
|
onPublish: () => context
|
||||||
|
.read<DocumentShareBloc>()
|
||||||
|
.add(const DocumentShareEvent.publish('')),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,9 @@ class DocumentShareButton extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: BlocBuilder<DocumentShareBloc, DocumentShareState>(
|
child: BlocBuilder<DocumentShareBloc, DocumentShareState>(
|
||||||
builder: (context, state) => SizedBox(
|
builder: (context, state) {
|
||||||
|
final shareBloc = context.read<DocumentShareBloc>();
|
||||||
|
return SizedBox(
|
||||||
height: 32.0,
|
height: 32.0,
|
||||||
child: IntrinsicWidth(
|
child: IntrinsicWidth(
|
||||||
child: AppFlowyPopover(
|
child: AppFlowyPopover(
|
||||||
@ -51,7 +53,10 @@ class DocumentShareButton extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
margin: const EdgeInsets.all(16),
|
margin: const EdgeInsets.all(16),
|
||||||
offset: const Offset(0, 8),
|
offset: const Offset(0, 8),
|
||||||
popupBuilder: (context) => const ShareMenu(),
|
popupBuilder: (context) => BlocProvider.value(
|
||||||
|
value: shareBloc,
|
||||||
|
child: const ShareMenu(),
|
||||||
|
),
|
||||||
child: RoundedTextButton(
|
child: RoundedTextButton(
|
||||||
title: LocaleKeys.shareAction_buttonText.tr(),
|
title: LocaleKeys.shareAction_buttonText.tr(),
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 12.0),
|
padding: const EdgeInsets.symmetric(horizontal: 12.0),
|
||||||
@ -60,7 +65,8 @@ class DocumentShareButton extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -51,10 +51,13 @@ class _ShareMenuState extends State<ShareMenu> {
|
|||||||
return Column(
|
return Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
CustomSlidingSegmentedControl<ShareMenuTab>(
|
SizedBox(
|
||||||
|
height: 34,
|
||||||
|
child: CustomSlidingSegmentedControl<ShareMenuTab>(
|
||||||
initialValue: selectedTab,
|
initialValue: selectedTab,
|
||||||
curve: Curves.linear,
|
curve: Curves.linear,
|
||||||
padding: 0,
|
padding: 0,
|
||||||
|
fixedWidth: 128,
|
||||||
innerPadding: const EdgeInsets.all(3.0),
|
innerPadding: const EdgeInsets.all(3.0),
|
||||||
children: children,
|
children: children,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
@ -78,6 +81,7 @@ class _ShareMenuState extends State<ShareMenu> {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
),
|
||||||
_buildTab(context),
|
_buildTab(context),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
@ -108,13 +112,10 @@ class _Segment extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final textColor = isSelected ? null : Theme.of(context).hintColor;
|
final textColor = isSelected ? null : Theme.of(context).hintColor;
|
||||||
return SizedBox(
|
return FlowyText(
|
||||||
width: 128,
|
|
||||||
child: FlowyText(
|
|
||||||
title,
|
title,
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
color: textColor,
|
color: textColor,
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user