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", "name": "play-life-web",
"version": "4.20.4", "version": "4.20.5",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",

View File

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