6.4.11: Фикс кнопки назад для диалога желания
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 1m6s

This commit is contained in:
poignatov
2026-03-09 21:36:34 +03:00
parent b47d50f51c
commit c9a8b994eb
4 changed files with 17 additions and 16 deletions

View File

@@ -778,7 +778,7 @@ function AppContent() {
if (taskDetailModal || wishlistDetailModal) {
return
}
// Если это модальное окно, не обрабатываем здесь - компоненты сами закроют его
if (event.state && event.state.modalOpen) {
// Если модальных окон нет в DOM, это устаревшая запись — пропускаем её

View File

@@ -239,12 +239,14 @@ function WishlistDetail({ wishlistId, onNavigate, onRefresh, boardId, onClose, p
if (skipHistoryBack === true) {
// Сохраняем флаг перед сбросом
const hadWishlistHistory = historyPushedForWishlistRef.current
// Закрываем модальные окна
historyPushedForTaskRef.current = false
selectedTaskForDetailRef.current = null
setSelectedTaskForDetail(null)
historyPushedForWishlistRef.current = false
wishlistIdRef.current = null
// Закрываем экран желания через onClose
// Навигация на task-form уже происходит в TaskDetail, поэтому не вызываем onNavigate здесь
// App.jsx обработает навигацию и заменит запись task-detail на task-form через replaceState
@@ -255,6 +257,7 @@ function WishlistDetail({ wishlistId, onNavigate, onRefresh, boardId, onClose, p
window.history.back()
} else {
historyPushedForTaskRef.current = false
selectedTaskForDetailRef.current = null
setSelectedTaskForDetail(null)
}
}
@@ -291,28 +294,24 @@ function WishlistDetail({ wishlistId, onNavigate, onRefresh, boardId, onClose, p
if (!wishlistId && !selectedTaskForDetail) return
const handlePopState = (event) => {
// Проверяем наличие модальных окон в DOM
const taskDetailModal = document.querySelector('.task-detail-modal-overlay')
const wishlistDetailModal = document.querySelector('.wishlist-detail-modal-overlay')
// Используем refs для получения актуального состояния
// (refs обновляются сразу в обработчике, в отличие от DOM который обновляется после рендера)
const currentTaskDetail = selectedTaskForDetailRef.current
const currentWishlistId = wishlistIdRef.current
// Сначала проверяем вложенное модальное окно TaskDetail
if (currentTaskDetail || taskDetailModal) {
if (currentTaskDetail) {
setSelectedTaskForDetail(null)
selectedTaskForDetailRef.current = null
historyPushedForTaskRef.current = false
// Возвращаем запись для WishlistDetail
if (currentWishlistId || wishlistDetailModal) {
window.history.pushState({ modalOpen: true, type: 'wishlist-detail' }, '', window.location.href)
}
// НЕ пушим запись для WishlistDetail — оригинальная запись wishlist-detail
// уже находится на текущей позиции в history stack (мы вернулись на неё после back).
// Следующий back от wishlist-detail закроет диалог желания.
return
}
// Если открыто модальное окно WishlistDetail, закрываем его
if (currentWishlistId || wishlistDetailModal) {
if (currentWishlistId) {
if (onClose) {
onClose()
} else {
@@ -330,9 +329,11 @@ function WishlistDetail({ wishlistId, onNavigate, onRefresh, boardId, onClose, p
}
}
historyPushedForWishlistRef.current = false
wishlistIdRef.current = null
// Следующее нажатие "назад" обработается App.jsx нормально
return
}
}
window.addEventListener('popstate', handlePopState)