@pushwoosh/smart-components-kit 1.2.2 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -11,6 +11,11 @@ import { formatBytes, getRatioLabel, getThumbUrl } from './mediaFile.utils';
|
|
|
11
11
|
import { useLang } from './polyglot';
|
|
12
12
|
import { CropBadge, Dropzone, EmptyState, Grid, HiddenInput, Tile, TileActions, TileImage, UsageLine } from './styled';
|
|
13
13
|
const UPLOAD_PATH = '/api/media/upload';
|
|
14
|
+
const ALLOWED_IMAGE_EXTENSIONS = ['.jpg', '.jpeg', '.png', '.gif', '.webp'];
|
|
15
|
+
const isAllowedImage = file => {
|
|
16
|
+
const name = file.name.toLowerCase();
|
|
17
|
+
return ALLOWED_IMAGE_EXTENSIONS.some(ext => name.endsWith(ext));
|
|
18
|
+
};
|
|
14
19
|
/**
|
|
15
20
|
* Controlled media gallery: the parent owns the current page (and page size)
|
|
16
21
|
* and is notified of navigation via `onPageChange`. For a self-contained
|
|
@@ -117,7 +122,19 @@ export const MediaStorage = ({
|
|
|
117
122
|
};
|
|
118
123
|
}, [listAsync.value, rpcGateway, application]);
|
|
119
124
|
const uploadFiles = async selected => {
|
|
120
|
-
|
|
125
|
+
if (selected.length === 0) return;
|
|
126
|
+
const images = selected.filter(isAllowedImage);
|
|
127
|
+
if (selected.some(file => !isAllowedImage(file))) {
|
|
128
|
+
openToast({
|
|
129
|
+
title: lang({
|
|
130
|
+
message: 'SMART.MEDIA_STORAGE.UNSUPPORTED_FORMAT'
|
|
131
|
+
}),
|
|
132
|
+
type: 'error'
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
if (uploadInputRef.current) {
|
|
136
|
+
uploadInputRef.current.value = '';
|
|
137
|
+
}
|
|
121
138
|
if (images.length === 0) return;
|
|
122
139
|
setIsUploading(true);
|
|
123
140
|
try {
|
|
@@ -158,9 +175,6 @@ export const MediaStorage = ({
|
|
|
158
175
|
});
|
|
159
176
|
}
|
|
160
177
|
} finally {
|
|
161
|
-
if (uploadInputRef.current) {
|
|
162
|
-
uploadInputRef.current.value = '';
|
|
163
|
-
}
|
|
164
178
|
setIsUploading(false);
|
|
165
179
|
}
|
|
166
180
|
};
|
|
@@ -223,7 +237,7 @@ export const MediaStorage = ({
|
|
|
223
237
|
}), _jsx(HiddenInput, {
|
|
224
238
|
ref: uploadInputRef,
|
|
225
239
|
type: "file",
|
|
226
|
-
accept:
|
|
240
|
+
accept: ALLOWED_IMAGE_EXTENSIONS.join(','),
|
|
227
241
|
multiple: true,
|
|
228
242
|
onChange: event => void uploadFiles(Array.from(event.target.files ?? []))
|
|
229
243
|
}), loading && _jsx(EmptyState, {
|
|
@@ -8,6 +8,7 @@ export const messages = {
|
|
|
8
8
|
'SMART.MEDIA_STORAGE.NEXT_BUTTON': 'Next',
|
|
9
9
|
'SMART.MEDIA_STORAGE.LOAD_ERROR': 'Failed to load media files',
|
|
10
10
|
'SMART.MEDIA_STORAGE.UPLOAD_ERROR': 'Failed to upload image',
|
|
11
|
+
'SMART.MEDIA_STORAGE.UNSUPPORTED_FORMAT': 'Unsupported format. Use JPEG, PNG, GIF or WebP',
|
|
11
12
|
'SMART.MEDIA_STORAGE.UPLOAD_SUCCESS': 'Image uploaded',
|
|
12
13
|
'SMART.MEDIA_STORAGE.USAGE': '{{count}} files · {{size}}',
|
|
13
14
|
'SMART.MEDIA_STORAGE.CROPS_BADGE': '{{count}} cr.',
|
|
@@ -8,6 +8,7 @@ export const messages = {
|
|
|
8
8
|
'SMART.MEDIA_STORAGE.NEXT_BUTTON': 'Вперёд',
|
|
9
9
|
'SMART.MEDIA_STORAGE.LOAD_ERROR': 'Не удалось загрузить медиафайлы',
|
|
10
10
|
'SMART.MEDIA_STORAGE.UPLOAD_ERROR': 'Не удалось загрузить изображение',
|
|
11
|
+
'SMART.MEDIA_STORAGE.UNSUPPORTED_FORMAT': 'Неподдерживаемый формат. Используйте JPEG, PNG, GIF или WebP',
|
|
11
12
|
'SMART.MEDIA_STORAGE.UPLOAD_SUCCESS': 'Изображение загружено',
|
|
12
13
|
'SMART.MEDIA_STORAGE.USAGE': '{{count}} файлов · {{size}}',
|
|
13
14
|
'SMART.MEDIA_STORAGE.CROPS_BADGE': '{{count}} кр.',
|
|
@@ -9,6 +9,7 @@ export type MediaStorageMessages = {
|
|
|
9
9
|
'SMART.MEDIA_STORAGE.NEXT_BUTTON': NoParams;
|
|
10
10
|
'SMART.MEDIA_STORAGE.LOAD_ERROR': NoParams;
|
|
11
11
|
'SMART.MEDIA_STORAGE.UPLOAD_ERROR': NoParams;
|
|
12
|
+
'SMART.MEDIA_STORAGE.UNSUPPORTED_FORMAT': NoParams;
|
|
12
13
|
'SMART.MEDIA_STORAGE.UPLOAD_SUCCESS': NoParams;
|
|
13
14
|
'SMART.MEDIA_STORAGE.USAGE': {
|
|
14
15
|
count: number;
|
package/package.json
CHANGED