fixed image storage local on minio

This commit is contained in:
SlimusMinus
2026-07-10 01:24:58 +03:00
parent 7e9053e498
commit a344540267
9 changed files with 37 additions and 22 deletions

View File

@@ -1,7 +1,7 @@
import { useState, useCallback, useEffect, useRef } from "react";
import { useNavigate } from "react-router-dom";
import CloseIcon from "./icons/CloseIcon";
import { API_URL } from "../config/authConstants";
import { getImageUrl } from "../config/authConstants";
import { useChats } from "../hooks/useChats";
import { useAuthContext } from "../context/AuthContext";
@@ -13,7 +13,7 @@ export default function ImageViewer({ images, initialIndex = 0, onClose, postDat
const { createOrGetChat } = useChats();
const { isAuthenticated } = useAuthContext();
const urls = images.map(u => (u.startsWith("http") ? u : `${API_URL}${u}`));
const urls = images.map(u => getImageUrl(u));
const next = useCallback(() => {
setIndex(i => (i + 1) % urls.length);

View File

@@ -8,7 +8,7 @@ import { useState } from "react";
import { useNavigate } from "react-router-dom";
import { useChats } from "../hooks/useChats";
import { useAuthContext } from "../context/AuthContext";
import { API_URL } from "../config/authConstants";
import { getImageUrl } from "../config/authConstants";
import DateCalendarPopup from "./DateCalendarPopup";
import { useTranslation } from 'react-i18next';
@@ -36,7 +36,7 @@ export default function PostOnFeed({ ad, liked, onLike, onEdit, onDelete, onMark
console.error(err);
}
};
const imageUrl = ad.images?.[0] ? `${API_URL}${ad.images[0]}` : null;
const imageUrl = getImageUrl(ad.images?.[0]);
// ✅ Формируем строку адреса из city + district
const address = [ad.city, ad.district].filter(Boolean).join(", ");

View File

@@ -24,21 +24,31 @@ export default function ProfileModal({ onClose, initialData = {} }) {
const existingImageUrl = initialData.avatar || null;
const {
imageFile,
displayImage,
images,
imgError,
compressing,
fileInputRef,
handleFileChange,
removeImage,
getExistingUrlsToKeep,
getFilesForUpload,
} = useImageUpload(existingImageUrl);
const currentImage = images[0];
const displayImage = currentImage?.preview ?? null;
const imageFile = currentImage?.file ?? null;
// ─── Field change handler ───────────────────────────────────────────────
const handleFieldChange = useCallback((key, value) => {
setForm(prev => ({ ...prev, [key]: value }));
setErrors(prev => ({ ...prev, [key]: "" }));
}, []);
// ─── Remove image handler (wraps removeImage with the only image id) ─────
const handleRemoveImage = useCallback(() => {
if (currentImage?.id) removeImage(currentImage.id);
}, [currentImage, removeImage]);
// ─── Phone field change with formatting ──────────────────────────────────
const handlePhoneChange = useCallback((value) => {
const formatted = formatPhone(value);
@@ -53,13 +63,15 @@ export default function ProfileModal({ onClose, initialData = {} }) {
return;
}
const newAvatars = getFilesForUpload();
const keptExisting = getExistingUrlsToKeep();
const profileData = {
firstName: form.firstName.trim(),
lastName: form.lastName.trim(),
login: form.login.trim(),
phone: form.phone.trim(),
email: form.email.trim(),
avatar: imageFile || existingImageUrl,
avatar: newAvatars.length > 0 ? newAvatars[0] : (keptExisting.length > 0 ? keptExisting[0] : null),
};
const updatedUser = await updateProfile(user?.id, profileData);
@@ -82,7 +94,7 @@ export default function ProfileModal({ onClose, initialData = {} }) {
compressing={compressing}
fileInputRef={fileInputRef}
onFileChange={handleFileChange}
onRemove={removeImage}
onRemove={handleRemoveImage}
/>
<LoginField