diff --git a/frontend/Layout.tsx b/frontend/Layout.tsx index c4b4616..8da462d 100644 --- a/frontend/Layout.tsx +++ b/frontend/Layout.tsx @@ -109,7 +109,7 @@ const Layout: React.FC = ({ if (window.innerWidth < 1024) { setIsSidebarOpen(false); } - navigate(`/task/${newTask.uid}`, { state: { isNew: true } }); + navigate(`/task/${newTask.uid}`, { state: { isNew: true, from: location.pathname + location.search } }); } else { throw new Error('New task missing UID'); } diff --git a/frontend/components/Calendar.tsx b/frontend/components/Calendar.tsx index 06ed303..ae2e882 100644 --- a/frontend/components/Calendar.tsx +++ b/frontend/components/Calendar.tsx @@ -16,7 +16,7 @@ import CalendarMonthView from './Calendar/CalendarMonthView'; import CalendarWeekView from './Calendar/CalendarWeekView'; import CalendarDayView from './Calendar/CalendarDayView'; import { getApiPath } from '../config/paths'; -import { Link, useNavigate } from 'react-router-dom'; +import { Link, useNavigate, useLocation } from 'react-router-dom'; import { parseDateString } from '../utils/dateUtils'; const getLocale = (language: string) => { @@ -48,6 +48,7 @@ interface CalendarEvent { const Calendar: React.FC = () => { const { t, i18n } = useTranslation(); const navigate = useNavigate(); + const location = useLocation(); const [currentDate, setCurrentDate] = useState(new Date()); const [view, setView] = useState<'month' | 'week' | 'day'>('month'); const [events, setEvents] = useState([]); @@ -265,7 +266,7 @@ const Calendar: React.FC = () => { setIsEventDetailModalOpen(false); const targetUid = selectedTask.uid; setSelectedTask(null); - navigate(`/task/${targetUid}`); + navigate(`/task/${targetUid}`, { state: { from: location.pathname + location.search } }); } }; diff --git a/frontend/components/Inbox/InboxItems.tsx b/frontend/components/Inbox/InboxItems.tsx index cafc8d2..0deff2d 100644 --- a/frontend/components/Inbox/InboxItems.tsx +++ b/frontend/components/Inbox/InboxItems.tsx @@ -1,5 +1,5 @@ import React, { useState, useEffect } from 'react'; -import { useSearchParams, useNavigate } from 'react-router-dom'; +import { useSearchParams, useNavigate, useLocation } from 'react-router-dom'; import { Task } from '../../entities/Task'; import { Project } from '../../entities/Project'; import { Note } from '../../entities/Note'; @@ -31,6 +31,7 @@ const InboxItems: React.FC = () => { const { showSuccessToast, showErrorToast } = useToast(); const [searchParams, setSearchParams] = useSearchParams(); const navigate = useNavigate(); + const location = useLocation(); const [hasInitialized, setHasInitialized] = useState(false); @@ -243,7 +244,7 @@ const InboxItems: React.FC = () => { } if (options.navigateAfterCreate && createdTask.uid) { - navigate(`/task/${createdTask.uid}`); + navigate(`/task/${createdTask.uid}`, { state: { from: location.pathname + location.search } }); } return createdTask; diff --git a/frontend/components/Notifications/NotificationsDropdown.tsx b/frontend/components/Notifications/NotificationsDropdown.tsx index 0fd977a..cab5259 100644 --- a/frontend/components/Notifications/NotificationsDropdown.tsx +++ b/frontend/components/Notifications/NotificationsDropdown.tsx @@ -9,7 +9,7 @@ import { CheckCircleIcon, } from '@heroicons/react/24/outline'; import { useTranslation } from 'react-i18next'; -import { useNavigate } from 'react-router-dom'; +import { useNavigate, useLocation } from 'react-router-dom'; import { getApiPath } from '../../config/paths'; interface Notification { @@ -36,6 +36,7 @@ const NotificationsDropdown: React.FC = ({ }) => { const { t } = useTranslation(); const navigate = useNavigate(); + const location = useLocation(); const [isOpen, setIsOpen] = useState(false); const [unreadCount, setUnreadCount] = useState(0); const [notifications, setNotifications] = useState([]); @@ -213,7 +214,7 @@ const NotificationsDropdown: React.FC = ({ const handleNotificationClick = (notification: Notification) => { if (notification.data?.taskUid) { setIsOpen(false); - navigate(`/task/${notification.data.taskUid}`); + navigate(`/task/${notification.data.taskUid}`, { state: { from: location.pathname + location.search } }); } else if (notification.data?.projectUid) { setIsOpen(false); navigate(`/project/${notification.data.projectUid}`); diff --git a/frontend/components/Productivity/ProductivityAssistant.tsx b/frontend/components/Productivity/ProductivityAssistant.tsx index 8496e8b..f3fa8b4 100644 --- a/frontend/components/Productivity/ProductivityAssistant.tsx +++ b/frontend/components/Productivity/ProductivityAssistant.tsx @@ -1,6 +1,6 @@ import React, { useState, useEffect } from 'react'; import { useTranslation } from 'react-i18next'; -import { useNavigate } from 'react-router-dom'; +import { useNavigate, useLocation } from 'react-router-dom'; import { AcademicCapIcon, ExclamationTriangleIcon, @@ -39,6 +39,7 @@ const ProductivityAssistant: React.FC = ({ }) => { const { t } = useTranslation(); const navigate = useNavigate(); + const location = useLocation(); const [isExpanded, setIsExpanded] = useState(false); const [insights, setInsights] = useState([]); @@ -281,7 +282,7 @@ const ProductivityAssistant: React.FC = ({ if (!isProject) { // Handle task click - navigate to task details page if (item.uid) { - navigate(`/task/${item.uid}`); + navigate(`/task/${item.uid}`, { state: { from: location.pathname + location.search } }); } } else { // Handle project click - navigate to project page diff --git a/frontend/components/Task/TaskDetails.tsx b/frontend/components/Task/TaskDetails.tsx index bf25e71..e98c40b 100644 --- a/frontend/components/Task/TaskDetails.tsx +++ b/frontend/components/Task/TaskDetails.tsx @@ -857,7 +857,7 @@ const TaskDetails: React.FC = () => { showSuccessToast( t('task.deleteSuccess', 'Task deleted successfully') ); - navigate('/today'); + navigate(location.state?.from || '/today'); } catch (error) { console.error('Error deleting task:', error); showErrorToast(t('task.deleteError', 'Failed to delete task')); diff --git a/frontend/components/Task/TaskItem.tsx b/frontend/components/Task/TaskItem.tsx index df4c4ae..63f524b 100644 --- a/frontend/components/Task/TaskItem.tsx +++ b/frontend/components/Task/TaskItem.tsx @@ -1,5 +1,5 @@ import React, { useState, useEffect, useCallback } from 'react'; -import { useNavigate } from 'react-router-dom'; +import { useNavigate, useLocation } from 'react-router-dom'; import { Task } from '../../entities/Task'; import { Project } from '../../entities/Project'; import TaskHeader from './TaskHeader'; @@ -170,6 +170,7 @@ const TaskItem: React.FC = ({ showCompletedTasks = false, }) => { const navigate = useNavigate(); + const location = useLocation(); const { t } = useTranslation(); const [projectList, setProjectList] = useState(projects); const [isConfirmDialogOpen, setIsConfirmDialogOpen] = useState(false); @@ -230,12 +231,14 @@ const TaskItem: React.FC = ({ useEffect(() => { setShowSubtasks(false); }, [task.id]); + const fromState = { state: { from: location.pathname + location.search } }; + const handleTaskClick = () => { if (task.uid) { if (task.habit_mode) { navigate(`/habit/${task.uid}`); } else { - navigate(`/task/${task.uid}`); + navigate(`/task/${task.uid}`, fromState); } } }; @@ -243,7 +246,7 @@ const TaskItem: React.FC = ({ const handleSubtaskClick = async () => { // Navigate to the parent task URL (not the subtask URL) if (task.uid) { - navigate(`/task/${task.uid}`); + navigate(`/task/${task.uid}`, fromState); } }; @@ -264,7 +267,7 @@ const TaskItem: React.FC = ({ e.preventDefault(); e.stopPropagation(); if (task.uid) { - navigate(`/task/${task.uid}`); + navigate(`/task/${task.uid}`, fromState); } }; diff --git a/frontend/components/UniversalSearch/SearchResults.tsx b/frontend/components/UniversalSearch/SearchResults.tsx index b9496c9..da21b8b 100644 --- a/frontend/components/UniversalSearch/SearchResults.tsx +++ b/frontend/components/UniversalSearch/SearchResults.tsx @@ -1,5 +1,5 @@ import React, { useState, useEffect } from 'react'; -import { useNavigate } from 'react-router-dom'; +import { useNavigate, useLocation } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import { CheckCircleIcon, @@ -46,6 +46,7 @@ const SearchResults: React.FC = ({ const [results, setResults] = useState([]); const [isLoading, setIsLoading] = useState(false); const navigate = useNavigate(); + const location = useLocation(); useEffect(() => { const fetchResults = async () => { @@ -134,7 +135,7 @@ const SearchResults: React.FC = ({ case 'Task': // Tasks use uid directly if (result.uid) { - navigate(`/task/${result.uid}`); + navigate(`/task/${result.uid}`, { state: { from: location.pathname + location.search } }); } break; case 'Project': {