Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Do not close expanded popup when deleting an email (#2272)
Leendert de Borst0151e6630c03
diff --git a/apps/browser-extension/src/entrypoints/popup/components/EmailPreview.tsx b/apps/browser-extension/src/entrypoints/popup/components/EmailPreview.tsxindex 5325c3e00..1a3229f1b 100644--- a/apps/browser-extension/src/entrypoints/popup/components/EmailPreview.tsx+++ b/apps/browser-extension/src/entrypoints/popup/components/EmailPreview.tsx@@ -1,6 +1,6 @@import React, { useState, useEffect } from 'react';import { useTranslation } from 'react-i18next';-import { Link } from 'react-router-dom';+import { Link, useLocation } from 'react-router-dom';import { useDb } from '@/entrypoints/popup/context/DbContext';import { useWebApi } from '@/entrypoints/popup/context/WebApiContext';@@ -29,6 +29,7 @@ export const EmailPreview: React.FC<EmailPreviewProps> = ({ email }) => {const [displayedCount, setDisplayedCount] = useState(2);const webApi = useWebApi();const dbContext = useDb();+ const location = useLocation();const emailsPerLoad = 3;const canLoadMore = displayedCount < emails.length;@@ -288,7 +289,8 @@ export const EmailPreview: React.FC<EmailPreviewProps> = ({ email }) => {) : (<Linkkey={mail.id}- to={`/emails/${mail.id}`}+ // Carry where we came from so the email's back/delete (incl. popped-out window) returns here, not the emails list.+ to={`/emails/${mail.id}?returnTo=${encodeURIComponent(`${location.pathname}${location.search}`)}`}className={`flex justify-between items-center p-2 ps-3 pe-3 rounded cursor-pointer bg-white dark:bg-gray-800 shadow hover:shadow-md transition-all border border-gray-200 dark:border-gray-700 hover:bg-gray-50 dark:hover:bg-gray-700 ${mail.id > lastEmailId ? 'bg-yellow-50 dark:bg-yellow-900/30' : ''}`}diff --git a/apps/browser-extension/src/entrypoints/popup/pages/emails/EmailDetails.tsx b/apps/browser-extension/src/entrypoints/popup/pages/emails/EmailDetails.tsxindex fab61511f..3ea7601f7 100644--- a/apps/browser-extension/src/entrypoints/popup/pages/emails/EmailDetails.tsx+++ b/apps/browser-extension/src/entrypoints/popup/pages/emails/EmailDetails.tsx@@ -1,6 +1,6 @@import React, { useEffect, useMemo, useState, useCallback } from 'react';import { useTranslation } from 'react-i18next';-import { Link, useParams, useNavigate } from 'react-router-dom';+import { Link, useParams, useNavigate, useSearchParams } from 'react-router-dom';import Modal from '@/entrypoints/popup/components/Dialogs/Modal';import LoadingSpinner from '@/entrypoints/popup/components/LoadingSpinner';@@ -26,6 +26,9 @@ const EmailDetails: React.FC = (): React.ReactElement => {const { t } = useTranslation();const { id } = useParams<{ id: string }>();const navigate = useNavigate();+ const [searchParams] = useSearchParams();+ // Where the email was opened from (e.g. the owning item); set by the recent-emails list.+ const fromPath = searchParams.get('returnTo');const dbContext = useDb();const webApi = useWebApi();const [error, setError] = useState<string | null>(null);@@ -39,10 +42,11 @@ const EmailDetails: React.FC = (): React.ReactElement => {const { setHeaderButtons } = useHeaderButtons();useEffect(() => {- // For popup windows, ensure we have proper history state for navigation- if (PopoutUtility.isPopup()) {- // Clear existing history and create fresh entries- window.history.replaceState({}, '', `popup.html#/emails`);+ // For expanded windows, ensure we have proper history state for navigation.+ const isExpandedWindow = new URLSearchParams(window.location.search).get('expanded') === 'true';+ if (isExpandedWindow) {+ const parentPath = PopoutUtility.getReturnPath() ?? '/emails';+ window.history.replaceState({}, '', `popup.html#${parentPath}`);window.history.pushState({}, '', `popup.html#/emails/${id}`);}@@ -144,22 +148,24 @@ const EmailDetails: React.FC = (): React.ReactElement => {const handleDelete = useCallback(async () : Promise<void> => {try {await webApi.delete(`Email/${id}`);- if (PopoutUtility.isPopup()) {- window.close();+ // Go back to wherever the email was opened from.+ if (window.history.length > 1) {+ navigate(-1);} else {- navigate('/emails');+ navigate(fromPath ?? '/emails');}} catch (err) {setError(err instanceof Error ? err.message : 'Failed to delete email');}- }, [id, webApi, navigate]);+ }, [id, webApi, navigate, fromPath]);/*** Open the email details in a new expanded popup.*/const openInNewPopup = useCallback((): void => {- PopoutUtility.openInNewPopup(`/emails/${id}`);- }, [id]);+ // Carry the origin into the new window so its back/delete returns there.+ PopoutUtility.openInNewPopup(`/emails/${id}`, fromPath ?? undefined);+ }, [id, fromPath]);/*** Handle downloading an attachment.