Desktop: drag and drop profile photo; share drop-zone hook with post form
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -53,8 +53,12 @@ export function useImageUpload(existingUrls = []) {
|
||||
/**
|
||||
* Добавляет файлы к списку: проверка типа и размера, сжатие, превью.
|
||||
* Общая точка для выбора через <input type="file"> и перетаскивания (drop).
|
||||
*
|
||||
* replace — заменить текущие фото вместо добавления (одиночный аватар).
|
||||
* Старые фото снимаются только после успешной обработки новых: при ошибке
|
||||
* пользователь остаётся с прежним фото.
|
||||
*/
|
||||
const addFiles = useCallback(async (fileList) => {
|
||||
const addFiles = useCallback(async (fileList, { replace = false } = {}) => {
|
||||
const files = Array.from(fileList || []);
|
||||
if (!files.length) return;
|
||||
setImgError("");
|
||||
@@ -91,7 +95,13 @@ export function useImageUpload(existingUrls = []) {
|
||||
isExisting: false,
|
||||
serverUrl: null,
|
||||
}));
|
||||
setImages(prev => [...prev, ...newImages]);
|
||||
setImages(prev => {
|
||||
if (!replace) return [...prev, ...newImages];
|
||||
prev.forEach(img => {
|
||||
if (!img.isExisting && img.preview) URL.revokeObjectURL(img.preview);
|
||||
});
|
||||
return newImages;
|
||||
});
|
||||
} catch {
|
||||
setImgError(t('imageUpload.processingFailed'));
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user