fixed get profile avatar and get user from back
This commit is contained in:
@@ -26,9 +26,15 @@ export function useImageUpload(existingUrls = []) {
|
||||
const fileInputRef = useRef(null);
|
||||
|
||||
const existingUrlList = Array.isArray(existingUrls) ? existingUrls : [];
|
||||
const existingUrlsKey = existingUrlList.join("\u0000");
|
||||
|
||||
// Синхронизируем существующие изображения при изменениях извне (например,
|
||||
// когда свежие данные профиля подтягиваются с бэка уже после монтирования).
|
||||
// Не перезаписываем стейт, если пользователь успел выбрать новые файлы.
|
||||
const hasUserSelected = images.some(img => !img.isExisting);
|
||||
|
||||
useEffect(() => {
|
||||
if (existingUrlList.length > 0) {
|
||||
if (existingUrlList.length > 0 && !hasUserSelected) {
|
||||
setImages(existingUrlList.map((url, i) => ({
|
||||
id: `existing-${i}`,
|
||||
file: null,
|
||||
@@ -38,7 +44,7 @@ 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 || []);
|
||||
|
||||
Reference in New Issue
Block a user