4.20.5: Кнопка назад для окна переноса
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 1m12s

This commit is contained in:
poignatov
2026-02-05 12:49:46 +03:00
parent 0ee689151e
commit 0463c237c0
3 changed files with 60 additions and 25 deletions

View File

@@ -1 +1 @@
4.20.4
4.20.5

View File

@@ -1,6 +1,6 @@
{
"name": "play-life-web",
"version": "4.20.4",
"version": "4.20.5",
"type": "module",
"scripts": {
"dev": "vite",

View File

@@ -75,39 +75,62 @@ function TaskList({ onNavigate, data, loading, backgroundLoading, error, onRetry
setSelectedTaskForDetail(null)
}
// Добавляем запись в историю при открытии модального окна и обрабатываем "назад"
const historyPushedRef = useRef(false)
// Добавляем запись в историю при открытии модальных окон и обрабатываем "назад"
const historyPushedForDetailRef = useRef(false)
const historyPushedForPostponeRef = useRef(false)
const selectedTaskForDetailRef = useRef(selectedTaskForDetail)
const selectedTaskForPostponeRef = useRef(selectedTaskForPostpone)
// Обновляем ref при изменении значения
// Обновляем refs при изменении значений
useEffect(() => {
selectedTaskForDetailRef.current = selectedTaskForDetail
}, [selectedTaskForDetail])
selectedTaskForPostponeRef.current = selectedTaskForPostpone
}, [selectedTaskForDetail, selectedTaskForPostpone])
useEffect(() => {
if (selectedTaskForDetail && !historyPushedRef.current) {
// Добавляем запись в историю при открытии модального окна
window.history.pushState({ modalOpen: true, type: 'task-detail' }, '', window.location.href)
historyPushedRef.current = true
} else if (!selectedTaskForDetail) {
historyPushedRef.current = false
if (selectedTaskForPostpone && !historyPushedForPostponeRef.current) {
// Добавляем запись в историю при открытии модального окна переноса
window.history.pushState({ modalOpen: true, type: 'task-postpone' }, '', window.location.href)
historyPushedForPostponeRef.current = true
} else if (!selectedTaskForPostpone) {
historyPushedForPostponeRef.current = false
}
if (!selectedTaskForDetail) return
if (selectedTaskForDetail && !historyPushedForDetailRef.current) {
// Добавляем запись в историю при открытии модального окна деталей задачи
window.history.pushState({ modalOpen: true, type: 'task-detail' }, '', window.location.href)
historyPushedForDetailRef.current = true
} else if (!selectedTaskForDetail) {
historyPushedForDetailRef.current = false
}
if (!selectedTaskForDetail && !selectedTaskForPostpone) return
const handlePopState = (event) => {
// Проверяем наличие модального окна в DOM
// Проверяем наличие модальных окон в DOM
const taskDetailModal = document.querySelector('.task-detail-modal-overlay')
const postponeModal = document.querySelector('.task-postpone-modal-overlay')
// Используем ref для получения актуального состояния
// Используем refs для получения актуального состояния
const currentTaskDetail = selectedTaskForDetailRef.current
const currentPostpone = selectedTaskForPostponeRef.current
// Проверяем, открыто ли модальное окно (по состоянию или в DOM)
// Сначала проверяем модальное окно переноса (если оно открыто поверх)
if (currentPostpone || postponeModal) {
setSelectedTaskForPostpone(null)
setPostponeDate('')
historyPushedForPostponeRef.current = false
// Возвращаем запись для модального окна деталей задачи, если оно было открыто
if (currentTaskDetail || taskDetailModal) {
window.history.pushState({ modalOpen: true, type: 'task-detail' }, '', window.location.href)
}
return
}
// Если открыто модальное окно деталей задачи, закрываем его
if (currentTaskDetail || taskDetailModal) {
// Закрываем модальное окно
setSelectedTaskForDetail(null)
historyPushedRef.current = false
// Предотвращаем дальнейшую обработку в App.jsx
historyPushedForDetailRef.current = false
// Следующее нажатие "назад" обработается App.jsx нормально
return
}
@@ -117,7 +140,7 @@ function TaskList({ onNavigate, data, loading, backgroundLoading, error, onRetry
return () => {
window.removeEventListener('popstate', handlePopState)
}
}, [selectedTaskForDetail])
}, [selectedTaskForDetail, selectedTaskForPostpone])
@@ -367,9 +390,16 @@ function TaskList({ onNavigate, data, loading, backgroundLoading, error, onRetry
}
const handlePostponeClose = () => {
// Если была добавлена запись в историю, удаляем её через history.back()
// Обработчик popstate закроет модальное окно и сбросит флаг
if (historyPushedForPostponeRef.current) {
window.history.back()
} else {
// Если записи не было, просто закрываем модальное окно
setSelectedTaskForPostpone(null)
setPostponeDate('')
}
}
const handleDateSelect = (date) => {
if (!date) return
@@ -440,9 +470,14 @@ function TaskList({ onNavigate, data, loading, backgroundLoading, error, onRetry
onRefresh()
}
// Закрываем модальное окно
// Закрываем модальное окно и удаляем запись из истории, если она была добавлена
// Обработчик popstate закроет модальное окно и сбросит флаг
if (historyPushedForPostponeRef.current) {
window.history.back()
} else {
setSelectedTaskForPostpone(null)
setPostponeDate('')
}
} catch (err) {
console.error('Error postponing task:', err)
setToast({ message: err.message || 'Ошибка при переносе задачи', type: 'error' })