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.

fix: the markdown file name doesn't update after renaming the document (#2777)

Lucas.Xu5bcf48a4f95e
diff --git a/frontend/appflowy_flutter/integration_test/share_markdown_test.dart b/frontend/appflowy_flutter/integration_test/share_markdown_test.dart
index 3fa7d8a2b2..a39575e49b 100644
--- a/frontend/appflowy_flutter/integration_test/share_markdown_test.dart
+++ b/frontend/appflowy_flutter/integration_test/share_markdown_test.dart
@@ -1,5 +1,6 @@
import 'dart:io';
+import 'package:appflowy/plugins/document/presentation/share/share_button.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
@@ -47,6 +48,38 @@ void main() {
final markdown = file.readAsStringSync();
expect(markdown, expectedMarkdown);
});
+
+ testWidgets(
+ 'share the markdown after renaming the document name',
+ (tester) async {
+ await tester.initializeAppFlowy();
+ await tester.tapGoButton();
+
+ // expect to see a readme page
+ tester.expectToSeePageName(readme);
+
+ // rename the document
+ await tester.hoverOnPageName(readme);
+ await tester.renamePage('example');
+
+ final shareButton = find.byType(ShareActionList);
+ final shareButtonState =
+ tester.state(shareButton) as ShareActionListState;
+ final path =
+ await mockSaveFilePath(location, '${shareButtonState.name}.md');
+
+ // click the share button and select markdown
+ await tester.tapShareButton();
+ await tester.tapMarkdownButton();
+
+ // expect to see the success dialog
+ tester.expectToExportSuccess();
+
+ final file = File(path);
+ final isExist = file.existsSync();
+ expect(isExist, true);
+ },
+ );
});
}
diff --git a/frontend/appflowy_flutter/integration_test/util/common_operations.dart b/frontend/appflowy_flutter/integration_test/util/common_operations.dart
index 7114b2f285..585a40cd60 100644
--- a/frontend/appflowy_flutter/integration_test/util/common_operations.dart
+++ b/frontend/appflowy_flutter/integration_test/util/common_operations.dart
@@ -10,6 +10,8 @@ import 'package:appflowy/workspace/presentation/home/menu/app/section/item.dart'
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
+import 'package:flowy_infra_ui/widget/buttons/primary_button.dart';
+import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'base.dart';
@@ -79,6 +81,26 @@ extension CommonOperations on WidgetTester {
await tapButtonWithName(ViewDisclosureAction.delete.name);
}
+ Future<void> tapRenamePageButton() async {
+ await tapPageOptionButton();
+ await tapButtonWithName(ViewDisclosureAction.rename.name);
+ }
+
+ Future<void> renamePage(String name) async {
+ await tapRenamePageButton();
+ await enterText(find.byType(TextFormField), name);
+ await tapOKButton();
+ }
+
+ Future<void> tapOKButton() async {
+ final okButton = find.byWidgetPredicate(
+ (widget) =>
+ widget is PrimaryTextButton &&
+ widget.label == LocaleKeys.button_OK.tr(),
+ );
+ await tapButton(okButton);
+ }
+
void expectToSeeDocumentBanner() {
expect(find.byType(DocumentBanner), findsOneWidget);
}
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 8b3705fb5c..3aba387cbc 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
@@ -2,6 +2,7 @@ import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/plugins/document/application/share_bloc.dart';
import 'package:appflowy/util/file_picker/file_picker_service.dart';
+import 'package:appflowy/workspace/application/view/view_listener.dart';
import 'package:appflowy/workspace/presentation/home/toast.dart';
import 'package:appflowy/workspace/presentation/widgets/pop_up_action.dart';
import 'package:appflowy_backend/protobuf/flowy-document2/entities.pb.dart';
@@ -68,7 +69,7 @@ class DocumentShareButton extends StatelessWidget {
}
}
-class ShareActionList extends StatelessWidget {
+class ShareActionList extends StatefulWidget {
const ShareActionList({
super.key,
required this.view,
@@ -76,6 +77,27 @@ class ShareActionList extends StatelessWidget {
final ViewPB view;
+ @override
+ State<ShareActionList> createState() => ShareActionListState();
+}
+
+@visibleForTesting
+class ShareActionListState extends State<ShareActionList> {
+ late String name;
+ late final ViewListener viewListener = ViewListener(view: widget.view);
+
+ @override
+ void initState() {
+ super.initState();
+ listenOnViewUpdated();
+ }
+
+ @override
+ void dispose() {
+ viewListener.stop();
+ super.dispose();
+ }
+
@override
Widget build(BuildContext context) {
final docShareBloc = context.read<DocShareBloc>();
@@ -96,7 +118,7 @@ class ShareActionList extends StatelessWidget {
case ShareAction.markdown:
final exportPath = await getIt<FilePickerService>().saveFile(
dialogTitle: '',
- fileName: '${view.name}.md',
+ fileName: '$name.md',
);
if (exportPath != null) {
docShareBloc.add(DocShareEvent.shareMarkdown(exportPath));
@@ -107,6 +129,15 @@ class ShareActionList extends StatelessWidget {
},
);
}
+
+ void listenOnViewUpdated() {
+ name = widget.view.name;
+ viewListener.start(
+ onViewUpdated: (view) {
+ name = view.fold((l) => l.name, (r) => '');
+ },
+ );
+ }
}
enum ShareAction {
diff --git a/frontend/appflowy_flutter/lib/startup/tasks/windows.dart b/frontend/appflowy_flutter/lib/startup/tasks/windows.dart
index c01e9412a3..f864eae4e2 100644
--- a/frontend/appflowy_flutter/lib/startup/tasks/windows.dart
+++ b/frontend/appflowy_flutter/lib/startup/tasks/windows.dart
@@ -37,7 +37,7 @@ class InitAppWindowTask extends LaunchTask with WindowListener {
title: title,
);
- await windowManager.waitUntilReadyToShow(windowOptions, () async {
+ windowManager.waitUntilReadyToShow(windowOptions, () async {
await windowManager.show();
await windowManager.focus();
});