feat: saved searches

Lets users name and pin a search query from the SearchResults page;
saved searches persist to localStorage and show as quick links in a new
sidebar section, similar to Favorites. Clicking re-runs the query.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
cesnimda
2026-06-30 22:00:12 +02:00
parent c7ead8caae
commit 9bd3799fbc
3 changed files with 79 additions and 3 deletions
+14 -1
View File
@@ -5,6 +5,7 @@ import EmailRow from '../components/EmailRow.jsx';
import BulkToolbar from '../components/BulkToolbar.jsx';
import useSelection from '../hooks/useSelection.js';
import useListKeyboardNav from '../hooks/useListKeyboardNav.js';
import useSavedSearches from '../hooks/useSavedSearches.js';
const PAGE_SIZE = 50;
@@ -21,6 +22,13 @@ export default function SearchResults() {
const [error, setError] = useState(null);
const { selected, toggle, clear, removeIds, selectedIds } = useSelection();
const focusedId = useListKeyboardNav(emails, (id) => setEmails((prev) => prev.filter((x) => x.id !== id)));
const { searches: savedSearches, add: addSavedSearch } = useSavedSearches();
const isSaved = savedSearches.some((s) => s.query === q);
const handleSave = () => {
const label = window.prompt('Name this saved search:', q);
if (label && label.trim()) addSavedSearch(label.trim(), q);
};
useEffect(() => {
setEmails([]);
@@ -63,11 +71,16 @@ export default function SearchResults() {
return (
<div className="folder-view">
<div className="folder-view-head">
<div className="folder-view-head saved-search-row">
<h2 className="folder-view-title">🔍 "{q}"</h2>
{totalCount !== null && (
<span className="folder-view-count">{totalCount.toLocaleString()} result{totalCount !== 1 ? 's' : ''}</span>
)}
{q.trim() && (
<button className="saved-search-save-btn" onClick={handleSave} disabled={isSaved}>
{isSaved ? '★ Saved' : '☆ Save search'}
</button>
)}
</div>
{!q.trim() && <div className="fv-empty">Enter a search query above.</div>}