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: drop files duplicates (#7620)

Mathias Mogensenb4fbfaf2f835
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_drop_handler.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_drop_handler.dart
index 62810545dd..4c689a1a7b 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_drop_handler.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_drop_handler.dart
@@ -109,6 +109,10 @@ class EditorDropHandler extends StatelessWidget {
void _onDragUpdated(Offset position) {
final data = editorState.selectionService.getDropTargetRenderData(position);
+ if (dropManagerState?.isDropEnabled == false) {
+ return editorState.selectionService.removeDropTarget();
+ }
+
if (data != null &&
data.dropPath != null &&
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_drop_manager.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_drop_manager.dart
index 8b59809f3b..23fc58777f 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_drop_manager.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_drop_manager.dart
@@ -14,6 +14,8 @@ class EditorDropManagerState extends ChangeNotifier {
}
bool get isDropEnabled => _draggedTypes.isEmpty;
+
+ bool contains(String type) => _draggedTypes.contains(type);
}
final enableDocumentDragNotifier = ValueNotifier(true);
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/file/file_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/file/file_block_component.dart
index fe50224caa..e25863652c 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/file/file_block_component.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/file/file_block_component.dart
@@ -157,6 +157,8 @@ class FileBlockComponent extends BlockComponentStatefulWidget {
super.configuration = const BlockComponentConfiguration(),
});
+ static const uploadDragKey = 'FileUploadMenu';
+
@override
State<FileBlockComponent> createState() => FileBlockComponentState();
}
@@ -253,20 +255,23 @@ class FileBlockComponentState extends State<FileBlockComponent>
if (UniversalPlatform.isDesktopOrWeb) {
if (url == null || url.isEmpty) {
child = DropTarget(
+ enable: dropManagerState?.isDropEnabled == true ||
+ dropManagerState?.contains(FileBlockKeys.type) == true,
onDragEntered: (_) {
if (dropManagerState?.isDropEnabled == true) {
+ dropManagerState?.add(FileBlockKeys.type);
setState(() => isDragging = true);
}
},
onDragExited: (_) {
- if (dropManagerState?.isDropEnabled == true) {
+ if (dropManagerState?.contains(FileBlockKeys.type) == true) {
+ dropManagerState?.remove(FileBlockKeys.type);
setState(() => isDragging = false);
}
},
onDragDone: (details) {
- if (dropManagerState?.isDropEnabled == true) {
- insertFileFromLocal(details.files);
- }
+ dropManagerState?.remove(FileBlockKeys.type);
+ insertFileFromLocal(details.files);
},
child: AppFlowyPopover(
controller: controller,
@@ -277,8 +282,12 @@ class FileBlockComponentState extends State<FileBlockComponent>
minHeight: 80,
),
clickHandler: PopoverClickHandler.gestureDetector,
- onOpen: () => dropManagerState?.add(FileBlockKeys.type),
- onClose: () => dropManagerState?.remove(FileBlockKeys.type),
+ onOpen: () => dropManagerState?.add(
+ FileBlockComponent.uploadDragKey,
+ ),
+ onClose: () => dropManagerState?.remove(
+ FileBlockComponent.uploadDragKey,
+ ),
popupBuilder: (_) => FileUploadMenu(
onInsertLocalFile: insertFileFromLocal,
onInsertNetworkFile: insertNetworkFile,
@@ -345,7 +354,7 @@ class FileBlockComponentState extends State<FileBlockComponent>
void _openMenu() {
if (UniversalPlatform.isDesktopOrWeb) {
controller.show();
- dropManagerState?.add(FileBlockKeys.type);
+ dropManagerState?.add(FileBlockComponent.uploadDragKey);
} else {
editorState.updateSelectionWithReason(null, extraInfo: {});
showUploadFileMobileMenu();
@@ -574,7 +583,7 @@ class FileBlockComponentState extends State<FileBlockComponent>
Rect getBlockRect({bool shiftWithBaseOffset = false}) {
final renderBox = fileKey.currentContext?.findRenderObject();
if (renderBox is RenderBox) {
- return Offset.zero & renderBox.size;
+ return padding.topLeft & renderBox.size;
}
return Rect.zero;
}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/image_placeholder.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/image_placeholder.dart
index df975de731..bfe5062c0c 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/image_placeholder.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/image_placeholder.dart
@@ -1,5 +1,6 @@
import 'dart:io';
+import 'package:appflowy/plugins/document/presentation/editor_drop_manager.dart';
import 'package:flutter/material.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
@@ -44,11 +45,27 @@ class ImagePlaceholderState extends State<ImagePlaceholder> {
final documentService = DocumentService();
late final editorState = context.read<EditorState>();
+ late EditorDropManagerState? dropManagerState = UniversalPlatform.isMobile
+ ? null
+ : context.read<EditorDropManagerState?>();
+
+ bool get isDragEnabled =>
+ dropManagerState?.isDropEnabled == true ||
+ dropManagerState?.contains(CustomImageBlockKeys.type) == true;
+
bool showLoading = false;
String? errorMessage;
bool isDraggingFiles = false;
+ @override
+ void didChangeDependencies() {
+ if (UniversalPlatform.isMobile) {
+ dropManagerState = context.read<EditorDropManagerState>();
+ }
+ super.didChangeDependencies();
+ }
+
@override
Widget build(BuildContext context) {
final Widget child = DecoratedBox(
@@ -131,8 +148,15 @@ class ImagePlaceholderState extends State<ImagePlaceholder> {
);
},
child: DropTarget(
- onDragEntered: (_) => setState(() => isDraggingFiles = true),
- onDragExited: (_) => setState(() => isDraggingFiles = false),
+ enable: isDragEnabled,
+ onDragEntered: (_) {
+ if (isDragEnabled) {
+ setState(() => isDraggingFiles = true);
+ }
+ },
+ onDragExited: (_) {
+ setState(() => isDraggingFiles = false);
+ },
onDragDone: (details) {
// Only accept files where the mimetype is an image,
// otherwise we assume it's a file we cannot display.