Skip to content

Commit

Permalink
Merge branch 'feat/1.4.2/ui' into test
Browse files Browse the repository at this point in the history
  • Loading branch information
shuashuai committed Nov 22, 2024
2 parents 3a795b2 + ab30cdf commit 85f792f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 21 deletions.
3 changes: 3 additions & 0 deletions ui/src/components/Editor/ToolBars/file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ const Image = ({ editorInstance }) => {
editor.replaceRange('', startPos, endPos);
editor.replaceSelection(text);
})
.catch(() => {
editor.replaceRange('', startPos, endPos);
})
.finally(() => {
editor.setReadOnly(false);
editor.focus();
Expand Down
36 changes: 23 additions & 13 deletions ui/src/components/Editor/ToolBars/image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,14 @@ const Image = ({ editorInstance }) => {

editor.replaceSelection(loadingText);
editor.setReadOnly(true);
const urls = await upload(fileList).catch((ex) => {
console.error('upload file error: ', ex);
});
const urls = await upload(fileList)
.catch(() => {
editor.replaceRange('', startPos, endPos);
})
.finally(() => {
editor.setReadOnly(false);
editor.focus();
});

const text: string[] = [];
if (Array.isArray(urls)) {
Expand All @@ -183,8 +188,6 @@ const Image = ({ editorInstance }) => {
} else {
editor.replaceRange('', startPos, endPos);
}
editor.setReadOnly(false);
editor.focus();
};

const paste = async (event) => {
Expand All @@ -199,14 +202,21 @@ const Image = ({ editorInstance }) => {

editor.replaceSelection(loadingText);
editor.setReadOnly(true);
const urls = await upload(clipboard.files);
const text = urls.map(({ name, url, type }) => {
return `${type === 'post' ? '!' : ''}[${name}](${url})`;
});

editor.replaceRange(text.join('\n'), startPos, endPos);
editor.setReadOnly(false);
editor.focus();
upload(clipboard.files)
.then((urls) => {
const text = urls.map(({ name, url, type }) => {
return `${type === 'post' ? '!' : ''}[${name}](${url})`;
});

editor.replaceRange(text.join('\n'), startPos, endPos);
})
.catch(() => {
editor.replaceRange('', startPos, endPos);
})
.finally(() => {
editor.setReadOnly(false);
editor.focus();
});

return;
}
Expand Down
26 changes: 18 additions & 8 deletions ui/src/pages/Admin/Write/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,12 @@ const Index: FC = () => {
max_image_size: Number(formData.max_image_size.value),
max_attachment_size: Number(formData.max_attachment_size.value),
max_image_megapixel: Number(formData.max_image_megapixel.value),
authorized_image_extensions: formData.authorized_image_extensions.value
.split(',')
?.map((item) => item.trim().toLowerCase()),
authorized_image_extensions:
formData.authorized_image_extensions.value.length > 0
? formData.authorized_image_extensions.value
.split(',')
?.map((item) => item.trim().toLowerCase())
: [],
authorized_attachment_extensions:
formData.authorized_attachment_extensions.value.length > 0
? formData.authorized_attachment_extensions.value
Expand Down Expand Up @@ -287,11 +290,12 @@ const Index: FC = () => {
</Form.Control.Feedback>
</Form.Group>

<Form.Group className="mb-3" controlId="image_size">
<Form.Group className="mb-3" controlId="max_image_size">
<Form.Label>{t('image_size.label')}</Form.Label>
<Form.Control
type="number"
value={formData.max_image_size.value}
isInvalid={formData.max_image_size.isInvalid}
onChange={(evt) => {
handleValueChange({
max_image_size: {
Expand All @@ -308,11 +312,12 @@ const Index: FC = () => {
</Form.Control.Feedback>
</Form.Group>

<Form.Group className="mb-3" controlId="attachment_size">
<Form.Group className="mb-3" controlId="max_attachment_size">
<Form.Label>{t('attachment_size.label')}</Form.Label>
<Form.Control
type="number"
value={formData.max_attachment_size.value}
isInvalid={formData.max_attachment_size.isInvalid}
onChange={(evt) => {
handleValueChange({
max_attachment_size: {
Expand All @@ -329,10 +334,11 @@ const Index: FC = () => {
</Form.Control.Feedback>
</Form.Group>

<Form.Group className="mb-3" controlId="image_megapixels">
<Form.Group className="mb-3" controlId="max_image_megapixel">
<Form.Label>{t('image_megapixels.label')}</Form.Label>
<Form.Control
type="number"
isInvalid={formData.max_image_megapixel.isInvalid}
value={formData.max_image_megapixel.value}
onChange={(evt) => {
handleValueChange({
Expand All @@ -350,11 +356,12 @@ const Index: FC = () => {
</Form.Control.Feedback>
</Form.Group>

<Form.Group className="mb-3" controlId="image_extensions">
<Form.Group className="mb-3" controlId="authorized_image_extensions">
<Form.Label>{t('image_extensions.label')}</Form.Label>
<Form.Control
type="text"
value={formData.authorized_image_extensions.value}
isInvalid={formData.authorized_image_extensions.isInvalid}
onChange={(evt) => {
handleValueChange({
authorized_image_extensions: {
Expand All @@ -371,11 +378,14 @@ const Index: FC = () => {
</Form.Control.Feedback>
</Form.Group>

<Form.Group className="mb-3" controlId="attachment_extensions">
<Form.Group
className="mb-3"
controlId="authorized_attachment_extensions">
<Form.Label>{t('attachment_extensions.label')}</Form.Label>
<Form.Control
type="text"
value={formData.authorized_attachment_extensions.value}
isInvalid={formData.authorized_attachment_extensions.isInvalid}
onChange={(evt) => {
handleValueChange({
authorized_attachment_extensions: {
Expand Down

0 comments on commit 85f792f

Please sign in to comment.