Fix redirect after task deletion to return to originating view (#887)

This commit is contained in:
Chris 2026-03-01 16:07:02 +02:00 committed by GitHub
parent edc9d214f6
commit a80e9b5aba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 24 additions and 16 deletions

View file

@ -109,7 +109,7 @@ const Layout: React.FC<LayoutProps> = ({
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');
}

View file

@ -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<CalendarEvent[]>([]);
@ -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 } });
}
};

View file

@ -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;

View file

@ -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<NotificationsDropdownProps> = ({
}) => {
const { t } = useTranslation();
const navigate = useNavigate();
const location = useLocation();
const [isOpen, setIsOpen] = useState(false);
const [unreadCount, setUnreadCount] = useState(0);
const [notifications, setNotifications] = useState<Notification[]>([]);
@ -213,7 +214,7 @@ const NotificationsDropdown: React.FC<NotificationsDropdownProps> = ({
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}`);

View file

@ -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<ProductivityAssistantProps> = ({
}) => {
const { t } = useTranslation();
const navigate = useNavigate();
const location = useLocation();
const [isExpanded, setIsExpanded] = useState(false);
const [insights, setInsights] = useState<ProductivityInsight[]>([]);
@ -281,7 +282,7 @@ const ProductivityAssistant: React.FC<ProductivityAssistantProps> = ({
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

View file

@ -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'));

View file

@ -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<TaskItemProps> = ({
showCompletedTasks = false,
}) => {
const navigate = useNavigate();
const location = useLocation();
const { t } = useTranslation();
const [projectList, setProjectList] = useState<Project[]>(projects);
const [isConfirmDialogOpen, setIsConfirmDialogOpen] = useState(false);
@ -230,12 +231,14 @@ const TaskItem: React.FC<TaskItemProps> = ({
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<TaskItemProps> = ({
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<TaskItemProps> = ({
e.preventDefault();
e.stopPropagation();
if (task.uid) {
navigate(`/task/${task.uid}`);
navigate(`/task/${task.uid}`, fromState);
}
};

View file

@ -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<SearchResultsProps> = ({
const [results, setResults] = useState<SearchResult[]>([]);
const [isLoading, setIsLoading] = useState(false);
const navigate = useNavigate();
const location = useLocation();
useEffect(() => {
const fetchResults = async () => {
@ -134,7 +135,7 @@ const SearchResults: React.FC<SearchResultsProps> = ({
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': {