4.20.6: Исправлено удаление фото в желаниях
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 1m28s
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 1m28s
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "play-life-web",
|
||||
"version": "4.20.5",
|
||||
"version": "4.20.6",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -16,6 +16,7 @@ function WishlistForm({ onNavigate, wishlistId, editConditionIndex, newTaskId, b
|
||||
const [link, setLink] = useState('')
|
||||
const [imageUrl, setImageUrl] = useState(null)
|
||||
const [imageFile, setImageFile] = useState(null)
|
||||
const [imageRemoved, setImageRemoved] = useState(false) // Флаг удаления фото
|
||||
const [showCropper, setShowCropper] = useState(false)
|
||||
const [crop, setCrop] = useState({ x: 0, y: 0 })
|
||||
const [zoom, setZoom] = useState(1)
|
||||
@@ -144,6 +145,7 @@ function WishlistForm({ onNavigate, wishlistId, editConditionIndex, newTaskId, b
|
||||
setPrice(state.price || '')
|
||||
setLink(state.link || '')
|
||||
setImageUrl(state.imageUrl || null)
|
||||
setImageRemoved(false) // Сбрасываем флаг удаления при восстановлении
|
||||
|
||||
// Восстанавливаем условия и автоматически добавляем новую задачу
|
||||
const restoredConditions = state.unlockConditions || []
|
||||
@@ -220,6 +222,7 @@ function WishlistForm({ onNavigate, wishlistId, editConditionIndex, newTaskId, b
|
||||
setLink('')
|
||||
setImageUrl(null)
|
||||
setImageFile(null)
|
||||
setImageRemoved(false)
|
||||
setUnlockConditions([])
|
||||
setError('')
|
||||
setShowCropper(false)
|
||||
@@ -244,6 +247,7 @@ function WishlistForm({ onNavigate, wishlistId, editConditionIndex, newTaskId, b
|
||||
setLink(data.link || '')
|
||||
setImageUrl(data.image_url || null)
|
||||
setImageFile(null) // Сбрасываем imageFile при загрузке существующего желания
|
||||
setImageRemoved(false) // Сбрасываем флаг удаления при загрузке
|
||||
setSelectedProjectId(data.project_id ? String(data.project_id) : '')
|
||||
if (data.unlock_conditions) {
|
||||
setUnlockConditions(data.unlock_conditions.map((cond, idx) => ({
|
||||
@@ -271,6 +275,7 @@ function WishlistForm({ onNavigate, wishlistId, editConditionIndex, newTaskId, b
|
||||
setLink(data.link || '')
|
||||
setImageUrl(data.image_url || null)
|
||||
setImageFile(null)
|
||||
setImageRemoved(false) // Сбрасываем флаг удаления при загрузке
|
||||
setSelectedProjectId(data.project_id ? String(data.project_id) : '')
|
||||
}
|
||||
} catch (err) {
|
||||
@@ -286,6 +291,7 @@ function WishlistForm({ onNavigate, wishlistId, editConditionIndex, newTaskId, b
|
||||
setLink('')
|
||||
setImageUrl(null)
|
||||
setImageFile(null)
|
||||
setImageRemoved(false)
|
||||
setUnlockConditions([])
|
||||
setSelectedProjectId('')
|
||||
setError('')
|
||||
@@ -353,6 +359,7 @@ function WishlistForm({ onNavigate, wishlistId, editConditionIndex, newTaskId, b
|
||||
reader.onload = () => {
|
||||
setImageUrl(reader.result)
|
||||
setImageFile(blob)
|
||||
setImageRemoved(false) // Сбрасываем флаг удаления при загрузке из метаданных
|
||||
setShowCropper(true)
|
||||
}
|
||||
reader.readAsDataURL(blob)
|
||||
@@ -413,6 +420,7 @@ function WishlistForm({ onNavigate, wishlistId, editConditionIndex, newTaskId, b
|
||||
reader.onload = () => {
|
||||
setImageFile(file)
|
||||
setImageUrl(reader.result)
|
||||
setImageRemoved(false) // Сбрасываем флаг удаления при выборе нового фото
|
||||
setShowCropper(true)
|
||||
}
|
||||
reader.readAsDataURL(file)
|
||||
@@ -465,6 +473,7 @@ function WishlistForm({ onNavigate, wishlistId, editConditionIndex, newTaskId, b
|
||||
reader.onload = () => {
|
||||
setImageUrl(reader.result)
|
||||
setImageFile(croppedImage)
|
||||
setImageRemoved(false) // Сбрасываем флаг удаления при сохранении обрезки
|
||||
setShowCropper(false)
|
||||
}
|
||||
reader.readAsDataURL(croppedImage)
|
||||
@@ -609,8 +618,19 @@ function WishlistForm({ onNavigate, wishlistId, editConditionIndex, newTaskId, b
|
||||
const savedItem = await response.json()
|
||||
const itemId = savedItem.id || wishlistId
|
||||
|
||||
// Загружаем картинку если есть
|
||||
if (imageFile && itemId) {
|
||||
// Удаляем картинку если она была удалена пользователем
|
||||
if (imageRemoved && itemId) {
|
||||
const deleteResponse = await authFetch(`${API_URL}/${itemId}/image`, {
|
||||
method: 'DELETE',
|
||||
})
|
||||
|
||||
if (!deleteResponse.ok) {
|
||||
setToastMessage({ text: 'Желание сохранено, но ошибка при удалении картинки', type: 'warning' })
|
||||
}
|
||||
}
|
||||
|
||||
// Загружаем картинку если есть новое фото
|
||||
if (imageFile && itemId && !imageRemoved) {
|
||||
const formData = new FormData()
|
||||
formData.append('image', imageFile)
|
||||
|
||||
@@ -744,6 +764,11 @@ function WishlistForm({ onNavigate, wishlistId, editConditionIndex, newTaskId, b
|
||||
onClick={() => {
|
||||
setImageUrl(null)
|
||||
setImageFile(null)
|
||||
setImageRemoved(true) // Устанавливаем флаг удаления
|
||||
// Сбрасываем file input, чтобы можно было выбрать новое фото
|
||||
if (fileInputRef.current) {
|
||||
fileInputRef.current.value = ''
|
||||
}
|
||||
}}
|
||||
className="remove-image-button"
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user