fix: the desktop cover didn't sync with the mobile cover (#5252)

This commit is contained in:
Lucas.Xu 2024-05-03 09:12:49 +08:00 committed by GitHub
parent 2eb88821ca
commit 554c821db9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 53 additions and 39 deletions

View File

@ -2,6 +2,7 @@ import 'dart:io';
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';
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet.dart';
import 'package:appflowy/plugins/base/emoji/emoji_picker_screen.dart';
import 'package:appflowy/plugins/base/icon/icon_picker.dart';
@ -14,6 +15,7 @@ import 'package:appflowy/plugins/document/presentation/editor_plugins/image/uplo
import 'package:appflowy/plugins/document/presentation/editor_plugins/migration/editor_migration.dart';
import 'package:appflowy/plugins/document/presentation/editor_style.dart';
import 'package:appflowy/shared/appflowy_network_image.dart';
import 'package:appflowy/workspace/application/view/view_ext.dart';
import 'package:appflowy/workspace/application/view/view_listener.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:appflowy_editor/appflowy_editor.dart' hide UploadImageMenu;
@ -85,9 +87,12 @@ class _DocumentCoverWidgetState extends State<DocumentCoverWidget> {
widget.node.attributes[DocumentHeaderBlockKeys.coverDetails];
String? get icon => widget.node.attributes[DocumentHeaderBlockKeys.icon];
bool get hasIcon => viewIcon.isNotEmpty;
bool get hasCover => coverType != CoverType.none;
bool get hasCover =>
coverType != CoverType.none ||
cover?.type != PageStyleCoverImageType.none;
String viewIcon = '';
PageStyleCover? cover;
late final ViewListener viewListener;
@override
@ -95,6 +100,7 @@ class _DocumentCoverWidgetState extends State<DocumentCoverWidget> {
super.initState();
final value = widget.view.icon.value;
viewIcon = value.isNotEmpty ? value : icon ?? '';
cover = widget.view.cover;
widget.node.addListener(_reload);
viewListener = ViewListener(
viewId: widget.view.id,
@ -102,6 +108,7 @@ class _DocumentCoverWidgetState extends State<DocumentCoverWidget> {
onViewUpdated: (p0) {
setState(() {
viewIcon = p0.icon.value;
cover = p0.cover;
});
},
);

View File

@ -176,48 +176,55 @@ class EditorMigration {
root.attributes[DocumentHeaderBlockKeys.coverType],
);
final coverDetails = root.attributes[DocumentHeaderBlockKeys.coverDetails];
Map extra = {};
if (coverType == CoverType.none ||
coverDetails == null ||
coverDetails is! String) {
return;
}
Map extra = {};
switch (coverType) {
case CoverType.asset:
// The new version does not support the asset cover.
break;
case CoverType.color:
extra = {
ViewExtKeys.coverKey: {
ViewExtKeys.coverTypeKey:
PageStyleCoverImageType.pureColor.toString(),
ViewExtKeys.coverValueKey: coverDetails,
},
};
break;
case CoverType.file:
if (isURL(coverDetails)) {
if (coverDetails.contains('unsplash')) {
extra = {
ViewExtKeys.coverKey: {
ViewExtKeys.coverTypeKey:
PageStyleCoverImageType.unsplashImage.toString(),
ViewExtKeys.coverValueKey: coverDetails,
},
};
} else {
extra = {
ViewExtKeys.coverKey: {
ViewExtKeys.coverTypeKey:
PageStyleCoverImageType.customImage.toString(),
ViewExtKeys.coverValueKey: coverDetails,
},
};
extra = {
ViewExtKeys.coverKey: {
ViewExtKeys.coverTypeKey: PageStyleCoverImageType.none.toString(),
ViewExtKeys.coverValueKey: '',
},
};
} else {
switch (coverType) {
case CoverType.asset:
// The new version does not support the asset cover.
break;
case CoverType.color:
extra = {
ViewExtKeys.coverKey: {
ViewExtKeys.coverTypeKey:
PageStyleCoverImageType.pureColor.toString(),
ViewExtKeys.coverValueKey: coverDetails,
},
};
break;
case CoverType.file:
if (isURL(coverDetails)) {
if (coverDetails.contains('unsplash')) {
extra = {
ViewExtKeys.coverKey: {
ViewExtKeys.coverTypeKey:
PageStyleCoverImageType.unsplashImage.toString(),
ViewExtKeys.coverValueKey: coverDetails,
},
};
} else {
extra = {
ViewExtKeys.coverKey: {
ViewExtKeys.coverTypeKey:
PageStyleCoverImageType.customImage.toString(),
ViewExtKeys.coverValueKey: coverDetails,
},
};
}
}
}
break;
default:
break;
default:
}
}
if (extra.isEmpty) {