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.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
fix: minor improvements to media interactions (#6867)
Mathias Mogensenc910bda5344d
diff --git a/frontend/appflowy_flutter/integration_test/desktop/database/database_row_cover_test.dart b/frontend/appflowy_flutter/integration_test/desktop/database/database_row_cover_test.dartindex 6c96a4825e..8741dcd75f 100644--- a/frontend/appflowy_flutter/integration_test/desktop/database/database_row_cover_test.dart+++ b/frontend/appflowy_flutter/integration_test/desktop/database/database_row_cover_test.dart@@ -4,12 +4,10 @@ import 'package:appflowy/core/config/kv.dart';import 'package:appflowy/core/config/kv_keys.dart';import 'package:appflowy/generated/locale_keys.g.dart';import 'package:appflowy/plugins/database/widgets/card/card.dart';-import 'package:appflowy/plugins/database/widgets/cell_editor/media_cell_editor.dart';import 'package:appflowy/plugins/database/widgets/row/row_banner.dart';import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';import 'package:appflowy/shared/af_image.dart';import 'package:appflowy/startup/startup.dart';-import 'package:appflowy_backend/protobuf/flowy-database2/field_entities.pbenum.dart';import 'package:appflowy_backend/protobuf/flowy-folder/view.pbenum.dart';import 'package:easy_localization/easy_localization.dart';import 'package:flutter/services.dart';@@ -26,61 +24,6 @@ void main() {IntegrationTestWidgetsFlutterBinding.ensureInitialized();group('database row cover', () {- testWidgets('add image to media field and check if cover is set (grid)',- (tester) async {- await tester.initializeAppFlowy();- await tester.tapAnonymousSignInButton();-- await tester.createNewPageWithNameUnderParent(layout: ViewLayoutPB.Grid);-- // Invoke the field editor- await tester.tapGridFieldWithName('Type');- await tester.tapEditFieldButton();-- // Change to media type- await tester.tapSwitchFieldTypeButton();- await tester.selectFieldType(FieldType.Media);- await tester.dismissFieldEditor();-- // Prepare file for upload from local- final image = await rootBundle.load('assets/test/images/sample.jpeg');- final tempDirectory = await getTemporaryDirectory();-- final imagePath = p.join(tempDirectory.path, 'sample.jpeg');- final file = File(imagePath)- ..writeAsBytesSync(image.buffer.asUint8List());-- mockPickFilePaths(paths: [imagePath]);- await getIt<KeyValueStorage>().set(KVKeys.kCloudType, '0');-- // Open media cell editor- await tester.tapCellInGrid(rowIndex: 0, fieldType: FieldType.Media);- await tester.findMediaCellEditor(findsOneWidget);-- // Click on add file button in the Media Cell Editor- await tester.tap(find.text(LocaleKeys.grid_media_addFileOrImage.tr()));- await tester.pumpAndSettle();-- // Tap on the upload interaction- await tester.tapFileUploadHint();-- // Expect one file- expect(find.byType(RenderMedia), findsOneWidget);-- // Close cell editor- await tester.dismissCellEditor();-- // Open first row in row detail view- await tester.openFirstRowDetailPage();- await tester.pumpAndSettle();-- // Expect a cover to be shown- expect(find.byType(RowCover), findsOneWidget);-- // Remove the temp file- await Future.wait([file.delete()]);- });-testWidgets('add and remove cover from Row Detail Card', (tester) async {await tester.initializeAppFlowy();await tester.tapAnonymousSignInButton();diff --git a/frontend/appflowy_flutter/lib/plugins/database/widgets/cell/desktop_row_detail/desktop_row_detail_media_cell.dart b/frontend/appflowy_flutter/lib/plugins/database/widgets/cell/desktop_row_detail/desktop_row_detail_media_cell.dartindex 53fc5d558a..772149fa59 100644--- a/frontend/appflowy_flutter/lib/plugins/database/widgets/cell/desktop_row_detail/desktop_row_detail_media_cell.dart+++ b/frontend/appflowy_flutter/lib/plugins/database/widgets/cell/desktop_row_detail/desktop_row_detail_media_cell.dart@@ -27,6 +27,7 @@ import 'package:flowy_infra_ui/flowy_infra_ui.dart';import 'package:flowy_infra_ui/style_widget/hover.dart';import 'package:flutter/material.dart';import 'package:flutter_bloc/flutter_bloc.dart';+import 'package:open_filex/open_filex.dart';import 'package:reorderables/reorderables.dart';const _dropFileKey = 'files_media';@@ -151,9 +152,10 @@ class DekstopRowDetailMediaCellSkin extends IEditableMediaCellSkin {child: Row(mainAxisSize: MainAxisSize.min,children: [- const FlowySvg(+ FlowySvg(FlowySvgs.add_thin_s,- size: Size.square(12),+ size: const Size.square(12),+ color: Theme.of(context).hintColor,),const HSpace(6),FlowyText.medium(@@ -219,7 +221,9 @@ class _FilePreviewFeedback extends StatelessWidget {}}-class _AddFileButton extends StatelessWidget {+const _menuWidth = 350.0;++class _AddFileButton extends StatefulWidget {const _AddFileButton({this.mutex,required this.controller,@@ -232,15 +236,22 @@ class _AddFileButton extends StatelessWidget {final PopoverDirection direction;final Widget child;+ @override+ State<_AddFileButton> createState() => _AddFileButtonState();+}++class _AddFileButtonState extends State<_AddFileButton> {+ Offset? position;+@overrideWidget build(BuildContext context) {return AppFlowyPopover(triggerActions: PopoverTriggerFlags.none,- controller: controller,- mutex: mutex,+ controller: widget.controller,+ mutex: widget.mutex,offset: const Offset(0, 10),- direction: direction,- constraints: const BoxConstraints(maxWidth: 350),+ direction: widget.direction,+ constraints: const BoxConstraints(maxWidth: _menuWidth),margin: EdgeInsets.zero,onClose: () =>context.read<EditorDropManagerState>().remove(_dropFileKey),@@ -273,7 +284,7 @@ class _AddFileButton extends StatelessWidget {),);- controller.close();+ widget.controller.close();},),onInsertNetworkFile: (url) {@@ -306,14 +317,25 @@ class _AddFileButton extends StatelessWidget {),);- controller.close();+ widget.controller.close();},);},- child: GestureDetector(- onTap: controller.show,- behavior: HitTestBehavior.translucent,- child: FlowyHover(resetHoverOnRebuild: false, child: child),+ child: MouseRegion(+ onEnter: (event) => position = event.position,+ onExit: (_) => position = null,+ onHover: (event) => position = event.position,+ child: GestureDetector(+ onTap: () {+ if (position != null) {+ widget.controller.showAt(+ position! - const Offset(_menuWidth / 2, 0),+ );+ }+ },+ behavior: HitTestBehavior.translucent,+ child: FlowyHover(resetHoverOnRebuild: false, child: widget.child),+ ),),);}@@ -456,6 +478,11 @@ class _FilePreviewRenderState extends State<_FilePreviewRender> {onTap: widget.foregroundText != null? null: () {+ if (file.uploadType == FileUploadTypePB.LocalFile) {+ OpenFilex.open(file.url);+ return;+ }+if (file.fileType != MediaFileTypePB.Image) {afLaunchUrlString(widget.file.url);return;diff --git a/frontend/rust-lib/flowy-database2/src/event_handler.rs b/frontend/rust-lib/flowy-database2/src/event_handler.rsindex d641cb234a..c071fe2314 100644--- a/frontend/rust-lib/flowy-database2/src/event_handler.rs+++ b/frontend/rust-lib/flowy-database2/src/event_handler.rs@@ -1,5 +1,5 @@use collab_database::fields::media_type_option::MediaCellData;-use collab_database::rows::{Cell, CoverType, RowCover, RowId};+use collab_database::rows::{Cell, RowCover, RowId};use lib_infra::box_any::BoxAny;use std::sync::{Arc, Weak};use tokio::sync::oneshot;@@ -1320,34 +1320,6 @@ pub(crate) async fn update_media_cell_handler().await?;- let image_file = params- .inserted_files- .iter()- .find(|file| file.file_type == MediaFileTypePB::Image);- let row_meta = database_editor- .get_row_meta(&cell_id.view_id, &cell_id.row_id)- .await;-- if let (Some(row_meta), Some(file)) = (row_meta, image_file) {- let row_meta = row_meta.clone();- if row_meta.cover.is_none() {- let update_row_meta = UpdateRowMetaParams {- id: cell_id.row_id.clone().into(),- view_id: cell_id.view_id.clone(),- cover: Some(RowCover {- data: file.url.clone(),- upload_type: file.upload_type.into(),- cover_type: CoverType::FileCover,- }),- ..UpdateRowMetaParams::default()- };-- database_editor- .update_row_meta(&cell_id.row_id, update_row_meta)- .await;- }- }-Ok(())}