Desktop: drag and drop photos into the post form
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -50,13 +50,19 @@ export function useImageUpload(existingUrls = []) {
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [existingUrlsKey, hasUserSelected]);
|
||||
|
||||
const handleFileChange = useCallback(async (e) => {
|
||||
const files = Array.from(e.target.files || []);
|
||||
/**
|
||||
* Добавляет файлы к списку: проверка типа и размера, сжатие, превью.
|
||||
* Общая точка для выбора через <input type="file"> и перетаскивания (drop).
|
||||
*/
|
||||
const addFiles = useCallback(async (fileList) => {
|
||||
const files = Array.from(fileList || []);
|
||||
if (!files.length) return;
|
||||
setImgError("");
|
||||
|
||||
for (const file of files) {
|
||||
if (!file.type.startsWith("image/")) {
|
||||
// Сверяем с ACCEPT, а не с "image/*": у <input> тип отсекает окно выбора,
|
||||
// а при перетаскивании может прилететь что угодно (GIF, HEIC, SVG)
|
||||
if (!ACCEPT.split(",").includes(file.type)) {
|
||||
setImgError(t('imageUpload.invalidType'));
|
||||
return;
|
||||
}
|
||||
@@ -94,6 +100,8 @@ export function useImageUpload(existingUrls = []) {
|
||||
}
|
||||
}, [t]);
|
||||
|
||||
const handleFileChange = useCallback((e) => addFiles(e.target.files), [addFiles]);
|
||||
|
||||
const removeImage = useCallback((id) => {
|
||||
setImages(prev => {
|
||||
const img = prev.find(i => i.id === id);
|
||||
@@ -136,6 +144,7 @@ export function useImageUpload(existingUrls = []) {
|
||||
compressing,
|
||||
fileInputRef,
|
||||
handleFileChange,
|
||||
addFiles,
|
||||
removeImage,
|
||||
getFilesForUpload,
|
||||
getExistingUrlsToKeep,
|
||||
|
||||
Reference in New Issue
Block a user