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.

feat: cover in database row (#6238)

Mathias Mogensen12c575dbbe5d
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.dart
new file mode 100644
index 0000000000..4600ea37fc
--- /dev/null
+++ b/frontend/appflowy_flutter/integration_test/desktop/database/database_row_cover_test.dart
@@ -0,0 +1,188 @@
+import 'dart:io';
+
+import 'package:flutter/services.dart';
+
+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/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_test/flutter_test.dart';
+import 'package:integration_test/integration_test.dart';
+import 'package:path/path.dart' as p;
+import 'package:path_provider/path_provider.dart';
+
+import '../../shared/database_test_op.dart';
+import '../../shared/mock/mock_file_picker.dart';
+import '../../shared/util.dart';
+
+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.tapButtonWithName(
+ LocaleKeys.document_plugins_file_fileUploadHint.tr(),
+ );
+
+ // 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(BannerCover), findsOneWidget);
+
+ // Remove the temp file
+ await Future.wait([file.delete()]);
+ });
+
+ testWidgets('upload and remove cover from Row Detail Card', (tester) async {
+ await tester.initializeAppFlowy();
+ await tester.tapAnonymousSignInButton();
+
+ await tester.createNewPageWithNameUnderParent(layout: ViewLayoutPB.Grid);
+
+ // Open first row in row detail view
+ await tester.openFirstRowDetailPage();
+ await tester.pumpAndSettle();
+
+ // Expect no cover (BannerCover is always in the Widget tree - thus check AFImage)
+ expect(find.byType(AFImage), findsNothing);
+
+ // Hover on RowBanner to show Add Cover button
+ await tester.hoverRowBanner();
+
+ // Click on Add Cover button
+ await tester.tapAddCoverButton();
+
+ // Prepare image 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');
+
+ // Tap on the upload image button
+ await tester.tapButtonWithName(
+ LocaleKeys.document_imageBlock_upload_placeholder.tr(),
+ );
+ await tester.pumpAndSettle();
+
+ // Expect a cover to be shown
+ expect(find.byType(AFImage), findsOneWidget);
+
+ // Tap on the delete cover button
+ await tester.tapButtonWithName(
+ LocaleKeys.document_plugins_cover_removeCover.tr(),
+ );
+ await tester.pumpAndSettle();
+
+ // Expect no cover to be shown
+ expect(find.byType(AFImage), findsNothing);
+
+ // Remove the temp file
+ await Future.wait([file.delete()]);
+ });
+
+ testWidgets('upload cover and check in Board', (tester) async {
+ await tester.initializeAppFlowy();
+ await tester.tapAnonymousSignInButton();
+
+ await tester.createNewPageWithNameUnderParent(layout: ViewLayoutPB.Board);
+
+ // Open "Card 1"
+ await tester.tap(find.text('Card 1'));
+ await tester.pumpAndSettle();
+
+ // Expect no cover (BannerCover is always in the Widget tree - thus check AFImage)
+ expect(find.byType(AFImage), findsNothing);
+
+ // Hover on RowBanner to show Add Cover button
+ await tester.hoverRowBanner();
+
+ // Click on Add Cover button
+ await tester.tapAddCoverButton();
+
+ // Prepare image 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');
+
+ // Tap on the upload image button
+ await tester.tapButtonWithName(
+ LocaleKeys.document_imageBlock_upload_placeholder.tr(),
+ );
+ await tester.pumpAndSettle();
+
+ // Dismiss Row Detail Page
+ await tester.dismissRowDetailPage();
+
+ // Expect a cover to be shown in CardCover
+ expect(
+ find.descendant(
+ of: find.byType(CardCover),
+ matching: find.byType(AFImage),
+ ),
+ findsOneWidget,
+ );
+
+ // Remove the temp file
+ await Future.wait([file.delete()]);
+ });
+ });
+}
diff --git a/frontend/appflowy_flutter/integration_test/desktop_runner_2.dart b/frontend/appflowy_flutter/integration_test/desktop_runner_2.dart
index 9053da8d18..56c9cfa53d 100644
--- a/frontend/appflowy_flutter/integration_test/desktop_runner_2.dart
+++ b/frontend/appflowy_flutter/integration_test/desktop_runner_2.dart
@@ -6,6 +6,7 @@ import 'desktop/database/database_field_settings_test.dart'
as database_field_settings_test;
import 'desktop/database/database_field_test.dart' as database_field_test;
import 'desktop/database/database_filter_test.dart' as database_filter_test;
+import 'desktop/database/database_media_test.dart' as database_media_test;
import 'desktop/database/database_row_page_test.dart' as database_row_page_test;
import 'desktop/database/database_row_test.dart' as database_row_test;
import 'desktop/database/database_setting_test.dart' as database_setting_test;
@@ -35,6 +36,7 @@ Future<void> runIntegration2OnDesktop() async {
database_sort_test.main();
database_view_test.main();
database_calendar_test.main();
+ database_media_test.main();
// DON'T add more tests here. This is the second test runner for desktop.
}
diff --git a/frontend/appflowy_flutter/integration_test/desktop_runner_3.dart b/frontend/appflowy_flutter/integration_test/desktop_runner_3.dart
index f1025b8f1e..284f6d4245 100644
--- a/frontend/appflowy_flutter/integration_test/desktop_runner_3.dart
+++ b/frontend/appflowy_flutter/integration_test/desktop_runner_3.dart
@@ -1,6 +1,8 @@
import 'package:integration_test/integration_test.dart';
import 'desktop/board/board_test_runner.dart' as board_test_runner;
+import 'desktop/database/database_row_cover_test.dart'
+ as database_row_cover_test;
import 'desktop/settings/settings_runner.dart' as settings_test_runner;
import 'desktop/sidebar/sidebar_test_runner.dart' as sidebar_test_runner;
import 'desktop/uncategorized/emoji_shortcut_test.dart' as emoji_shortcut_test;
@@ -30,4 +32,5 @@ Future<void> runIntegration3OnDesktop() async {
sidebar_test_runner.main();
board_test_runner.main();
tabs_test.main();
+ database_row_cover_test.main();
}
diff --git a/frontend/appflowy_flutter/integration_test/shared/database_test_op.dart b/frontend/appflowy_flutter/integration_test/shared/database_test_op.dart
index 876de18eb7..04058a0c80 100644
--- a/frontend/appflowy_flutter/integration_test/shared/database_test_op.dart
+++ b/frontend/appflowy_flutter/integration_test/shared/database_test_op.dart
@@ -70,6 +70,7 @@ import 'package:appflowy/plugins/database/widgets/setting/database_setting_actio
import 'package:appflowy/plugins/database/widgets/setting/database_settings_list.dart';
import 'package:appflowy/plugins/database/widgets/setting/setting_button.dart';
import 'package:appflowy/plugins/database/widgets/setting/setting_property_list.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/image/upload_image_menu/upload_image_menu.dart';
import 'package:appflowy/util/field_type_extension.dart';
import 'package:appflowy/workspace/presentation/widgets/date_picker/widgets/clear_date_button.dart';
import 'package:appflowy/workspace/presentation/widgets/date_picker/widgets/date_type_option_button.dart';
@@ -571,6 +572,18 @@ extension AppFlowyDatabaseTest on WidgetTester {
await pumpAndSettle();
}
+ /// Used to open the add cover popover, by pressing on "Add cover"-button.
+ ///
+ /// Should call [hoverRowBanner] first.
+ ///
+ Future<void> tapAddCoverButton() async {
+ await tapButtonWithName(
+ LocaleKeys.document_plugins_cover_addCover.tr(),
+ );
+ await pumpAndSettle();
+ expect(find.byType(UploadImageMenu), findsOneWidget);
+ }
+
Future<void> openEmojiPicker() async =>
tapButton(find.byType(AddEmojiButton));
diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/database/card/card_detail/mobile_card_detail_screen.dart b/frontend/appflowy_flutter/lib/mobile/presentation/database/card/card_detail/mobile_card_detail_screen.dart
index 4b080e540d..a3ce4ceb3f 100644
--- a/frontend/appflowy_flutter/lib/mobile/presentation/database/card/card_detail/mobile_card_detail_screen.dart
+++ b/frontend/appflowy_flutter/lib/mobile/presentation/database/card/card_detail/mobile_card_detail_screen.dart
@@ -21,6 +21,10 @@ import 'package:appflowy/plugins/database/widgets/cell/editable_cell_builder.dar
import 'package:appflowy/plugins/database/widgets/cell/editable_cell_skeleton/text.dart';
import 'package:appflowy/plugins/database/widgets/row/cells/cell_container.dart';
import 'package:appflowy/plugins/database/widgets/row/row_property.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/file/file_upload_menu.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/file/file_util.dart';
+import 'package:appflowy/shared/af_image.dart';
+import 'package:appflowy_backend/protobuf/flowy-database2/file_entities.pbenum.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/row_entities.pb.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/theme_extension.dart';
@@ -146,6 +150,57 @@ class _MobileRowDetailPageState extends State<MobileRowDetailPage> {
text: LocaleKeys.button_duplicate.tr(),
),
const Divider(height: 8.5, thickness: 0.5),
+ MobileQuickActionButton(
+ onTap: () => showMobileBottomSheet(
+ context,
+ title: LocaleKeys.grid_media_addFileMobile.tr(),
+ showHeader: true,
+ showCloseButton: true,
+ showDragHandle: true,
+ builder: (dialogContext) => Container(
+ margin: const EdgeInsets.only(top: 12),
+ constraints: const BoxConstraints(
+ maxHeight: 340,
+ minHeight: 80,
+ ),
+ child: FileUploadMenu(
+ onInsertLocalFile: (files) async {
+ context
+ ..pop()
+ ..pop();
+
+ if (_bloc.state.currentRowId == null) {
+ return;
+ }
+
+ await insertLocalFiles(
+ context,
+ files,
+ userProfile: _bloc.userProfile,
+ documentId: _bloc.state.currentRowId!,
+ onUploadSuccess: (file, path, isLocalMode) {
+ _bloc.add(
+ MobileRowDetailEvent.addCover(
+ RowCoverPB(
+ url: path,
+ uploadType: isLocalMode
+ ? FileUploadTypePB.LocalFile
+ : FileUploadTypePB.CloudFile,
+ ),
+ ),
+ );
+ },
+ );
+ },
+ onInsertNetworkFile: (url) async =>
+ _onInsertNetworkFile(url, context),
+ ),
+ ),
+ ),
+ icon: FlowySvgs.add_cover_s,
+ text: 'Add cover',
+ ),
+ const Divider(height: 8.5, thickness: 0.5),
MobileQuickActionButton(
onTap: () => _performAction(viewId, _bloc.state.currentRowId, true),
text: LocaleKeys.button_delete.tr(),
@@ -178,6 +233,37 @@ class _MobileRowDetailPageState extends State<MobileRowDetailPage> {
gravity: ToastGravity.BOTTOM,
);
}
+
+ Future<void> _onInsertNetworkFile(
+ String url,
+ BuildContext context,
+ ) async {
+ context
+ ..pop()
+ ..pop();
+
+ if (url.isEmpty) return;
+ final uri = Uri.tryParse(url);
+ if (uri == null) {
+ return;
+ }
+
+ String name = uri.pathSegments.isNotEmpty ? uri.pathSegments.last : "";
+ if (name.isEmpty && uri.pathSegments.length > 1) {
+ name = uri.pathSegments[uri.pathSegments.length - 2];
+ } else if (name.isEmpty) {
+ name = uri.host;
+ }
+
+ _bloc.add(
+ MobileRowDetailEvent.addCover(
+ RowCoverPB(
+ url: url,
+ uploadType: FileUploadTypePB.NetworkFile,
+ ),
+ ),
+ );
+ }
}
class RowDetailFab extends StatelessWidget {
@@ -322,91 +408,129 @@ class MobileRowDetailPageContentState
rowController: rowController,
),
child: BlocBuilder<RowDetailBloc, RowDetailState>(
- builder: (context, rowDetailState) {
- return Column(
- children: [
- BlocProvider<RowBannerBloc>(
- create: (context) => RowBannerBloc(
- viewId: viewId,
- fieldController: fieldController,
- rowMeta: rowController.rowMeta,
- )..add(const RowBannerEvent.initial()),
- child: BlocConsumer<RowBannerBloc, RowBannerState>(
- listener: (context, state) {
- if (state.primaryField == null) {
- return;
- }
- primaryFieldId.value = state.primaryField!.id;
- },
- builder: (context, state) {
- if (state.primaryField == null) {
- return const SizedBox.shrink();
- }
-
- return Padding(
- padding: const EdgeInsets.symmetric(horizontal: 16),
- child: cellBuilder.buildCustom(
- CellContext(
- rowId: rowController.rowId,
- fieldId: state.primaryField!.id,
- ),
- skinMap: EditableCellSkinMap(
- textSkin: _TitleSkin(),
- ),
+ builder: (context, rowDetailState) => Column(
+ children: [
+ if (rowDetailState.rowMeta.cover.url.isNotEmpty) ...[
+ GestureDetector(
+ onTap: () => showMobileBottomSheet(
+ context,
+ backgroundColor: AFThemeExtension.of(context).background,
+ showDragHandle: true,
+ builder: (_) => Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ MobileQuickActionButton(
+ onTap: () {
+ context
+ ..pop()
+ ..read<RowDetailBloc>()
+ .add(const RowDetailEvent.removeCover());
+ },
+ text: LocaleKeys.button_delete.tr(),
+ textColor: Theme.of(context).colorScheme.error,
+ icon: FlowySvgs.trash_s,
+ iconColor: Theme.of(context).colorScheme.error,
),
- );
- },
+ ],
+ ),
+ ),
+ child: SizedBox(
+ height: 200,
+ width: double.infinity,
+ child: Container(
+ clipBehavior: Clip.antiAlias,
+ decoration: BoxDecoration(
+ color: Theme.of(context).colorScheme.surface,
+ ),
+ child: AFImage(
+ url: rowDetailState.rowMeta.cover.url,
+ uploadType: widget.rowMeta.cover.uploadType,
+ userProfile:
+ context.read<MobileRowDetailBloc>().userProfile,
+ ),
+ ),
),
),
- Expanded(
- child: ListView(
- padding: const EdgeInsets.only(top: 9, bottom: 100),
- children: [
- Padding(
- padding: const EdgeInsets.symmetric(horizontal: 16),
- child: MobileRowPropertyList(
- databaseController: widget.databaseController,
- cellBuilder: cellBuilder,
+ ],
+ BlocProvider<RowBannerBloc>(
+ create: (context) => RowBannerBloc(
+ viewId: viewId,
+ fieldController: fieldController,
+ rowMeta: rowController.rowMeta,
+ )..add(const RowBannerEvent.initial()),
+ child: BlocConsumer<RowBannerBloc, RowBannerState>(
+ listener: (context, state) {
+ if (state.primaryField == null) {
+ return;
+ }
+ primaryFieldId.value = state.primaryField!.id;
+ },
+ builder: (context, state) {
+ if (state.primaryField == null) {
+ return const SizedBox.shrink();
+ }
+
+ return Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16),
+ child: cellBuilder.buildCustom(
+ CellContext(
+ rowId: rowController.rowId,
+ fieldId: state.primaryField!.id,
),
+ skinMap: EditableCellSkinMap(textSkin: _TitleSkin()),
),
- Padding(
- padding: const EdgeInsets.fromLTRB(6, 6, 16, 0),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- if (rowDetailState.numHiddenFields != 0) ...[
- const ToggleHiddenFieldsVisibilityButton(),
- ],
- const VSpace(8.0),
- ValueListenableBuilder(
- valueListenable: primaryFieldId,
- builder: (context, primaryFieldId, child) {
- if (primaryFieldId.isEmpty) {
- return const SizedBox.shrink();
- }
- return OpenRowPageButton(
- databaseController: widget.databaseController,
- cellContext: CellContext(
- rowId: rowController.rowId,
- fieldId: primaryFieldId,
- ),
- documentId: rowController.rowMeta.documentId,
- );
- },
- ),
- MobileRowDetailCreateFieldButton(
- viewId: viewId,
- fieldController: fieldController,
- ),
+ );
+ },
+ ),
+ ),
+ Expanded(
+ child: ListView(
+ padding: const EdgeInsets.only(top: 9, bottom: 100),
+ children: [
+ Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16),
+ child: MobileRowPropertyList(
+ databaseController: widget.databaseController,
+ cellBuilder: cellBuilder,
+ ),
+ ),
+ Padding(
+ padding: const EdgeInsets.fromLTRB(6, 6, 16, 0),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ if (rowDetailState.numHiddenFields != 0) ...[
+ const ToggleHiddenFieldsVisibilityButton(),
],
- ),
+ const VSpace(8.0),
+ ValueListenableBuilder(
+ valueListenable: primaryFieldId,
+ builder: (context, primaryFieldId, child) {
+ if (primaryFieldId.isEmpty) {
+ return const SizedBox.shrink();
+ }
+ return OpenRowPageButton(
+ databaseController: widget.databaseController,
+ cellContext: CellContext(
+ rowId: rowController.rowId,
+ fieldId: primaryFieldId,
+ ),
+ documentId: rowController.rowMeta.documentId,
+ );
+ },
+ ),
+ MobileRowDetailCreateFieldButton(
+ viewId: viewId,
+ fieldController: fieldController,
+ ),
+ ],
),
- ],
- ),
+ ),
+ ],
),
- ],
- );
- },
+ ),
+ ],
+ ),
),
);
}
diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/database/card/mobile_card_content.dart b/frontend/appflowy_flutter/lib/mobile/presentation/database/card/mobile_card_content.dart
index 2697841005..935533e5f6 100644
--- a/frontend/appflowy_flutter/lib/mobile/presentation/database/card/mobile_card_content.dart
+++ b/frontend/appflowy_flutter/lib/mobile/presentation/database/card/mobile_card_content.dart
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
+import 'package:appflowy/plugins/database/board/application/board_bloc.dart';
import 'package:appflowy/plugins/database/widgets/card/card.dart';
import 'package:appflowy/plugins/database/widgets/card/card_bloc.dart';
import 'package:appflowy/plugins/database/widgets/cell/card_cell_builder.dart';
@@ -11,6 +12,7 @@ import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/theme_extension.dart';
import 'package:flowy_infra_ui/style_widget/text.dart';
import 'package:flowy_infra_ui/widget/spacing.dart';
+import 'package:flutter_bloc/flutter_bloc.dart';
class MobileCardContent extends StatelessWidget {
const MobileCardContent({
@@ -30,46 +32,57 @@ class MobileCardContent extends StatelessWidget {
Widget build(BuildContext context) {
final attachmentCount = rowMeta.attachmentCount.toInt();
- return Padding(
- padding: styleConfiguration.cardPadding,
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- ...cells.map(
- (cellMeta) {
- return cellBuilder.build(
- cellContext: cellMeta.cellContext(),
- styleMap: mobileBoardCardCellStyleMap(context),
- hasNotes: !rowMeta.isDocumentEmpty,
- );
- },
+ return Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ if (rowMeta.cover.url.isNotEmpty) ...[
+ CardCover(
+ cover: rowMeta.cover,
+ userProfile: context.read<BoardBloc>().userProfile,
),
- if (attachmentCount > 0) ...[
- const VSpace(4),
- Padding(
- padding: const EdgeInsets.only(left: 8),
- child: Row(
- children: [
- const FlowySvg(
- FlowySvgs.media_s,
- size: Size.square(12),
- ),
- const HSpace(6),
- Flexible(
- child: FlowyText.regular(
- LocaleKeys.grid_media_attachmentsHint
- .tr(args: ['$attachmentCount']),
- fontSize: 12,
- color: AFThemeExtension.of(context).secondaryTextColor,
- overflow: TextOverflow.ellipsis,
- ),
- ),
- ],
- ),
- ),
- ],
],
- ),
+ Padding(
+ padding: styleConfiguration.cardPadding,
+ child: Column(
+ children: [
+ ...cells.map(
+ (cellMeta) {
+ return cellBuilder.build(
+ cellContext: cellMeta.cellContext(),
+ styleMap: mobileBoardCardCellStyleMap(context),
+ hasNotes: !rowMeta.isDocumentEmpty,
+ );
+ },
+ ),
+ if (attachmentCount > 0) ...[
+ const VSpace(4),
+ Padding(
+ padding: const EdgeInsets.only(left: 8),
+ child: Row(
+ children: [
+ const FlowySvg(
+ FlowySvgs.media_s,
+ size: Size.square(12),
+ ),
+ const HSpace(6),
+ Flexible(
+ child: FlowyText.regular(
+ LocaleKeys.grid_media_attachmentsHint
+ .tr(args: ['$attachmentCount']),
+ fontSize: 12,
+ color:
+ AFThemeExtension.of(context).secondaryTextColor,
+ overflow: TextOverflow.ellipsis,
+ ),
+ ),
+ ],
+ ),
+ ),
+ ],
+ ],
+ ),
+ ),
+ ],
);
}
}
diff --git a/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/media_cell_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/media_cell_bloc.dart
index 5b260784a9..9874646e32 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/media_cell_bloc.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/application/cell/bloc/media_cell_bloc.dart
@@ -7,6 +7,7 @@ import 'package:appflowy/user/application/user_service.dart';
import 'package:appflowy_backend/dispatch/dispatch.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/cell_entities.pb.dart';
+import 'package:appflowy_backend/protobuf/flowy-database2/file_entities.pbenum.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/media_entities.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pb.dart';
import 'package:flowy_infra/uuid.dart';
@@ -194,7 +195,7 @@ class MediaCellEvent with _$MediaCellEvent {
const factory MediaCellEvent.addFile({
required String url,
required String name,
- required MediaUploadTypePB uploadType,
+ required FileUploadTypePB uploadType,
required MediaFileTypePB fileType,
}) = _AddFile;
diff --git a/frontend/appflowy_flutter/lib/plugins/database/application/row/row_banner_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database/application/row/row_banner_bloc.dart
index 1f05352dc5..3169403d4a 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/application/row/row_banner_bloc.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/application/row/row_banner_bloc.dart
@@ -1,8 +1,13 @@
+import 'package:flutter/foundation.dart';
+
import 'package:appflowy/plugins/database/application/field/field_controller.dart';
-import 'package:appflowy/plugins/database/domain/field_service.dart';
import 'package:appflowy/plugins/database/application/row/row_service.dart';
+import 'package:appflowy/plugins/database/domain/field_service.dart';
+import 'package:appflowy_backend/dispatch/dispatch.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/protobuf.dart';
+import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pb.dart';
+import 'package:equatable/equatable.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
@@ -26,6 +31,11 @@ class RowBannerBloc extends Bloc<RowBannerEvent, RowBannerState> {
final RowBackendService _rowBackendSvc;
final RowMetaListener _metaListener;
+ UserProfilePB? _userProfile;
+ UserProfilePB? get userProfile => _userProfile;
+
+ bool get hasCover => state.rowMeta.cover.url.isNotEmpty;
+
@override
Future<void> close() async {
await _metaListener.stop();
@@ -36,15 +46,21 @@ class RowBannerBloc extends Bloc<RowBannerEvent, RowBannerState> {
on<RowBannerEvent>(
(event, emit) {
event.when(
- initial: () {
- _loadPrimaryField();
+ initial: () async {
+ await _loadPrimaryField();
_listenRowMetaChanged();
+ final result = await UserEventGetUserProfile().send();
+ result.fold(
+ (userProfile) => _userProfile = userProfile,
+ (error) => Log.error(error),
+ );
},
didReceiveRowMeta: (RowMetaPB rowMeta) {
emit(state.copyWith(rowMeta: rowMeta));
},
- setCover: (String coverURL) => _updateMeta(coverURL: coverURL),
+ setCover: (RowCoverPB cover) => _updateMeta(cover: cover),
setIcon: (String iconURL) => _updateMeta(iconURL: iconURL),
+ removeCover: () => _removeCover(),
didReceiveFieldUpdate: (updatedField) {
emit(
state.copyWith(
@@ -91,14 +107,19 @@ class RowBannerBloc extends Bloc<RowBannerEvent, RowBannerState> {
}
/// Update the meta of the row and the view
- Future<void> _updateMeta({String? iconURL, String? coverURL}) async {
+ Future<void> _updateMeta({String? iconURL, RowCoverPB? cover}) async {
final result = await _rowBackendSvc.updateMeta(
iconURL: iconURL,
- coverURL: coverURL,
+ cover: cover,
rowId: state.rowMeta.id,
);
result.fold((l) => null, (err) => Log.error(err));
}
+
+ Future<void> _removeCover() async {
+ final result = await _rowBackendSvc.removeCover(state.rowMeta.id);
+ result.fold((l) => null, (err) => Log.error(err));
+ }
}
@freezed
@@ -109,11 +130,14 @@ class RowBannerEvent with _$RowBannerEvent {
const factory RowBannerEvent.didReceiveFieldUpdate(FieldPB field) =
_DidReceiveFieldUpdate;
const factory RowBannerEvent.setIcon(String iconURL) = _SetIcon;
- const factory RowBannerEvent.setCover(String coverURL) = _SetCover;
+ const factory RowBannerEvent.setCover(RowCoverPB cover) = _SetCover;
+ const factory RowBannerEvent.removeCover() = _RemoveCover;
}
@freezed
-class RowBannerState with _$RowBannerState {
+class RowBannerState extends Equatable with _$RowBannerState {
+ const RowBannerState._();
+
const factory RowBannerState({
required FieldPB? primaryField,
required RowMetaPB rowMeta,
@@ -125,6 +149,14 @@ class RowBannerState with _$RowBannerState {
rowMeta: rowMetaPB,
loadingState: const LoadingState.loading(),
);
+
+ @override
+ List<Object?> get props => [
+ rowMeta.cover.url,
+ rowMeta.icon,
+ primaryField,
+ loadingState,
+ ];
}
@freezed
diff --git a/frontend/appflowy_flutter/lib/plugins/database/application/row/row_service.dart b/frontend/appflowy_flutter/lib/plugins/database/application/row/row_service.dart
index 2db78e7e19..151a32d961 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/application/row/row_service.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/application/row/row_service.dart
@@ -83,7 +83,7 @@ class RowBackendService {
Future<FlowyResult<void, FlowyError>> updateMeta({
required String rowId,
String? iconURL,
- String? coverURL,
+ RowCoverPB? cover,
bool? isDocumentEmpty,
}) {
final payload = UpdateRowMetaChangesetPB.create()
@@ -93,8 +93,8 @@ class RowBackendService {
if (iconURL != null) {
payload.iconUrl = iconURL;
}
- if (coverURL != null) {
- payload.coverUrl = coverURL;
+ if (cover != null) {
+ payload.cover = cover;
}
if (isDocumentEmpty != null) {
@@ -104,6 +104,14 @@ class RowBackendService {
return DatabaseEventUpdateRowMeta(payload).send();
}
+ Future<FlowyResult<void, FlowyError>> removeCover(String rowId) async {
+ final payload = RemoveCoverPayloadPB.create()
+ ..viewId = viewId
+ ..rowId = rowId;
+
+ return DatabaseEventRemoveCover(payload).send();
+ }
+
static Future<FlowyResult<void, FlowyError>> deleteRows(
String viewId,
List<RowId> rowIds,
diff --git a/frontend/appflowy_flutter/lib/plugins/database/board/application/board_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database/board/application/board_bloc.dart
index a8a8d9ca30..ad6b82e7df 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/board/application/board_bloc.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/board/application/board_bloc.dart
@@ -6,9 +6,11 @@ import 'package:appflowy/plugins/database/application/field/field_info.dart';
import 'package:appflowy/plugins/database/application/row/row_service.dart';
import 'package:appflowy/plugins/database/board/group_ext.dart';
import 'package:appflowy/plugins/database/domain/group_service.dart';
+import 'package:appflowy_backend/dispatch/dispatch.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/protobuf.dart';
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
+import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pb.dart';
import 'package:appflowy_board/appflowy_board.dart';
import 'package:appflowy_result/appflowy_result.dart';
import 'package:collection/collection.dart';
@@ -47,6 +49,9 @@ class BoardBloc extends Bloc<BoardEvent, BoardState> {
late final GroupBackendService groupBackendSvc;
+ UserProfilePB? _userProfile;
+ UserProfilePB? get userProfile => _userProfile;
+
FieldController get fieldController => databaseController.fieldController;
String get viewId => databaseController.viewId;
@@ -94,6 +99,12 @@ class BoardBloc extends Bloc<BoardEvent, BoardState> {
emit(BoardState.initial(viewId));
_startListening();
await _openDatabase(emit);
+
+ final result = await UserEventGetUserProfile().send();
+ result.fold(
+ (profile) => _userProfile = profile,
+ (err) => Log.error('Failed to fetch user profile: ${err.msg}'),
+ );
},
createRow: (groupId, position, title, targetRowId) async {
final primaryField = databaseController.fieldController.fieldInfos
diff --git a/frontend/appflowy_flutter/lib/plugins/database/board/presentation/board_page.dart b/frontend/appflowy_flutter/lib/plugins/database/board/presentation/board_page.dart
index 3f44d116f5..7c31879e2b 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/board/presentation/board_page.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/board/presentation/board_page.dart
@@ -1,5 +1,8 @@
import 'dart:io';
+import 'package:flutter/material.dart' hide Card;
+import 'package:flutter/services.dart';
+
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/database/board/mobile_board_page.dart';
@@ -23,14 +26,13 @@ import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/theme_extension.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flowy_infra_ui/style_widget/hover.dart';
-import 'package:flutter/material.dart' hide Card;
-import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:universal_platform/universal_platform.dart';
import '../../widgets/card/card.dart';
import '../../widgets/cell/card_cell_builder.dart';
import '../application/board_bloc.dart';
+
import 'toolbar/board_setting_bar.dart';
import 'widgets/board_focus_scope.dart';
import 'widgets/board_hidden_groups.dart';
@@ -687,6 +689,7 @@ class _BoardCardState extends State<_BoardCard> {
rowId: rowMeta.id,
),
),
+ userProfile: context.read<BoardBloc>().userProfile,
),
),
),
@@ -852,6 +855,7 @@ void _openCard({
builder: (_) => RowDetailPage(
databaseController: databaseController,
rowController: rowController,
+ userProfile: context.read<BoardBloc>().userProfile,
),
);
}
diff --git a/frontend/appflowy_flutter/lib/plugins/database/board/presentation/widgets/board_hidden_groups.dart b/frontend/appflowy_flutter/lib/plugins/database/board/presentation/widgets/board_hidden_groups.dart
index a013d370f8..4c55205b21 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/board/presentation/widgets/board_hidden_groups.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/board/presentation/widgets/board_hidden_groups.dart
@@ -419,12 +419,11 @@ class HiddenGroupPopupItemList extends StatelessWidget {
onPressed: () {
FlowyOverlay.show(
context: context,
- builder: (_) {
- return RowDetailPage(
- databaseController: databaseController,
- rowController: rowController,
- );
- },
+ builder: (_) => RowDetailPage(
+ databaseController: databaseController,
+ rowController: rowController,
+ userProfile: context.read<BoardBloc>().userProfile,
+ ),
);
PopoverContainer.of(context).close();
},
diff --git a/frontend/appflowy_flutter/lib/plugins/database/calendar/application/calendar_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database/calendar/application/calendar_bloc.dart
index 3e9b4ac7d7..b2fd09ce85 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/calendar/application/calendar_bloc.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/calendar/application/calendar_bloc.dart
@@ -7,6 +7,7 @@ import 'package:appflowy_backend/dispatch/dispatch.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/protobuf.dart';
import 'package:appflowy_backend/protobuf/flowy-error/protobuf.dart';
+import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pb.dart';
import 'package:appflowy_result/appflowy_result.dart';
import 'package:calendar_view/calendar_view.dart';
import 'package:fixnum/fixnum.dart';
@@ -33,11 +34,20 @@ class CalendarBloc extends Bloc<CalendarEvent, CalendarState> {
CellMemCache get cellCache => databaseController.rowCache.cellCache;
RowCache get rowCache => databaseController.rowCache;
+ UserProfilePB? _userProfile;
+ UserProfilePB? get userProfile => _userProfile;
+
void _dispatch() {
on<CalendarEvent>(
(event, emit) async {
await event.when(
initial: () async {
+ final result = await UserEventGetUserProfile().send();
+ result.fold(
+ (profile) => _userProfile = profile,
+ (err) => Log.error('Failed to get user profile: $err'),
+ );
+
_startListening();
await _openDatabase(emit);
_loadAllEvents();
diff --git a/frontend/appflowy_flutter/lib/plugins/database/calendar/presentation/calendar_event_card.dart b/frontend/appflowy_flutter/lib/plugins/database/calendar/presentation/calendar_event_card.dart
index 98444362bc..3f3d4a4166 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/calendar/presentation/calendar_event_card.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/calendar/presentation/calendar_event_card.dart
@@ -1,3 +1,5 @@
+import 'package:flutter/material.dart';
+
import 'package:appflowy/mobile/presentation/database/card/card_detail/mobile_card_detail_screen.dart';
import 'package:appflowy/plugins/database/application/database_controller.dart';
import 'package:appflowy/plugins/database/application/row/row_cache.dart';
@@ -10,12 +12,12 @@ import 'package:flowy_infra/size.dart';
import 'package:flowy_infra/theme_extension.dart';
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:go_router/go_router.dart';
import 'package:universal_platform/universal_platform.dart';
import '../application/calendar_bloc.dart';
+
import 'calendar_event_editor.dart';
class EventCard extends StatefulWidget {
@@ -80,6 +82,7 @@ class _EventCardState extends State<EventCard> {
rowCache: rowCache,
isEditing: false,
cellBuilder: cellBuilder,
+ isCompact: true,
onTap: (context) {
if (UniversalPlatform.isMobile) {
context.push(
@@ -107,6 +110,7 @@ class _EventCardState extends State<EventCard> {
),
onStartEditing: () {},
onEndEditing: () {},
+ userProfile: context.read<CalendarBloc>().userProfile,
);
final decoration = BoxDecoration(
diff --git a/frontend/appflowy_flutter/lib/plugins/database/calendar/presentation/calendar_event_editor.dart b/frontend/appflowy_flutter/lib/plugins/database/calendar/presentation/calendar_event_editor.dart
index 8a57bea2bd..d1ee346800 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/calendar/presentation/calendar_event_editor.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/calendar/presentation/calendar_event_editor.dart
@@ -130,6 +130,7 @@ class EventEditorControls extends StatelessWidget {
child: RowDetailPage(
databaseController: databaseController,
rowController: rowController,
+ userProfile: context.read<CalendarBloc>().userProfile,
),
),
);
diff --git a/frontend/appflowy_flutter/lib/plugins/database/calendar/presentation/calendar_page.dart b/frontend/appflowy_flutter/lib/plugins/database/calendar/presentation/calendar_page.dart
index 0e24bf6836..ca117bb20f 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/calendar/presentation/calendar_page.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/calendar/presentation/calendar_page.dart
@@ -1,3 +1,5 @@
+import 'package:flutter/material.dart';
+
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet.dart';
@@ -17,13 +19,13 @@ import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/size.dart';
import 'package:flowy_infra/theme_extension.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
-import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:universal_platform/universal_platform.dart';
import '../../application/row/row_controller.dart';
import '../../widgets/row/row_detail.dart';
+
import 'calendar_day.dart';
import 'layout/sizes.dart';
import 'toolbar/calendar_setting_bar.dart';
@@ -365,6 +367,7 @@ void showEventDetails({
child: RowDetailPage(
rowController: rowController,
databaseController: databaseController,
+ userProfile: context.read<CalendarBloc>().userProfile,
),
);
},
@@ -428,15 +431,16 @@ class _UnscheduledEventsButtonState extends State<UnscheduledEventsButton> {
),
),
),
- popupBuilder: (_) {
- return BlocProvider.value(
+ popupBuilder: (_) => BlocProvider.value(
+ value: context.read<CalendarBloc>(),
+ child: BlocProvider.value(
value: context.read<ViewBloc>(),
child: UnscheduleEventsList(
databaseController: widget.databaseController,
unscheduleEvents: state.unscheduleEvents,
),
- );
- },
+ ),
+ ),
);
},
),
diff --git a/frontend/appflowy_flutter/lib/plugins/database/grid/application/grid_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database/grid/application/grid_bloc.dart
index e12cad59be..54e281ab9a 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/grid/application/grid_bloc.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/grid/application/grid_bloc.dart
@@ -6,9 +6,11 @@ import 'package:appflowy/plugins/database/application/row/row_cache.dart';
import 'package:appflowy/plugins/database/application/row/row_service.dart';
import 'package:appflowy/plugins/database/grid/presentation/widgets/filter/filter_info.dart';
import 'package:appflowy/plugins/database/grid/presentation/widgets/sort/sort_info.dart';
+import 'package:appflowy_backend/dispatch/dispatch.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/protobuf.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
+import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pb.dart';
import 'package:appflowy_result/appflowy_result.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
@@ -27,11 +29,20 @@ class GridBloc extends Bloc<GridEvent, GridState> {
String get viewId => databaseController.viewId;
+ UserProfilePB? _userProfile;
+ UserProfilePB? get userProfile => _userProfile;
+
void _dispatch() {
on<GridEvent>(
(event, emit) async {
await event.when(
initial: () async {
+ final response = await UserEventGetUserProfile().send();
+ response.fold(
+ (userProfile) => _userProfile = userProfile,
+ (err) => Log.error(err),
+ );
+
_startListening();
await _openGrid(emit);
},
diff --git a/frontend/appflowy_flutter/lib/plugins/database/grid/application/row/mobile_row_detail_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database/grid/application/row/mobile_row_detail_bloc.dart
index 60c7ad8e65..d70dae3804 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/grid/application/row/mobile_row_detail_bloc.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/grid/application/row/mobile_row_detail_bloc.dart
@@ -1,5 +1,10 @@
import 'package:appflowy/plugins/database/application/database_controller.dart';
import 'package:appflowy/plugins/database/application/row/row_cache.dart';
+import 'package:appflowy/plugins/database/application/row/row_service.dart';
+import 'package:appflowy_backend/dispatch/dispatch.dart';
+import 'package:appflowy_backend/log.dart';
+import 'package:appflowy_backend/protobuf/flowy-database2/row_entities.pb.dart';
+import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pb.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
@@ -9,17 +14,23 @@ class MobileRowDetailBloc
extends Bloc<MobileRowDetailEvent, MobileRowDetailState> {
MobileRowDetailBloc({required this.databaseController})
: super(MobileRowDetailState.initial()) {
+ rowBackendService = RowBackendService(viewId: databaseController.viewId);
_dispatch();
}
final DatabaseController databaseController;
+ late final RowBackendService rowBackendService;
+
+ UserProfilePB? _userProfile;
+ UserProfilePB? get userProfile => _userProfile;
void _dispatch() {
on<MobileRowDetailEvent>(
(event, emit) {
event.when(
- initial: (rowId) {
+ initial: (rowId) async {
_startListening();
+
emit(
state.copyWith(
isLoading: false,
@@ -27,6 +38,12 @@ class MobileRowDetailBloc
rowInfos: databaseController.rowCache.rowInfos,
),
);
+
+ final result = await UserEventGetUserProfile().send();
+ result.fold(
+ (profile) => _userProfile = profile,
+ (error) => Log.error(error),
+ );
},
didLoadRows: (rows) {
emit(state.copyWith(rowInfos: rows));
@@ -34,6 +51,16 @@ class MobileRowDetailBloc
changeRowId: (rowId) {
emit(state.copyWith(currentRowId: rowId));
},
+ addCover: (rowCover) async {
+ if (state.currentRowId == null) {
+ return;
+ }
+
+ await rowBackendService.updateMeta(
+ rowId: state.currentRowId!,
+ cover: rowCover,
+ );
+ },
);
},
);
@@ -66,6 +93,7 @@ class MobileRowDetailEvent with _$MobileRowDetailEvent {
const factory MobileRowDetailEvent.didLoadRows(List<RowInfo> rows) =
_DidLoadRows;
const factory MobileRowDetailEvent.changeRowId(String rowId) = _ChangeRowId;
+ const factory MobileRowDetailEvent.addCover(RowCoverPB cover) = _AddCover;
}
@freezed
diff --git a/frontend/appflowy_flutter/lib/plugins/database/grid/application/row/row_detail_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database/grid/application/row/row_detail_bloc.dart
index 3fcaae3332..baef064258 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/grid/application/row/row_detail_bloc.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/grid/application/row/row_detail_bloc.dart
@@ -1,12 +1,17 @@
+import 'package:flutter/foundation.dart';
+
import 'package:appflowy/plugins/database/application/cell/cell_controller.dart';
import 'package:appflowy/plugins/database/application/field/field_controller.dart';
import 'package:appflowy/plugins/database/application/field/field_info.dart';
+import 'package:appflowy/plugins/database/application/row/row_controller.dart';
+import 'package:appflowy/plugins/database/application/row/row_service.dart';
import 'package:appflowy/plugins/database/domain/field_service.dart';
import 'package:appflowy/plugins/database/domain/field_settings_service.dart';
-import 'package:appflowy/plugins/database/application/row/row_controller.dart';
+import 'package:appflowy/plugins/database/domain/row_meta_listener.dart';
import 'package:appflowy/plugins/database/widgets/setting/field_visibility_extension.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/field_settings_entities.pb.dart';
+import 'package:appflowy_backend/protobuf/flowy-database2/row_entities.pb.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
@@ -16,7 +21,8 @@ class RowDetailBloc extends Bloc<RowDetailEvent, RowDetailState> {
RowDetailBloc({
required this.fieldController,
required this.rowController,
- }) : super(RowDetailState.initial()) {
+ }) : _metaListener = RowMetaListener(rowController.rowId),
+ super(RowDetailState.initial(rowController.rowMeta)) {
_dispatch();
_startListening();
_init();
@@ -26,12 +32,14 @@ class RowDetailBloc extends Bloc<RowDetailEvent, RowDetailState> {
final FieldController fieldController;
final RowController rowController;
+ final RowMetaListener _metaListener;
final List<CellContext> allCells = [];
@override
Future<void> close() async {
await rowController.dispose();
+ await _metaListener.stop();
return super.close();
}
@@ -91,12 +99,27 @@ class RowDetailBloc extends Bloc<RowDetailEvent, RowDetailState> {
endEditingField: () {
emit(state.copyWith(editingFieldId: "", newFieldId: ""));
},
+ removeCover: () {
+ RowBackendService(viewId: rowController.viewId)
+ .removeCover(rowController.rowId);
+ },
+ didReceiveRowMeta: (rowMeta) {
+ emit(state.copyWith(rowMeta: rowMeta));
+ },
);
},
);
}
void _startListening() {
+ _metaListener.start(
+ callback: (rowMeta) {
+ if (!isClosed) {
+ add(RowDetailEvent.didReceiveRowMeta(rowMeta));
+ }
+ },
+ );
+
rowController.addListener(
onRowChanged: (cellMap, reason) {
if (isClosed) {
@@ -238,6 +261,11 @@ class RowDetailEvent with _$RowDetailEvent {
/// End editing an event
const factory RowDetailEvent.endEditingField() = _EndEditingField;
+
+ const factory RowDetailEvent.removeCover() = _RemoveCover;
+
+ const factory RowDetailEvent.didReceiveRowMeta(RowMetaPB rowMeta) =
+ _DidReceiveRowMeta;
}
@freezed
@@ -249,14 +277,16 @@ class RowDetailState with _$RowDetailState {
required int numHiddenFields,
required String editingFieldId,
required String newFieldId,
+ required RowMetaPB rowMeta,
}) = _RowDetailState;
- factory RowDetailState.initial() => const RowDetailState(
+ factory RowDetailState.initial(RowMetaPB rowMeta) => RowDetailState(
fields: [],
visibleCells: [],
showHiddenFields: false,
numHiddenFields: 0,
editingFieldId: "",
newFieldId: "",
+ rowMeta: rowMeta,
);
}
diff --git a/frontend/appflowy_flutter/lib/plugins/database/grid/application/row/row_document_bloc.dart b/frontend/appflowy_flutter/lib/plugins/database/grid/application/row/row_document_bloc.dart
index 93b55bfb3d..743d854b23 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/grid/application/row/row_document_bloc.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/grid/application/row/row_document_bloc.dart
@@ -81,7 +81,7 @@ class RowDocumentBloc extends Bloc<RowDocumentEvent, RowDocumentState> {
// new document for the given document id of the row.
final documentView =
await _createRowDocumentView(rowMeta.documentId);
- if (documentView != null) {
+ if (documentView != null && !isClosed) {
add(RowDocumentEvent.didReceiveRowDocument(documentView));
}
} else {
diff --git a/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/grid_page.dart b/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/grid_page.dart
index 8b03d2c6be..e339d8f8f9 100755
--- a/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/grid_page.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/grid/presentation/grid_page.dart
@@ -1,5 +1,7 @@
import 'dart:math';
+import 'package:flutter/material.dart';
+
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/database/application/row/row_service.dart';
import 'package:appflowy/plugins/database/domain/sort_service.dart';
@@ -17,7 +19,6 @@ import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flowy_infra_ui/style_widget/scrolling/styled_scrollview.dart';
-import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:linked_scroll_controller/linked_scroll_controller.dart';
import 'package:provider/provider.dart';
@@ -27,6 +28,7 @@ import '../../application/row/row_controller.dart';
import '../../tab_bar/tab_bar_view.dart';
import '../../widgets/row/row_detail.dart';
import '../application/grid_bloc.dart';
+
import 'grid_scroll.dart';
import 'layout/layout.dart';
import 'layout/sizes.dart';
@@ -201,6 +203,7 @@ class _GridPageState extends State<GridPage> {
child: RowDetailPage(
databaseController: context.read<GridBloc>().databaseController,
rowController: rowController,
+ userProfile: context.read<GridBloc>().userProfile,
),
),
);
@@ -462,18 +465,17 @@ class _GridRowsState extends State<_GridRows> {
index: index,
rowController: rowController,
cellBuilder: EditableCellBuilder(databaseController: databaseController),
- openDetailPage: (rowDetailContext) {
- FlowyOverlay.show(
- context: rowDetailContext,
- builder: (_) => BlocProvider.value(
- value: context.read<ViewBloc>(),
- child: RowDetailPage(
- rowController: rowController,
- databaseController: databaseController,
- ),
+ openDetailPage: (rowDetailContext) => FlowyOverlay.show(
+ context: rowDetailContext,
+ builder: (_) => BlocProvider.value(
+ value: context.read<ViewBloc>(),
+ child: RowDetailPage(
+ rowController: rowController,
+ databaseController: databaseController,
+ userProfile: context.read<GridBloc>().userProfile,
),
- );
- },
+ ),
+ ),
);
if (animation != null) {
diff --git a/frontend/appflowy_flutter/lib/plugins/database/widgets/card/card.dart b/frontend/appflowy_flutter/lib/plugins/database/widgets/card/card.dart
index 4e627360f9..0f73a9a9f8 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/widgets/card/card.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/widgets/card/card.dart
@@ -1,3 +1,5 @@
+import 'package:flutter/material.dart';
+
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/database/card/card.dart';
@@ -5,19 +7,21 @@ import 'package:appflowy/plugins/database/application/field/field_controller.dar
import 'package:appflowy/plugins/database/application/row/row_cache.dart';
import 'package:appflowy/plugins/database/application/row/row_controller.dart';
import 'package:appflowy/plugins/database/grid/presentation/widgets/row/action.dart';
-import 'package:appflowy_backend/protobuf/flowy-database2/row_entities.pb.dart';
+import 'package:appflowy/shared/af_image.dart';
+import 'package:appflowy_backend/protobuf/flowy-database2/protobuf.dart';
+import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pb.dart';
import 'package:appflowy_popover/appflowy_popover.dart';
import 'package:collection/collection.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/theme_extension.dart';
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:universal_platform/universal_platform.dart';
import '../cell/card_cell_builder.dart';
import '../cell/card_cell_skeleton/card_cell.dart';
+
import 'card_bloc.dart';
import 'container/accessory.dart';
import 'container/card_container.dart';
@@ -39,6 +43,8 @@ class RowCard extends StatefulWidget {
this.onShiftTap,
this.groupingFieldId,
this.groupId,
+ this.userProfile,
+ this.isCompact = false,
});
final FieldController fieldController;
@@ -66,6 +72,14 @@ class RowCard extends StatefulWidget {
final RowCardStyleConfiguration styleConfiguration;
+ /// Specifically the token is used to handle requests to retrieve images
+ /// from cloud storage, such as the card cover.
+ final UserProfilePB? userProfile;
+
+ /// Whether the card is in a narrow space.
+ /// This is used to determine eg. the Cover height.
+ final bool isCompact;
+
@override
State<RowCard> createState() => _RowCardState();
}
@@ -165,6 +179,8 @@ class _RowCardState extends State<RowCard> {
cellBuilder: widget.cellBuilder,
styleConfiguration: widget.styleConfiguration,
cells: state.cells,
+ userProfile: widget.userProfile,
+ isCompact: widget.isCompact,
),
),
);
@@ -188,48 +204,62 @@ class _CardContent extends StatelessWidget {
required this.cellBuilder,
required this.cells,
required this.styleConfiguration,
+ this.userProfile,
+ this.isCompact = false,
});
final RowMetaPB rowMeta;
final CardCellBuilder cellBuilder;
final List<CellMeta> cells;
final RowCardStyleConfiguration styleConfiguration;
+ final UserProfilePB? userProfile;
+ final bool isCompact;
@override
Widget build(BuildContext context) {
final attachmentCount = rowMeta.attachmentCount.toInt();
- final child = Padding(
- padding: styleConfiguration.cardPadding,
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- ..._makeCells(context, rowMeta, cells),
- if (attachmentCount > 0) ...[
- const VSpace(2),
- Padding(
- padding: const EdgeInsets.only(left: 8),
- child: Row(
- children: [
- const FlowySvg(
- FlowySvgs.media_s,
- size: Size.square(12),
- ),
- const HSpace(4),
- Flexible(
- child: FlowyText.regular(
- LocaleKeys.grid_media_attachmentsHint
- .tr(args: ['$attachmentCount']),
- fontSize: 11,
- color: AFThemeExtension.of(context).secondaryTextColor,
- overflow: TextOverflow.ellipsis,
- ),
+ final child = Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ CardCover(
+ cover: rowMeta.cover,
+ userProfile: userProfile,
+ isCompact: isCompact,
+ ),
+ Padding(
+ padding: styleConfiguration.cardPadding,
+ child: Column(
+ children: [
+ ..._makeCells(context, rowMeta, cells),
+ if (attachmentCount > 0) ...[
+ const VSpace(2),
+ Padding(
+ padding: const EdgeInsets.only(left: 8),
+ child: Row(
+ children: [
+ const FlowySvg(
+ FlowySvgs.media_s,
+ size: Size.square(12),
+ ),
+ const HSpace(4),
+ Flexible(
+ child: FlowyText.regular(
+ LocaleKeys.grid_media_attachmentsHint
+ .tr(args: ['$attachmentCount']),
+ fontSize: 11,
+ color:
+ AFThemeExtension.of(context).secondaryTextColor,
+ overflow: TextOverflow.ellipsis,
+ ),
+ ),
+ ],
),
- ],
- ),
- ),
- ],
- ],
- ),
+ ),
+ ],
+ ],
+ ),
+ ),
+ ],
);
return styleConfiguration.hoverStyle == null
? child
@@ -267,6 +297,52 @@ class _CardContent extends StatelessWidget {
}
}
+class CardCover extends StatelessWidget {
+ const CardCover({
+ super.key,
+ this.cover,
+ this.userProfile,
+ this.isCompact = false,
+ });
+
+ final RowCoverPB? cover;
+ final UserProfilePB? userProfile;
+ final bool isCompact;
+
+ @override
+ Widget build(BuildContext context) {
+ if (cover == null ||
+ cover!.url.isEmpty ||
+ cover!.uploadType == FileUploadTypePB.CloudFile &&
+ userProfile == null) {
+ return const SizedBox.shrink();
+ }
+
+ return Container(
+ clipBehavior: Clip.antiAlias,
+ decoration: BoxDecoration(
+ borderRadius: const BorderRadius.only(
+ topLeft: Radius.circular(4),
+ topRight: Radius.circular(4),
+ ),
+ color: Theme.of(context).cardColor,
+ ),
+ child: Row(
+ children: [
+ Expanded(
+ child: AFImage(
+ url: cover!.url,
+ uploadType: cover!.uploadType,
+ userProfile: userProfile,
+ height: isCompact ? 50 : 100,
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+}
+
class EditCardAccessory extends StatelessWidget with CardAccessory {
const EditCardAccessory({super.key});
diff --git a/frontend/appflowy_flutter/lib/plugins/database/widgets/cell/desktop_grid/desktop_grid_media_cell.dart b/frontend/appflowy_flutter/lib/plugins/database/widgets/cell/desktop_grid/desktop_grid_media_cell.dart
index 3841a5cad6..f1fc6beb4b 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/widgets/cell/desktop_grid/desktop_grid_media_cell.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/widgets/cell/desktop_grid/desktop_grid_media_cell.dart
@@ -1,4 +1,4 @@
-import 'dart:io';
+import 'package:flutter/material.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
@@ -9,13 +9,12 @@ import 'package:appflowy/plugins/database/widgets/cell_editor/media_cell_editor.
import 'package:appflowy/plugins/database/widgets/cell_editor/mobile_media_cell_editor.dart';
import 'package:appflowy/plugins/database/widgets/media_file_type_ext.dart';
import 'package:appflowy/plugins/database/widgets/row/cells/cell_container.dart';
-import 'package:appflowy/shared/appflowy_network_image.dart';
+import 'package:appflowy/shared/af_image.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/media_entities.pb.dart';
import 'package:appflowy_popover/appflowy_popover.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/theme_extension.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
-import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:universal_platform/universal_platform.dart';
@@ -160,38 +159,16 @@ class _FilePreviewRender extends StatelessWidget {
@override
Widget build(BuildContext context) {
- Widget child;
- if (file.fileType == MediaFileTypePB.Image) {
- if (file.uploadType == MediaUploadTypePB.NetworkMedia) {
- child = Image.network(
- file.url,
- height: 32,
- width: 32,
- fit: BoxFit.cover,
- );
- } else if (file.uploadType == MediaUploadTypePB.LocalMedia) {
- child = Image.file(
- File(file.url),
- height: 32,
- width: 32,
- fit: BoxFit.cover,
- );
- } else {
- // Cloud
- child = FlowyNetworkImage(
- url: file.url,
- userProfilePB: context.read<MediaCellBloc>().state.userProfile,
- height: 32,
- width: 32,
- );
- }
- } else {
- child = Container(
+ if (file.fileType != MediaFileTypePB.Image) {
+ return Container(
+ margin: const EdgeInsets.symmetric(horizontal: 2),
height: 32,
width: 32,
+ clipBehavior: Clip.antiAlias,
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: AFThemeExtension.of(context).greyHover,
+ borderRadius: BorderRadius.circular(4),
),
child: FlowySvg(
file.fileType.icon,
@@ -201,12 +178,18 @@ class _FilePreviewRender extends StatelessWidget {
}
return Container(
- margin: const EdgeInsets.all(2),
+ margin: const EdgeInsets.symmetric(horizontal: 2),
+ height: 32,
+ width: 32,
clipBehavior: Clip.antiAlias,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(4),
),
- child: child,
+ child: AFImage(
+ url: file.url,
+ uploadType: file.uploadType,
+ userProfile: context.read<MediaCellBloc>().state.userProfile,
+ ),
);
}
}
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.dart
index cf3288ddd3..fec4cd96b2 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
@@ -1,5 +1,3 @@
-import 'dart:io';
-
import 'package:flutter/material.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
@@ -13,12 +11,13 @@ import 'package:appflowy/plugins/document/presentation/editor_plugins/file/file_
import 'package:appflowy/plugins/document/presentation/editor_plugins/file/file_upload_menu.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/file/file_util.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/common.dart';
-import 'package:appflowy/shared/appflowy_network_image.dart';
+import 'package:appflowy/shared/af_image.dart';
import 'package:appflowy/util/theme_extension.dart';
import 'package:appflowy/util/xfile_ext.dart';
import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';
import 'package:appflowy/workspace/presentation/widgets/image_viewer/image_provider.dart';
import 'package:appflowy/workspace/presentation/widgets/image_viewer/interactive_image_viewer.dart';
+import 'package:appflowy_backend/protobuf/flowy-database2/file_entities.pbenum.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/media_entities.pb.dart';
import 'package:appflowy_popover/appflowy_popover.dart';
import 'package:collection/collection.dart';
@@ -195,8 +194,8 @@ class _AddFileButton extends StatelessWidget {
url: path,
name: file.name,
uploadType: isLocalMode
- ? MediaUploadTypePB.LocalMedia
- : MediaUploadTypePB.CloudMedia,
+ ? FileUploadTypePB.LocalFile
+ : FileUploadTypePB.CloudFile,
fileType: file.fileType.toMediaFileTypePB(),
),
);
@@ -229,7 +228,7 @@ class _AddFileButton extends StatelessWidget {
MediaCellEvent.addFile(
url: url,
name: name,
- uploadType: MediaUploadTypePB.NetworkMedia,
+ uploadType: FileUploadTypePB.NetworkFile,
fileType: fileType,
),
);
@@ -297,17 +296,11 @@ class _FilePreviewRenderState extends State<_FilePreviewRender> {
Widget build(BuildContext context) {
Widget child;
if (file.fileType == MediaFileTypePB.Image) {
- if (file.uploadType == MediaUploadTypePB.NetworkMedia) {
- child = Image.network(file.url, fit: BoxFit.cover);
- } else if (file.uploadType == MediaUploadTypePB.LocalMedia) {
- child = Image.file(File(file.url), fit: BoxFit.cover);
- } else {
- // Cloud
- child = FlowyNetworkImage(
- url: file.url,
- userProfilePB: context.read<MediaCellBloc>().state.userProfile,
- );
- }
+ child = AFImage(
+ url: file.url,
+ uploadType: file.uploadType,
+ userProfile: context.read<MediaCellBloc>().state.userProfile,
+ );
} else {
child = DecoratedBox(
decoration: BoxDecoration(color: file.fileType.color),
diff --git a/frontend/appflowy_flutter/lib/plugins/database/widgets/cell_editor/media_cell_editor.dart b/frontend/appflowy_flutter/lib/plugins/database/widgets/cell_editor/media_cell_editor.dart
index 7d8a80d98a..59ef6e6283 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/widgets/cell_editor/media_cell_editor.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/widgets/cell_editor/media_cell_editor.dart
@@ -1,5 +1,3 @@
-import 'dart:io';
-
import 'package:flutter/material.dart';
import 'package:appflowy/core/helpers/url_launcher.dart';
@@ -11,11 +9,12 @@ import 'package:appflowy/plugins/document/presentation/editor_plugins/file/file_
import 'package:appflowy/plugins/document/presentation/editor_plugins/file/file_upload_menu.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/file/file_util.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/common.dart';
-import 'package:appflowy/shared/appflowy_network_image.dart';
+import 'package:appflowy/shared/af_image.dart';
import 'package:appflowy/util/xfile_ext.dart';
import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';
import 'package:appflowy/workspace/presentation/widgets/image_viewer/image_provider.dart';
import 'package:appflowy/workspace/presentation/widgets/image_viewer/interactive_image_viewer.dart';
+import 'package:appflowy_backend/protobuf/flowy-database2/file_entities.pbenum.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/media_entities.pb.dart';
import 'package:appflowy_popover/appflowy_popover.dart';
import 'package:cross_file/cross_file.dart';
@@ -115,8 +114,8 @@ class _MediaCellEditorState extends State<MediaCellEditor> {
url: path,
name: file.name,
uploadType: isLocalMode
- ? MediaUploadTypePB.LocalMedia
- : MediaUploadTypePB.CloudMedia,
+ ? FileUploadTypePB.LocalFile
+ : FileUploadTypePB.CloudFile,
fileType: file.fileType.toMediaFileTypePB(),
),
);
@@ -152,7 +151,7 @@ class _MediaCellEditorState extends State<MediaCellEditor> {
MediaCellEvent.addFile(
url: url,
name: name,
- uploadType: MediaUploadTypePB.NetworkMedia,
+ uploadType: FileUploadTypePB.NetworkFile,
fileType: fileType,
),
);
@@ -193,10 +192,10 @@ class _MediaCellEditorState extends State<MediaCellEditor> {
}
}
-extension ToCustomImageType on MediaUploadTypePB {
+extension ToCustomImageType on FileUploadTypePB {
CustomImageType toCustomImageType() => switch (this) {
- MediaUploadTypePB.NetworkMedia => CustomImageType.external,
- MediaUploadTypePB.CloudMedia => CustomImageType.internal,
+ FileUploadTypePB.NetworkFile => CustomImageType.external,
+ FileUploadTypePB.CloudFile => CustomImageType.internal,
_ => CustomImageType.local,
};
}
@@ -265,39 +264,20 @@ class _RenderMediaState extends State<RenderMedia> {
child: const FlowySvg(FlowySvgs.drag_element_s),
),
const HSpace(8),
- if (file.fileType == MediaFileTypePB.Image &&
- file.uploadType == MediaUploadTypePB.CloudMedia) ...[
+ if (widget.file.fileType == MediaFileTypePB.Image) ...[
Expanded(
child: _openInteractiveViewer(
context,
files: widget.images,
index: imageIndex!,
- child: FlowyNetworkImage(
- url: file.url,
- userProfilePB:
+ child: AFImage(
+ url: widget.file.url,
+ uploadType: widget.file.uploadType,
+ userProfile:
context.read<MediaCellBloc>().state.userProfile,
),
),
),
- ] else if (file.fileType == MediaFileTypePB.Image) ...[
- Expanded(
- child: _openInteractiveViewer(
- context,
- files: widget.images,
- index: imageIndex!,
- child: file.uploadType == MediaUploadTypePB.NetworkMedia
- ? Image.network(
- file.url,
- fit: BoxFit.cover,
- alignment: Alignment.centerLeft,
- )
- : Image.file(
- File(file.url),
- fit: BoxFit.cover,
- alignment: Alignment.centerLeft,
- ),
- ),
- ),
] else ...[
Expanded(
child: GestureDetector(
diff --git a/frontend/appflowy_flutter/lib/plugins/database/widgets/cell_editor/mobile_media_cell_editor.dart b/frontend/appflowy_flutter/lib/plugins/database/widgets/cell_editor/mobile_media_cell_editor.dart
index 45fe7ff5d6..511e56da3e 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/widgets/cell_editor/mobile_media_cell_editor.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/widgets/cell_editor/mobile_media_cell_editor.dart
@@ -14,6 +14,7 @@ import 'package:appflowy/plugins/document/presentation/editor_plugins/image/comm
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/multi_image_block_component/image_render.dart';
import 'package:appflowy/util/xfile_ext.dart';
import 'package:appflowy/workspace/presentation/widgets/image_viewer/interactive_image_viewer.dart';
+import 'package:appflowy_backend/protobuf/flowy-database2/file_entities.pbenum.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/media_entities.pb.dart';
import 'package:cross_file/cross_file.dart';
import 'package:easy_localization/easy_localization.dart';
@@ -92,8 +93,8 @@ class MobileMediaCellEditor extends StatelessWidget {
url: path,
name: file.name,
uploadType: isLocalMode
- ? MediaUploadTypePB.LocalMedia
- : MediaUploadTypePB.CloudMedia,
+ ? FileUploadTypePB.LocalFile
+ : FileUploadTypePB.CloudFile,
fileType:
file.fileType.toMediaFileTypePB(),
),
@@ -166,7 +167,7 @@ class MobileMediaCellEditor extends StatelessWidget {
MediaCellEvent.addFile(
url: url,
name: name,
- uploadType: MediaUploadTypePB.NetworkMedia,
+ uploadType: FileUploadTypePB.NetworkFile,
fileType: fileType,
),
);
diff --git a/frontend/appflowy_flutter/lib/plugins/database/widgets/row/row_banner.dart b/frontend/appflowy_flutter/lib/plugins/database/widgets/row/row_banner.dart
index 862751f365..586381843c 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/widgets/row/row_banner.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/widgets/row/row_banner.dart
@@ -13,7 +13,12 @@ import 'package:appflowy/plugins/database/widgets/cell/editable_cell_builder.dar
import 'package:appflowy/plugins/database/widgets/cell/editable_cell_skeleton/text.dart';
import 'package:appflowy/plugins/database/widgets/row/cells/cell_container.dart';
import 'package:appflowy/plugins/database/widgets/row/row_action.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/file/file_util.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/image/upload_image_menu/upload_image_menu.dart';
+import 'package:appflowy/shared/af_image.dart';
import 'package:appflowy/workspace/presentation/settings/widgets/emoji_picker/emoji_picker.dart';
+import 'package:appflowy_backend/protobuf/flowy-database2/protobuf.dart';
+import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pb.dart';
import 'package:appflowy_popover/appflowy_popover.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
@@ -28,12 +33,14 @@ class RowBanner extends StatefulWidget {
required this.rowController,
required this.cellBuilder,
this.allowOpenAsFullPage = true,
+ this.userProfile,
});
final DatabaseController databaseController;
final RowController rowController;
final EditableCellBuilder cellBuilder;
final bool allowOpenAsFullPage;
+ final UserProfilePB? userProfile;
@override
State<RowBanner> createState() => _RowBannerState();
@@ -57,28 +64,45 @@ class _RowBannerState extends State<RowBanner> {
fieldController: widget.databaseController.fieldController,
rowMeta: widget.rowController.rowMeta,
)..add(const RowBannerEvent.initial()),
- child: MouseRegion(
- onEnter: (event) => _isHovering.value = true,
- onExit: (event) => _isHovering.value = false,
- child: Padding(
- padding: const EdgeInsets.fromLTRB(60, 34, 60, 0),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- SizedBox(
- height: 30,
- child: _BannerAction(
- isHovering: _isHovering,
- popoverController: popoverController,
+ child: Builder(
+ builder: (context) => MouseRegion(
+ onEnter: (event) => _isHovering.value = true,
+ onExit: (event) => _isHovering.value = false,
+ child: Padding(
+ padding: EdgeInsets.zero,
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ BannerCover(userProfile: widget.userProfile),
+ Padding(
+ padding: EdgeInsets.fromLTRB(
+ 60,
+ context.watch<RowBannerBloc>().hasCover ? 4 : 34,
+ 60,
+ 0,
+ ),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ SizedBox(
+ height: 30,
+ child: _BannerAction(
+ rowId: widget.rowController.rowId,
+ isHovering: _isHovering,
+ popoverController: popoverController,
+ ),
+ ),
+ const VSpace(8),
+ _BannerTitle(
+ cellBuilder: widget.cellBuilder,
+ popoverController: popoverController,
+ rowController: widget.rowController,
+ ),
+ ],
+ ),
),
- ),
- const VSpace(4),
- _BannerTitle(
- cellBuilder: widget.cellBuilder,
- popoverController: popoverController,
- rowController: widget.rowController,
- ),
- ],
+ ],
+ ),
),
),
),
@@ -86,23 +110,32 @@ class _RowBannerState extends State<RowBanner> {
}
}
-class _BannerAction extends StatelessWidget {
+class _BannerAction extends StatefulWidget {
const _BannerAction({
required this.isHovering,
required this.popoverController,
+ required this.rowId,
});
final ValueNotifier<bool> isHovering;
final PopoverController popoverController;
+ final String rowId;
+
+ @override
+ State<_BannerAction> createState() => _BannerActionState();
+}
+
+class _BannerActionState extends State<_BannerAction> {
+ bool isSelected = false;
@override
Widget build(BuildContext context) {
return SizedBox(
height: _kBannerActionHeight,
child: ValueListenableBuilder(
- valueListenable: isHovering,
+ valueListenable: widget.isHovering,
builder: (BuildContext context, bool isHovering, Widget? child) {
- if (!isHovering) {
+ if (!isHovering && !isSelected) {
return const SizedBox.shrink();
}
@@ -113,7 +146,7 @@ class _BannerAction extends StatelessWidget {
children: [
if (state.rowMeta.icon.isEmpty)
AddEmojiButton(
- onTap: () => popoverController.show(),
+ onTap: () => widget.popoverController.show(),
)
else
RemoveEmojiButton(
@@ -121,6 +154,24 @@ class _BannerAction extends StatelessWidget {
.read<RowBannerBloc>()
.add(const RowBannerEvent.setIcon('')),
),
+ const HSpace(8),
+ if (state.rowMeta.cover.url.isEmpty)
+ AddCoverButton(
+ rowId: widget.rowId,
+ onPopoverChanged: (isShowing) {
+ isSelected = isShowing;
+
+ if (!isShowing) {
+ setState(() {});
+ }
+ },
+ )
+ else
+ RemoveCoverButton(
+ onTap: () => context
+ .read<RowBannerBloc>()
+ .add(const RowBannerEvent.removeCover()),
+ ),
],
);
},
@@ -184,6 +235,48 @@ class _BannerTitle extends StatelessWidget {
}
}
+@visibleForTesting
+class BannerCover extends StatelessWidget {
+ const BannerCover({super.key, required this.userProfile});
+
+ final UserProfilePB? userProfile;
+
+ @override
+ Widget build(BuildContext context) {
+ return BlocBuilder<RowBannerBloc, RowBannerState>(
+ buildWhen: (prev, curr) =>
+ prev.rowMeta.cover.url != curr.rowMeta.cover.url,
+ builder: (context, state) {
+ final cover = state.rowMeta.cover;
+ if (cover.url.isEmpty) {
+ return const SizedBox.shrink();
+ }
+
+ return Row(
+ children: [
+ Expanded(
+ child: SizedBox(
+ height: 250,
+ child: Container(
+ clipBehavior: Clip.antiAlias,
+ decoration: BoxDecoration(
+ color: Theme.of(context).colorScheme.surface,
+ ),
+ child: AFImage(
+ url: cover.url,
+ uploadType: cover.uploadType,
+ userProfile: userProfile,
+ ),
+ ),
+ ),
+ ),
+ ],
+ );
+ },
+ );
+ }
+}
+
class EmojiButton extends StatelessWidget {
const EmojiButton({
super.key,
@@ -211,6 +304,87 @@ class EmojiButton extends StatelessWidget {
}
}
+class AddCoverButton extends StatelessWidget {
+ const AddCoverButton({
+ super.key,
+ required this.rowId,
+ required this.onPopoverChanged,
+ });
+
+ final String rowId;
+ final void Function(bool) onPopoverChanged;
+
+ @override
+ Widget build(BuildContext context) {
+ return AppFlowyPopover(
+ direction: PopoverDirection.bottomWithCenterAligned,
+ offset: const Offset(0, 5),
+ onOpen: () => onPopoverChanged(true),
+ onClose: () => onPopoverChanged(false),
+ popupBuilder: (_) => BlocProvider.value(
+ value: context.read<RowBannerBloc>(),
+ child: Builder(
+ builder: (context) {
+ return UploadImageMenu(
+ supportTypes: const [UploadImageType.local, UploadImageType.url],
+ onSelectedLocalImages: (images) async {
+ if (images.isEmpty) {
+ return;
+ }
+
+ final image = images.first;
+ await insertLocalFile(
+ context,
+ image,
+ userProfile: context.read<RowBannerBloc>().userProfile,
+ documentId: rowId,
+ onUploadSuccess: (url, isLocalMode) {
+ context.read<RowBannerBloc>().add(
+ RowBannerEvent.setCover(
+ RowCoverPB(
+ url: url,
+ uploadType: isLocalMode
+ ? FileUploadTypePB.LocalFile
+ : FileUploadTypePB.CloudFile,
+ ),
+ ),
+ );
+ },
+ );
+ onPopoverChanged(false);
+ },
+ onSelectedNetworkImage: (String url) {
+ context.read<RowBannerBloc>().add(
+ RowBannerEvent.setCover(
+ RowCoverPB(
+ url: url,
+ uploadType: FileUploadTypePB.NetworkFile,
+ ),
+ ),
+ );
+ onPopoverChanged(false);
+ },
+ onSelectedAIImage: (_) {},
+ );
+ },
+ ),
+ ),
+ child: SizedBox(
+ height: 26,
+ child: FlowyButton(
+ useIntrinsicWidth: true,
+ text: FlowyText.medium(
+ lineHeight: 1.0,
+ LocaleKeys.document_plugins_cover_addCover.tr(),
+ ),
+ leftIcon: const FlowySvg(FlowySvgs.image_s),
+ margin: const EdgeInsets.all(4),
+ ),
+ ),
+ );
+ }
+}
+
class AddEmojiButton extends StatelessWidget {
const AddEmojiButton({super.key, required this.onTap});
@@ -234,6 +408,29 @@ class AddEmojiButton extends StatelessWidget {
}
}
+class RemoveCoverButton extends StatelessWidget {
+ const RemoveCoverButton({super.key, required this.onTap});
+
+ final VoidCallback onTap;
+
+ @override
+ Widget build(BuildContext context) {
+ return SizedBox(
+ height: 26,
+ child: FlowyButton(
+ useIntrinsicWidth: true,
+ text: FlowyText.medium(
+ lineHeight: 1.0,
+ LocaleKeys.document_plugins_cover_removeCover.tr(),
+ ),
+ leftIcon: const FlowySvg(FlowySvgs.image_s),
+ onTap: onTap,
+ margin: const EdgeInsets.all(4),
+ ),
+ );
+ }
+}
+
class RemoveEmojiButton extends StatelessWidget {
const RemoveEmojiButton({super.key, required this.onTap});
diff --git a/frontend/appflowy_flutter/lib/plugins/database/widgets/row/row_detail.dart b/frontend/appflowy_flutter/lib/plugins/database/widgets/row/row_detail.dart
index bdc1812926..5a47f23d85 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/widgets/row/row_detail.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/widgets/row/row_detail.dart
@@ -1,3 +1,5 @@
+import 'package:flutter/material.dart';
+
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/database/application/database_controller.dart';
@@ -10,9 +12,9 @@ import 'package:appflowy/startup/plugin/plugin.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/user/application/reminder/reminder_bloc.dart';
import 'package:appflowy/workspace/application/tabs/tabs_bloc.dart';
+import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pb.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
-import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../cell/editable_cell_builder.dart';
@@ -26,11 +28,13 @@ class RowDetailPage extends StatefulWidget with FlowyOverlayDelegate {
required this.rowController,
required this.databaseController,
this.allowOpenAsFullPage = true,
+ this.userProfile,
});
final RowController rowController;
final DatabaseController databaseController;
final bool allowOpenAsFullPage;
+ final UserProfilePB? userProfile;
@override
State<RowDetailPage> createState() => _RowDetailPageState();
@@ -71,6 +75,7 @@ class _RowDetailPageState extends State<RowDetailPage> {
rowController: widget.rowController,
cellBuilder: cellBuilder,
allowOpenAsFullPage: widget.allowOpenAsFullPage,
+ userProfile: widget.userProfile,
),
const VSpace(16),
Padding(
diff --git a/frontend/appflowy_flutter/lib/plugins/database_document/database_document_page.dart b/frontend/appflowy_flutter/lib/plugins/database_document/database_document_page.dart
index 755526a5e1..b32da477bf 100644
--- a/frontend/appflowy_flutter/lib/plugins/database_document/database_document_page.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database_document/database_document_page.dart
@@ -1,3 +1,5 @@
+import 'package:flutter/material.dart';
+
import 'package:appflowy/plugins/database/application/row/related_row_detail_bloc.dart';
import 'package:appflowy/plugins/database/grid/application/row/row_detail_bloc.dart';
import 'package:appflowy/plugins/database/grid/presentation/widgets/common/type_option_separator.dart';
@@ -15,7 +17,6 @@ import 'package:appflowy/workspace/application/action_navigation/navigation_acti
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/protobuf.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
-import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
// This widget is largely copied from `plugins/document/document_page.dart` intentionally instead of opting for an abstraction. We can make an abstraction after the view refactor is done and there's more clarity in that department.
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/file/file_util.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/file/file_util.dart
index ad0c74d3e7..bad67ab377 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/file/file_util.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/file/file_util.dart
@@ -14,6 +14,7 @@ import 'package:appflowy/workspace/presentation/home/toast.dart';
import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';
import 'package:appflowy_backend/dispatch/error.dart';
import 'package:appflowy_backend/log.dart';
+import 'package:appflowy_backend/protobuf/flowy-database2/file_entities.pbenum.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/media_entities.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-user/auth.pbenum.dart';
import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pb.dart';
@@ -101,8 +102,8 @@ Future<void> downloadMediaFile(
UserProfilePB? userProfile,
}) async {
if ([
- MediaUploadTypePB.NetworkMedia,
- MediaUploadTypePB.LocalMedia,
+ FileUploadTypePB.NetworkFile,
+ FileUploadTypePB.LocalFile,
].contains(file.uploadType)) {
/// When the file is a network file or a local file, we can directly open the file.
await afLaunchUrl(Uri.parse(file.url));
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/header/document_header_node_widget.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/header/document_header_node_widget.dart
index 399bec59de..6d31048fff 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/header/document_header_node_widget.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/header/document_header_node_widget.dart
@@ -1,5 +1,7 @@
import 'dart:io';
+import 'package:flutter/material.dart';
+
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/application/page_style/document_page_style_bloc.dart';
@@ -23,7 +25,6 @@ import 'package:appflowy_popover/appflowy_popover.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flowy_infra_ui/widget/rounded_button.dart';
-import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:string_validator/string_validator.dart';
@@ -484,11 +485,16 @@ class DocumentCoverState extends State<DocumentCover> {
UploadImageType.url,
UploadImageType.unsplash,
],
- onSelectedLocalImages: (paths) async {
+ onSelectedLocalImages: (files) async {
context.pop();
+
+ if (files.isEmpty) {
+ return;
+ }
+
widget.onChangeCover(
CoverType.file,
- paths.first,
+ files.first.path,
);
},
onSelectedAIImage: (_) {
@@ -613,9 +619,14 @@ class DocumentCoverState extends State<DocumentCover> {
UploadImageType.url,
UploadImageType.unsplash,
],
- onSelectedLocalImages: (paths) {
+ onSelectedLocalImages: (files) {
popoverController.close();
- onCoverChanged(CoverType.file, paths.first);
+ if (files.isEmpty) {
+ return;
+ }
+
+ final item = files.map((file) => file.path).first;
+ onCoverChanged(CoverType.file, item);
},
onSelectedAIImage: (_) {
throw UnimplementedError();
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 5fc47900a9..b4da27f678 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,7 @@
import 'dart:io';
+import 'package:flutter/material.dart';
+
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet.dart';
@@ -22,7 +24,6 @@ import 'package:flowy_infra/uuid.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flowy_infra_ui/style_widget/hover.dart';
import 'package:flowy_infra_ui/style_widget/snap_bar.dart';
-import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:http/http.dart';
@@ -103,11 +104,13 @@ class ImagePlaceholderState extends State<ImagePlaceholder> {
UploadImageType.url,
UploadImageType.unsplash,
],
- onSelectedLocalImages: (paths) {
+ onSelectedLocalImages: (files) {
controller.close();
WidgetsBinding.instance.addPostFrameCallback((_) async {
final List<String> items = List.from(
- paths.where((url) => url != null && url.isNotEmpty),
+ files
+ .where((file) => file.path.isNotEmpty)
+ .map((file) => file.path),
);
if (items.isNotEmpty) {
await insertMultipleLocalImages(items);
@@ -224,12 +227,13 @@ class ImagePlaceholderState extends State<ImagePlaceholder> {
UploadImageType.url,
UploadImageType.unsplash,
],
- onSelectedLocalImages: (paths) async {
+ onSelectedLocalImages: (files) async {
context.pop();
- final List<String> items = List.from(
- paths.where((url) => url != null && url.isNotEmpty),
- );
+ final items = files
+ .where((file) => file.path.isNotEmpty)
+ .map((file) => file.path)
+ .toList();
await insertMultipleLocalImages(items);
},
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/multi_image_block_component/multi_image_menu.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/multi_image_block_component/multi_image_menu.dart
index b97544de76..d1fe23cb59 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/multi_image_block_component/multi_image_menu.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/multi_image_block_component/multi_image_menu.dart
@@ -1,5 +1,8 @@
import 'dart:io';
+import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
+
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/application/document_bloc.dart';
@@ -17,13 +20,12 @@ import 'package:appflowy/workspace/presentation/widgets/image_viewer/interactive
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_editor/appflowy_editor.dart' hide UploadImageMenu;
import 'package:appflowy_popover/appflowy_popover.dart';
+import 'package:cross_file/cross_file.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/size.dart';
import 'package:flowy_infra/theme_extension.dart';
import 'package:flowy_infra/uuid.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
-import 'package:flutter/material.dart';
-import 'package:flutter/services.dart';
import 'package:http/http.dart';
import 'package:path/path.dart' as p;
import 'package:provider/provider.dart';
@@ -276,11 +278,16 @@ class _MultiImageMenuState extends State<MultiImageMenu> {
);
}
- Future<void> insertLocalImages(List<String?> urls) async {
+ Future<void> insertLocalImages(List<XFile> files) async {
controller.close();
WidgetsBinding.instance.addPostFrameCallback((_) async {
- if (urls.isEmpty || urls.every((path) => path?.isEmpty ?? true)) {
+ final urls = files
+ .map((file) => file.path)
+ .where((path) => path.isNotEmpty)
+ .toList();
+
+ if (urls.isEmpty || urls.every((url) => url.isEmpty)) {
return;
}
@@ -331,7 +338,7 @@ class _MultiImageMenuState extends State<MultiImageMenu> {
final response = await get(uri);
await File(copyToPath).writeAsBytes(response.bodyBytes);
- await insertLocalImages([copyToPath]);
+ await insertLocalImages([XFile(copyToPath)]);
await File(copyToPath).delete();
} catch (e) {
Log.error('cannot save image file', e);
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/multi_image_block_component/multi_image_placeholder.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/multi_image_block_component/multi_image_placeholder.dart
index 8649c73a7a..f1095ff4e6 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/multi_image_block_component/multi_image_placeholder.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/multi_image_block_component/multi_image_placeholder.dart
@@ -108,9 +108,10 @@ class MultiImagePlaceholderState extends State<MultiImagePlaceholder> {
UploadImageType.url,
UploadImageType.unsplash,
],
- onSelectedLocalImages: (paths) {
+ onSelectedLocalImages: (files) {
controller.close();
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
+ final paths = files.map((file) => file.path).toList();
await insertLocalImages(paths);
});
},
@@ -191,9 +192,10 @@ class MultiImagePlaceholderState extends State<MultiImagePlaceholder> {
UploadImageType.url,
UploadImageType.unsplash,
],
- onSelectedLocalImages: (paths) async {
+ onSelectedLocalImages: (files) async {
context.pop();
- await insertLocalImages(paths);
+ final items = files.map((file) => file.path).toList();
+ await insertLocalImages(items);
},
onSelectedAIImage: (url) async {
context.pop();
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/upload_image_menu/upload_image_menu.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/upload_image_menu/upload_image_menu.dart
index f40cc0e221..836f087797 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/upload_image_menu/upload_image_menu.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/upload_image_menu/upload_image_menu.dart
@@ -4,6 +4,7 @@ import 'package:appflowy/plugins/document/presentation/editor_plugins/image/unsp
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/upload_image_menu/widgets/upload_image_file_widget.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
import 'package:appflowy_editor/appflowy_editor.dart' hide ColorOption;
+import 'package:cross_file/cross_file.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/theme_extension.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
@@ -42,7 +43,7 @@ class UploadImageMenu extends StatefulWidget {
this.allowMultipleImages = false,
});
- final void Function(List<String?>) onSelectedLocalImages;
+ final void Function(List<XFile>) onSelectedLocalImages;
final void Function(String url) onSelectedAIImage;
final void Function(String url) onSelectedNetworkImage;
final void Function(String color)? onSelectedColor;
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/upload_image_menu/widgets/upload_image_file_widget.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/upload_image_menu/widgets/upload_image_file_widget.dart
index 3ca36e846f..f08c74b84e 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/upload_image_menu/widgets/upload_image_file_widget.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/upload_image_menu/widgets/upload_image_file_widget.dart
@@ -19,7 +19,7 @@ class UploadImageFileWidget extends StatelessWidget {
this.allowMultipleImages = false,
});
- final void Function(List<String?>) onPickFiles;
+ final void Function(List<XFile>) onPickFiles;
final List<String> allowedExtensions;
final bool allowMultipleImages;
@@ -59,7 +59,7 @@ class UploadImageFileWidget extends StatelessWidget {
allowedExtensions: allowedExtensions,
allowMultiple: allowMultipleImages,
);
- onPickFiles(result?.files.map((f) => f.path).toList() ?? const []);
+ onPickFiles(result?.files.map((f) => f.xFile).toList() ?? const []);
} else {
final photoPermission =
await PermissionChecker.checkPhotoPermission(context);
@@ -69,7 +69,7 @@ class UploadImageFileWidget extends StatelessWidget {
}
// on mobile, the users can pick a image file from camera or image library
final result = await ImagePicker().pickMultiImage();
- onPickFiles(result.map((f) => f.path).toList());
+ onPickFiles(result);
}
}
}
diff --git a/frontend/appflowy_flutter/lib/shared/af_image.dart b/frontend/appflowy_flutter/lib/shared/af_image.dart
new file mode 100644
index 0000000000..ddab2f1b26
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/shared/af_image.dart
@@ -0,0 +1,62 @@
+import 'dart:io';
+
+import 'package:flutter/material.dart';
+
+import 'package:appflowy/shared/appflowy_network_image.dart';
+import 'package:appflowy_backend/protobuf/flowy-database2/file_entities.pbenum.dart';
+import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pb.dart';
+
+class AFImage extends StatelessWidget {
+ const AFImage({
+ super.key,
+ required this.url,
+ required this.uploadType,
+ this.height,
+ this.width,
+ this.fit = BoxFit.cover,
+ this.userProfile,
+ }) : assert(
+ uploadType != FileUploadTypePB.CloudFile || userProfile != null,
+ 'userProfile must be provided for accessing files from AF Cloud',
+ );
+
+ final String url;
+ final FileUploadTypePB uploadType;
+ final double? height;
+ final double? width;
+ final BoxFit fit;
+ final UserProfilePB? userProfile;
+
+ @override
+ Widget build(BuildContext context) {
+ if (uploadType == FileUploadTypePB.CloudFile && userProfile == null) {
+ return const SizedBox.shrink();
+ }
+
+ Widget child;
+ if (uploadType == FileUploadTypePB.NetworkFile) {
+ child = Image.network(
+ url,
+ height: height,
+ width: width,
+ fit: fit,
+ );
+ } else if (uploadType == FileUploadTypePB.LocalFile) {
+ child = Image.file(
+ File(url),
+ height: height,
+ width: width,
+ fit: fit,
+ );
+ } else {
+ child = FlowyNetworkImage(
+ url: url,
+ userProfilePB: userProfile,
+ height: height,
+ width: width,
+ );
+ }
+
+ return child;
+ }
+}
diff --git a/frontend/resources/translations/en.json b/frontend/resources/translations/en.json
index 77d02adfab..35a48bf0b8 100644
--- a/frontend/resources/translations/en.json
+++ b/frontend/resources/translations/en.json
@@ -1596,6 +1596,7 @@
"back": "Back",
"saveToGallery": "Save to gallery",
"removeIcon": "Remove icon",
+ "removeCover": "Remove cover",
"pasteImageUrl": "Paste image URL",
"or": "OR",
"pickFromFiles": "Pick from files",
diff --git a/frontend/rust-lib/event-integration-test/tests/database/local_test/test.rs b/frontend/rust-lib/event-integration-test/tests/database/local_test/test.rs
index ac3d30ddbc..a1f5b1f8e8 100644
--- a/frontend/rust-lib/event-integration-test/tests/database/local_test/test.rs
+++ b/frontend/rust-lib/event-integration-test/tests/database/local_test/test.rs
@@ -266,7 +266,7 @@ async fn update_row_meta_event_with_url_test() {
id: database.rows[0].id.clone(),
view_id: grid_view.id.clone(),
icon_url: Some("icon_url".to_owned()),
- cover_url: None,
+ cover: None,
is_document_empty: None,
attachment_count: None,
};
@@ -296,7 +296,7 @@ async fn update_row_meta_event_with_cover_test() {
id: database.rows[0].id.clone(),
view_id: grid_view.id.clone(),
icon_url: Some("cover url".to_owned()),
- cover_url: None,
+ cover: None,
is_document_empty: None,
attachment_count: None,
};
diff --git a/frontend/rust-lib/flowy-database2/src/entities/database_entities.rs b/frontend/rust-lib/flowy-database2/src/entities/database_entities.rs
index 688e878caa..6be48c856c 100644
--- a/frontend/rust-lib/flowy-database2/src/entities/database_entities.rs
+++ b/frontend/rust-lib/flowy-database2/src/entities/database_entities.rs
@@ -155,6 +155,7 @@ impl TryInto<MoveRowParams> for MoveRowPayloadPB {
})
}
}
+
#[derive(Debug, Clone, Default, ProtoBuf)]
pub struct MoveGroupRowPayloadPB {
#[pb(index = 1)]
@@ -323,3 +324,31 @@ pub struct DatabaseSnapshotPB {
#[pb(index = 4)]
pub data: Vec<u8>,
}
+
+#[derive(Debug, Clone, Default, ProtoBuf)]
+pub struct RemoveCoverPayloadPB {
+ #[pb(index = 1)]
+ pub view_id: String,
+
+ #[pb(index = 2)]
+ pub row_id: String,
+}
+
+pub struct RemoveCoverParams {
+ pub view_id: String,
+ pub row_id: RowId,
+}
+
+impl TryInto<RemoveCoverParams> for RemoveCoverPayloadPB {
+ type Error = ErrorCode;
+
+ fn try_into(self) -> Result<RemoveCoverParams, Self::Error> {
+ let view_id = NotEmptyStr::parse(self.view_id).map_err(|_| ErrorCode::DatabaseViewIdIsEmpty)?;
+ let row_id = NotEmptyStr::parse(self.row_id).map_err(|_| ErrorCode::RowIdIsEmpty)?;
+
+ Ok(RemoveCoverParams {
+ view_id: view_id.0,
+ row_id: RowId::from(row_id.0),
+ })
+ }
+}
diff --git a/frontend/rust-lib/flowy-database2/src/entities/file_entities.rs b/frontend/rust-lib/flowy-database2/src/entities/file_entities.rs
new file mode 100644
index 0000000000..191d4bb614
--- /dev/null
+++ b/frontend/rust-lib/flowy-database2/src/entities/file_entities.rs
@@ -0,0 +1,32 @@
+use collab_database::entity::FileUploadType;
+use flowy_derive::ProtoBuf_Enum;
+use serde::{Deserialize, Serialize};
+
+#[derive(Debug, Default, Clone, ProtoBuf_Enum, PartialEq, Eq, Copy, Serialize, Deserialize)]
+#[repr(u8)]
+pub enum FileUploadTypePB {
+ #[default]
+ LocalFile = 0,
+ NetworkFile = 1,
+ CloudFile = 2,
+}
+
+impl From<FileUploadType> for FileUploadTypePB {
+ fn from(data: FileUploadType) -> Self {
+ match data {
+ FileUploadType::LocalFile => FileUploadTypePB::LocalFile,
+ FileUploadType::NetworkFile => FileUploadTypePB::NetworkFile,
+ FileUploadType::CloudFile => FileUploadTypePB::CloudFile,
+ }
+ }
+}
+
+impl From<FileUploadTypePB> for FileUploadType {
+ fn from(data: FileUploadTypePB) -> Self {
+ match data {
+ FileUploadTypePB::LocalFile => FileUploadType::LocalFile,
+ FileUploadTypePB::NetworkFile => FileUploadType::NetworkFile,
+ FileUploadTypePB::CloudFile => FileUploadType::CloudFile,
+ }
+ }
+}
diff --git a/frontend/rust-lib/flowy-database2/src/entities/mod.rs b/frontend/rust-lib/flowy-database2/src/entities/mod.rs
index 6bacbd0539..56a9769b7a 100644
--- a/frontend/rust-lib/flowy-database2/src/entities/mod.rs
+++ b/frontend/rust-lib/flowy-database2/src/entities/mod.rs
@@ -5,6 +5,7 @@ mod cell_entities;
mod database_entities;
mod field_entities;
mod field_settings_entities;
+pub mod file_entities;
pub mod filter_entities;
mod group_entities;
pub mod parser;
@@ -26,6 +27,7 @@ pub use cell_entities::*;
pub use database_entities::*;
pub use field_entities::*;
pub use field_settings_entities::*;
+pub use file_entities::*;
pub use filter_entities::*;
pub use group_entities::*;
pub use position_entities::*;
diff --git a/frontend/rust-lib/flowy-database2/src/entities/row_entities.rs b/frontend/rust-lib/flowy-database2/src/entities/row_entities.rs
index 9384503fb5..f638ae5b02 100644
--- a/frontend/rust-lib/flowy-database2/src/entities/row_entities.rs
+++ b/frontend/rust-lib/flowy-database2/src/entities/row_entities.rs
@@ -13,6 +13,8 @@ use crate::entities::parser::NotEmptyStr;
use crate::entities::position_entities::OrderObjectPositionPB;
use crate::services::database::{InsertedRow, UpdatedRow};
+use super::FileUploadTypePB;
+
/// [RowPB] Describes a row. Has the id of the parent Block. Has the metadata of the row.
#[derive(Debug, Default, Clone, ProtoBuf, Eq, PartialEq)]
pub struct RowPB {
@@ -66,6 +68,36 @@ pub struct RowMetaPB {
#[pb(index = 5, one_of)]
pub attachment_count: Option<i64>,
+
+ #[pb(index = 6, one_of)]
+ pub cover: Option<RowCoverPB>,
+}
+
+#[derive(Debug, Default, Clone, ProtoBuf, Serialize, Deserialize)]
+pub struct RowCoverPB {
+ #[pb(index = 1)]
+ pub url: String,
+
+ #[pb(index = 2)]
+ pub upload_type: FileUploadTypePB,
+}
+
+impl From<RowCoverPB> for RowCover {
+ fn from(data: RowCoverPB) -> Self {
+ Self {
+ url: data.url,
+ upload_type: data.upload_type.into(),
+ }
+ }
+}
+
+impl From<RowCover> for RowCoverPB {
+ fn from(data: RowCover) -> Self {
+ Self {
+ url: data.url,
+ upload_type: data.upload_type.into(),
+ }
+ }
}
#[derive(Debug, Default, ProtoBuf)]
@@ -82,6 +114,7 @@ impl From<RowOrder> for RowMetaPB {
icon: None,
is_document_empty: None,
attachment_count: None,
+ cover: None,
}
}
}
@@ -92,6 +125,7 @@ impl From<&Row> for RowMetaPB {
id: data.id.clone().into_inner(),
document_id: None,
icon: None,
+ cover: None,
is_document_empty: None,
attachment_count: None,
}
@@ -106,6 +140,7 @@ impl From<Row> for RowMetaPB {
icon: None,
is_document_empty: None,
attachment_count: None,
+ cover: None,
}
}
}
@@ -114,10 +149,11 @@ impl From<RowDetail> for RowMetaPB {
fn from(row_detail: RowDetail) -> Self {
Self {
id: row_detail.row.id.to_string(),
- document_id: Some(row_detail.document_id),
- icon: row_detail.meta.icon_url,
+ document_id: Some(row_detail.document_id.clone()),
+ icon: row_detail.meta.icon_url.clone(),
is_document_empty: Some(row_detail.meta.is_document_empty),
attachment_count: Some(row_detail.meta.attachment_count),
+ cover: row_detail.meta.cover.map(|cover| cover.into()),
}
}
}
@@ -130,10 +166,10 @@ impl From<&RowDetail> for RowMetaPB {
icon: row_detail.meta.icon_url.clone(),
is_document_empty: Some(row_detail.meta.is_document_empty),
attachment_count: Some(row_detail.meta.attachment_count),
+ cover: row_detail.meta.clone().cover.map(|cover| cover.into()),
}
}
}
-//
#[derive(Debug, Default, Clone, ProtoBuf)]
pub struct UpdateRowMetaChangesetPB {
@@ -147,7 +183,7 @@ pub struct UpdateRowMetaChangesetPB {
pub icon_url: Option<String>,
#[pb(index = 4, one_of)]
- pub cover_url: Option<String>,
+ pub cover: Option<RowCoverPB>,
#[pb(index = 5, one_of)]
pub is_document_empty: Option<bool>,
@@ -156,7 +192,7 @@ pub struct UpdateRowMetaChangesetPB {
pub attachment_count: Option<i64>,
}
-#[derive(Debug)]
+#[derive(Debug, Default)]
pub struct UpdateRowMetaParams {
pub id: String,
pub view_id: String,
@@ -181,7 +217,7 @@ impl TryInto<UpdateRowMetaParams> for UpdateRowMetaChangesetPB {
id: row_id,
view_id,
icon_url: self.icon_url,
- cover: None,
+ cover: self.cover.map(|cover| cover.into()),
is_document_empty: self.is_document_empty,
attachment_count: self.attachment_count,
})
diff --git a/frontend/rust-lib/flowy-database2/src/entities/type_option_entities/media_entities.rs b/frontend/rust-lib/flowy-database2/src/entities/type_option_entities/media_entities.rs
index fd8ed9d95b..1395731d6e 100644
--- a/frontend/rust-lib/flowy-database2/src/entities/type_option_entities/media_entities.rs
+++ b/frontend/rust-lib/flowy-database2/src/entities/type_option_entities/media_entities.rs
@@ -1,8 +1,8 @@
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
use crate::{
- entities::CellIdPB,
- services::field::{MediaCellData, MediaFile, MediaFileType, MediaUploadType},
+ entities::{CellIdPB, FileUploadTypePB},
+ services::field::{MediaCellData, MediaFile, MediaFileType},
};
#[derive(Debug, Clone, Default, ProtoBuf)]
@@ -48,41 +48,12 @@ pub struct MediaFilePB {
pub url: String,
#[pb(index = 4)]
- pub upload_type: MediaUploadTypePB,
+ pub upload_type: FileUploadTypePB,
#[pb(index = 5)]
pub file_type: MediaFileTypePB,
}
-#[derive(Debug, Clone, Default, PartialEq, Eq, ProtoBuf_Enum)]
-#[repr(u8)]
-pub enum MediaUploadTypePB {
- #[default]
- LocalMedia = 0,
- NetworkMedia = 1,
- CloudMedia = 2,
-}
-
-impl From<MediaUploadType> for MediaUploadTypePB {
- fn from(data: MediaUploadType) -> Self {
- match data {
- MediaUploadType::LocalMedia => MediaUploadTypePB::LocalMedia,
- MediaUploadType::NetworkMedia => MediaUploadTypePB::NetworkMedia,
- MediaUploadType::CloudMedia => MediaUploadTypePB::CloudMedia,
- }
- }
-}
-
-impl From<MediaUploadTypePB> for MediaUploadType {
- fn from(data: MediaUploadTypePB) -> Self {
- match data {
- MediaUploadTypePB::LocalMedia => MediaUploadType::LocalMedia,
- MediaUploadTypePB::NetworkMedia => MediaUploadType::NetworkMedia,
- MediaUploadTypePB::CloudMedia => MediaUploadType::CloudMedia,
- }
- }
-}
-
#[derive(Debug, Clone, Default, PartialEq, Eq, ProtoBuf_Enum)]
#[repr(u8)]
pub enum MediaFileTypePB {
diff --git a/frontend/rust-lib/flowy-database2/src/event_handler.rs b/frontend/rust-lib/flowy-database2/src/event_handler.rs
index 7f6c5cce3d..b2d17869eb 100644
--- a/frontend/rust-lib/flowy-database2/src/event_handler.rs
+++ b/frontend/rust-lib/flowy-database2/src/event_handler.rs
@@ -1,4 +1,4 @@
-use collab_database::rows::{Cell, RowId};
+use collab_database::rows::{Cell, RowCover, RowId};
use lib_infra::box_any::BoxAny;
use std::sync::{Arc, Weak};
use tokio::sync::oneshot;
@@ -525,6 +525,31 @@ pub(crate) async fn move_row_handler(
Ok(())
}
+#[tracing::instrument(level = "debug", skip(data, manager), err)]
+pub(crate) async fn remove_cover_handler(
+ data: AFPluginData<RemoveCoverPayloadPB>,
+ manager: AFPluginState<Weak<DatabaseManager>>,
+) -> Result<(), FlowyError> {
+ let manager = upgrade_manager(manager)?;
+ let params: RemoveCoverParams = data.into_inner().try_into()?;
+ let database_editor = manager
+ .get_database_editor_with_view_id(&params.view_id)
+ .await?;
+
+ let update_row_changeset = UpdateRowMetaParams {
+ id: params.row_id.clone().into(),
+ view_id: params.view_id.clone(),
+ cover: Some(RowCover::default()),
+ ..Default::default()
+ };
+
+ database_editor
+ .update_row_meta(&params.row_id, update_row_changeset)
+ .await;
+
+ Ok(())
+}
+
#[tracing::instrument(level = "debug", skip(data, manager), err)]
pub(crate) async fn create_row_handler(
data: AFPluginData<CreateRowPayloadPB>,
@@ -1298,7 +1323,12 @@ pub(crate) async fn update_media_cell_handler(
let params: MediaCellChangesetPB = data.into_inner();
let cell_id: CellIdParams = params.cell_id.try_into()?;
let cell_changeset = MediaCellChangeset {
- inserted_files: params.inserted_files.into_iter().map(Into::into).collect(),
+ inserted_files: params
+ .inserted_files
+ .clone()
+ .into_iter()
+ .map(Into::into)
+ .collect(),
removed_ids: params.removed_ids,
};
@@ -1314,6 +1344,33 @@ pub(crate) async fn update_media_cell_handler(
BoxAny::new(cell_changeset),
)
.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 {
+ url: file.url.clone(),
+ upload_type: file.upload_type.into(),
+ }),
+ ..UpdateRowMetaParams::default()
+ };
+
+ database_editor
+ .update_row_meta(&cell_id.row_id, update_row_meta)
+ .await;
+ }
+ }
+
Ok(())
}
diff --git a/frontend/rust-lib/flowy-database2/src/event_map.rs b/frontend/rust-lib/flowy-database2/src/event_map.rs
index 5bd9cf6f33..6281cde745 100644
--- a/frontend/rust-lib/flowy-database2/src/event_map.rs
+++ b/frontend/rust-lib/flowy-database2/src/event_map.rs
@@ -41,6 +41,7 @@ pub fn init(database_manager: Weak<DatabaseManager>) -> AFPlugin {
.event(DatabaseEvent::DeleteRows, delete_rows_handler)
.event(DatabaseEvent::DuplicateRow, duplicate_row_handler)
.event(DatabaseEvent::MoveRow, move_row_handler)
+ .event(DatabaseEvent::RemoveCover, remove_cover_handler)
// Cell
.event(DatabaseEvent::GetCell, get_cell_handler)
.event(DatabaseEvent::UpdateCell, update_cell_handler)
@@ -244,6 +245,9 @@ pub enum DatabaseEvent {
#[event(input = "UpdateRowMetaChangesetPB")]
UpdateRowMeta = 56,
+ #[event(input = "RemoveCoverPayloadPB")]
+ RemoveCover = 57,
+
#[event(input = "CellIdPB", output = "CellPB")]
GetCell = 70,
diff --git a/frontend/rust-lib/flowy-database2/src/services/database/database_editor.rs b/frontend/rust-lib/flowy-database2/src/services/database/database_editor.rs
index 9247701961..69d1e1abf3 100644
--- a/frontend/rust-lib/flowy-database2/src/services/database/database_editor.rs
+++ b/frontend/rust-lib/flowy-database2/src/services/database/database_editor.rs
@@ -822,6 +822,7 @@ impl DatabaseEditor {
icon: row_meta.icon_url,
is_document_empty: Some(row_meta.is_document_empty),
attachment_count: Some(row_meta.attachment_count),
+ cover: row_meta.cover.map(|cover| cover.into()),
})
} else {
warn!(
diff --git a/frontend/rust-lib/flowy-database2/src/services/field/type_options/media_type_option/media_file.rs b/frontend/rust-lib/flowy-database2/src/services/field/type_options/media_type_option/media_file.rs
index affda5a98f..b4a24febb6 100644
--- a/frontend/rust-lib/flowy-database2/src/services/field/type_options/media_type_option/media_file.rs
+++ b/frontend/rust-lib/flowy-database2/src/services/field/type_options/media_type_option/media_file.rs
@@ -1,7 +1,59 @@
use std::fmt::{Display, Formatter};
+use collab_database::entity::FileUploadType;
use serde::{Deserialize, Serialize};
+use crate::entities::FileUploadTypePB;
+
+#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
+#[repr(u8)]
+pub enum MediaUploadType {
+ #[default]
+ LocalMedia = 0,
+ NetworkMedia = 1,
+ CloudMedia = 2,
+}
+
+impl From<MediaUploadType> for FileUploadTypePB {
+ fn from(media_upload_type: MediaUploadType) -> Self {
+ match media_upload_type {
+ MediaUploadType::LocalMedia => FileUploadTypePB::LocalFile,
+ MediaUploadType::NetworkMedia => FileUploadTypePB::NetworkFile,
+ MediaUploadType::CloudMedia => FileUploadTypePB::CloudFile,
+ }
+ }
+}
+
+impl From<FileUploadTypePB> for MediaUploadType {
+ fn from(file_upload_type: FileUploadTypePB) -> Self {
+ match file_upload_type {
+ FileUploadTypePB::LocalFile => MediaUploadType::LocalMedia,
+ FileUploadTypePB::NetworkFile => MediaUploadType::NetworkMedia,
+ FileUploadTypePB::CloudFile => MediaUploadType::CloudMedia,
+ }
+ }
+}
+
+impl From<MediaUploadType> for FileUploadType {
+ fn from(media_upload_type: MediaUploadType) -> Self {
+ match media_upload_type {
+ MediaUploadType::LocalMedia => FileUploadType::LocalFile,
+ MediaUploadType::NetworkMedia => FileUploadType::NetworkFile,
+ MediaUploadType::CloudMedia => FileUploadType::CloudFile,
+ }
+ }
+}
+
+impl From<FileUploadType> for MediaUploadType {
+ fn from(file_upload_type: FileUploadType) -> Self {
+ match file_upload_type {
+ FileUploadType::LocalFile => MediaUploadType::LocalMedia,
+ FileUploadType::NetworkFile => MediaUploadType::NetworkMedia,
+ FileUploadType::CloudFile => MediaUploadType::CloudMedia,
+ }
+ }
+}
+
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct MediaFile {
pub id: String,
@@ -33,15 +85,6 @@ impl Display for MediaFile {
}
}
-#[derive(PartialEq, Eq, Serialize, Deserialize, Debug, Default, Clone)]
-#[repr(u8)]
-pub enum MediaUploadType {
- #[default]
- LocalMedia = 0,
- NetworkMedia = 1,
- CloudMedia = 2,
-}
-
#[derive(PartialEq, Eq, Serialize, Deserialize, Debug, Default, Clone)]
#[repr(u8)]
pub enum MediaFileType {