diff --git a/VERSION b/VERSION index 7ecad14..476d3ce 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.21.0 +6.21.1 diff --git a/play-life-web/package.json b/play-life-web/package.json index f900406..607f7c8 100644 --- a/play-life-web/package.json +++ b/play-life-web/package.json @@ -1,6 +1,6 @@ { "name": "play-life-web", - "version": "6.21.0", + "version": "6.21.1", "type": "module", "scripts": { "dev": "vite", diff --git a/play-life-web/src/components/WishlistForm.jsx b/play-life-web/src/components/WishlistForm.jsx index 083dac5..a5b47f6 100644 --- a/play-life-web/src/components/WishlistForm.jsx +++ b/play-life-web/src/components/WishlistForm.jsx @@ -3,6 +3,7 @@ import { createPortal } from 'react-dom' import Cropper from 'react-easy-crop' import { useAuth } from './auth/AuthContext' import Toast from './Toast' +import './Wishlist.css' import './WishlistForm.css' // Извлекает первый URL из текста @@ -61,6 +62,10 @@ function WishlistForm({ onNavigate, wishlistId, editConditionIndex, newTaskId: n const [imageUrlInput, setImageUrlInput] = useState('') // Ссылка на картинку для загрузки по URL const [loadingImageFromUrl, setLoadingImageFromUrl] = useState(false) const [newTaskConsumed, setNewTaskConsumed] = useState(false) // Флаг что newTaskId уже добавлен как цель + const [isDeleting, setIsDeleting] = useState(false) + const [isCopying, setIsCopying] = useState(false) + const [showActionMenu, setShowActionMenu] = useState(false) + const actionMenuHistoryRef = useRef(false) const fileInputRef = useRef(null) // Загрузка задач, проектов и саджестов групп @@ -677,6 +682,77 @@ function WishlistForm({ onNavigate, wishlistId, editConditionIndex, newTaskId: n onNavigate?.('task-form', navParams) } + const openActionMenu = () => { + setShowActionMenu(true) + window.history.pushState({ actionMenu: true }, '') + actionMenuHistoryRef.current = true + } + + const closeActionMenu = () => { + setShowActionMenu(false) + if (actionMenuHistoryRef.current) { + actionMenuHistoryRef.current = false + window.history.back() + } + } + + // Обработка popstate для закрытия action menu кнопкой назад + useEffect(() => { + const handlePopState = () => { + if (showActionMenu) { + actionMenuHistoryRef.current = false + setShowActionMenu(false) + } + } + window.addEventListener('popstate', handlePopState) + return () => window.removeEventListener('popstate', handlePopState) + }, [showActionMenu]) + + const handleDelete = async () => { + if (!wishlistId) return + + setShowActionMenu(false) + if (actionMenuHistoryRef.current) { + actionMenuHistoryRef.current = false + window.history.go(-2) + } else { + window.history.back() + } + + setIsDeleting(true) + try { + const response = await authFetch(`${API_URL}/${wishlistId}`, { method: 'DELETE' }) + if (!response.ok) { + throw new Error('Ошибка при удалении') + } + } catch (err) { + console.error('Error deleting wishlist item:', err) + } + } + + const handleCopy = async () => { + if (!wishlistId) return + + setShowActionMenu(false) + if (actionMenuHistoryRef.current) { + actionMenuHistoryRef.current = false + window.history.go(-2) + } else { + window.history.back() + } + + setIsCopying(true) + try { + const response = await authFetch(`${API_URL}/${wishlistId}/copy`, { method: 'POST' }) + if (!response.ok) { + const errorText = await response.text().catch(() => '') + throw new Error(errorText || 'Ошибка при копировании') + } + } catch (err) { + console.error('Error copying wishlist item:', err) + } + } + const handleSubmit = async (e) => { e.preventDefault() setError('') @@ -1077,13 +1153,14 @@ function WishlistForm({ onNavigate, wishlistId, editConditionIndex, newTaskId: n zIndex: 1500, display: 'flex', justifyContent: 'center', + gap: '0.75rem', }}> + {wishlistId && ( + + )} , document.body ) : null} + {showActionMenu && createPortal( +
+
e.stopPropagation()}> +
+

{name}

+
+
+ + +
+
+
, + document.body + )} ) }