fix: keep the open folder when clearing search filters #1430

This commit is contained in:
Linus Rath
2026-10-29 20:11:08 +01:00
parent d875714f35
commit a225109400
2 changed files with 26 additions and 0 deletions
@@ -32,6 +32,8 @@ function makeClient() {
searchEmails: vi.fn().mockResolvedValue({ emails: [], hasMore: false, total: 0 }),
advancedSearchEmails: vi.fn().mockResolvedValue({ emails: [], hasMore: false, total: 0 }),
getSomeEmails: vi.fn().mockResolvedValue([]),
getEmails: vi.fn().mockResolvedValue({ emails: [], hasMore: false, total: 0, state: 'email-state' }),
getThreads: vi.fn().mockResolvedValue([]),
getAccountId: () => 'me',
} as unknown as IJMAPClient;
}
@@ -174,6 +176,21 @@ describe('search folder scope (#788)', () => {
expect(useEmailStore.getState().searchMailboxId).toBe('');
});
// #1430: "Clear" in the filter panel re-runs the search with nothing left
// to search for, which listed every message of the account in the folder.
it('shows the open folder again when the filters are cleared', async () => {
useEmailStore.setState({ searchFilters: { ...DEFAULT_SEARCH_FILTERS, from: 'bob@example.com' } });
await useEmailStore.getState().advancedSearch(client);
(client.advancedSearchEmails as ReturnType<typeof vi.fn>).mockClear();
useEmailStore.getState().clearSearchFilters();
await useEmailStore.getState().advancedSearch(client);
expect(client.advancedSearchEmails).not.toHaveBeenCalled();
expect(client.getEmails).toHaveBeenCalledTimes(1);
expect((client.getEmails as ReturnType<typeof vi.fn>).mock.calls[0][0]).toBe('sent');
});
});
describe('unread badge scope', () => {
+9
View File
@@ -5393,6 +5393,15 @@ export const useEmailStore = create<EmailStore>((set, get) => ({
const { query: searchQuery, filters: searchFilters } = transformed
?? (emailHooks.onSearch.size > 0 ? await transformSearch(typedQuery, typedFilters) : { query: typedQuery, filters: typedFilters });
if (controller.signal.aborted) return;
// Clearing the filters leaves nothing to search for. Under the
// all-folders scope that empty search listed every message of the
// account in place of the open folder (#1430), so load the folder.
if (!isUnifiedView && !selectedKeyword && get().selectedMailbox && isAllFoldersSearchScope(searchMailboxId)
&& !searchQuery.trim() && isFilterEmpty(searchFilters)) {
set({ searchAbortController: null });
await get().fetchEmails(client);
return;
}
startProvidedSearchResults(searchQuery, searchFilters, { get, set });
const emailsPerPage = useSettingsStore.getState().emailsPerPage;
let result;