mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: error message should persist on the image block (#4710)
This commit is contained in:
parent
fa3bc97698
commit
236b5bfe90
@ -45,6 +45,7 @@ class ImagePlaceholderState extends State<ImagePlaceholder> {
|
|||||||
late final editorState = context.read<EditorState>();
|
late final editorState = context.read<EditorState>();
|
||||||
|
|
||||||
bool showLoading = false;
|
bool showLoading = false;
|
||||||
|
String? errorMessage;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -67,19 +68,7 @@ class ImagePlaceholderState extends State<ImagePlaceholder> {
|
|||||||
size: Size.square(24),
|
size: Size.square(24),
|
||||||
),
|
),
|
||||||
const HSpace(10),
|
const HSpace(10),
|
||||||
...showLoading
|
..._buildTrailing(context),
|
||||||
? [
|
|
||||||
FlowyText(
|
|
||||||
LocaleKeys.document_imageBlock_imageIsUploading.tr(),
|
|
||||||
),
|
|
||||||
const HSpace(8),
|
|
||||||
const CircularProgressIndicator.adaptive(),
|
|
||||||
]
|
|
||||||
: [
|
|
||||||
FlowyText(
|
|
||||||
LocaleKeys.document_plugins_image_addAnImage.tr(),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -136,6 +125,30 @@ class ImagePlaceholderState extends State<ImagePlaceholder> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<Widget> _buildTrailing(BuildContext context) {
|
||||||
|
if (errorMessage != null) {
|
||||||
|
return [
|
||||||
|
FlowyText(
|
||||||
|
'${LocaleKeys.document_plugins_image_imageUploadFailed.tr()}: ${errorMessage!}',
|
||||||
|
),
|
||||||
|
];
|
||||||
|
} else if (showLoading) {
|
||||||
|
return [
|
||||||
|
FlowyText(
|
||||||
|
LocaleKeys.document_imageBlock_imageIsUploading.tr(),
|
||||||
|
),
|
||||||
|
const HSpace(8),
|
||||||
|
const CircularProgressIndicator.adaptive(),
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
return [
|
||||||
|
FlowyText(
|
||||||
|
LocaleKeys.document_plugins_image_addAnImage.tr(),
|
||||||
|
),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void showUploadImageMenu() {
|
void showUploadImageMenu() {
|
||||||
if (PlatformExtension.isDesktopOrWeb) {
|
if (PlatformExtension.isDesktopOrWeb) {
|
||||||
controller.show();
|
controller.show();
|
||||||
@ -188,8 +201,13 @@ class ImagePlaceholderState extends State<ImagePlaceholder> {
|
|||||||
|
|
||||||
final size = url.fileSize;
|
final size = url.fileSize;
|
||||||
if (size == null || size > 10 * 1024 * 1024) {
|
if (size == null || size > 10 * 1024 * 1024) {
|
||||||
// show error
|
|
||||||
controller.close();
|
controller.close();
|
||||||
|
setState(() {
|
||||||
|
showLoading = false;
|
||||||
|
this.errorMessage =
|
||||||
|
LocaleKeys.document_imageBlock_uploadImageErrorImageSizeTooBig.tr();
|
||||||
|
});
|
||||||
|
// show error
|
||||||
showSnackBarMessage(
|
showSnackBarMessage(
|
||||||
context,
|
context,
|
||||||
LocaleKeys.document_imageBlock_uploadImageErrorImageSizeTooBig.tr(),
|
LocaleKeys.document_imageBlock_uploadImageErrorImageSizeTooBig.tr(),
|
||||||
@ -210,10 +228,12 @@ class ImagePlaceholderState extends State<ImagePlaceholder> {
|
|||||||
// else we should save the image to cloud storage
|
// else we should save the image to cloud storage
|
||||||
setState(() {
|
setState(() {
|
||||||
showLoading = true;
|
showLoading = true;
|
||||||
|
this.errorMessage = null;
|
||||||
});
|
});
|
||||||
(path, errorMessage) = await saveImageToCloudStorage(url);
|
(path, errorMessage) = await saveImageToCloudStorage(url);
|
||||||
setState(() {
|
setState(() {
|
||||||
showLoading = false;
|
showLoading = false;
|
||||||
|
this.errorMessage = errorMessage;
|
||||||
});
|
});
|
||||||
imageType = CustomImageType.internal;
|
imageType = CustomImageType.internal;
|
||||||
}
|
}
|
||||||
@ -225,6 +245,9 @@ class ImagePlaceholderState extends State<ImagePlaceholder> {
|
|||||||
? LocaleKeys.document_imageBlock_error_invalidImage.tr()
|
? LocaleKeys.document_imageBlock_error_invalidImage.tr()
|
||||||
: ': $errorMessage',
|
: ': $errorMessage',
|
||||||
);
|
);
|
||||||
|
setState(() {
|
||||||
|
this.errorMessage = errorMessage;
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -786,7 +786,8 @@
|
|||||||
},
|
},
|
||||||
"image": {
|
"image": {
|
||||||
"copiedToPasteBoard": "The image link has been copied to the clipboard",
|
"copiedToPasteBoard": "The image link has been copied to the clipboard",
|
||||||
"addAnImage": "Add an image"
|
"addAnImage": "Add an image",
|
||||||
|
"imageUploadFailed": "Image upload failed"
|
||||||
},
|
},
|
||||||
"urlPreview": {
|
"urlPreview": {
|
||||||
"copiedToPasteBoard": "The link has been copied to the clipboard"
|
"copiedToPasteBoard": "The link has been copied to the clipboard"
|
||||||
|
Loading…
Reference in New Issue
Block a user