Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mail: Person search: Limit reactivity #373

Merged
merged 6 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions app/frontend/Mail/LeftPane/LeftPane.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<PersonsList persons={appGlobal.persons} bind:selected={$selectedPerson} size="small" />
<ViewSwitcher />
{:else if activeTab == SearchView.Search}
<SearchPane bind:searchMessages on:clear={onClearSearch} />
<SearchPane bind:searchMessages on:clear={endSearchMode} />
{:else}
<!--<ProjectList />-->
<AccountList {accounts} bind:selectedAccount />
Expand Down Expand Up @@ -62,28 +62,42 @@
export let selectedFolders: ArrayColl<Folder>;

let activeTab = SearchView.Folder;
$: if (!!$globalSearchTerm) {
$: if (!!$globalSearchTerm) openSearchPane();
function openSearchPane() {
activeTab = SearchView.Search;
}
$: if (activeTab != SearchView.Search) {
$: activeTab, clearSearchMessages();
function clearSearchMessages() {
searchMessages = null;
lastPerson = null;
}

function onClearSearch() {
// Search.svelte is removed here above, and therefore cannot react anymore, so have to do it here.
// Reproduction: window title | search field | (x) button
$: if (!$globalSearchTerm) endSearchMode();
function endSearchMode() {
activeTab = SearchView.Folder;
clearSearchMessages();
}

let lastPerson: Person;
$: activeTab == SearchView.Person && $selectedPerson && catchErrors(() => showPerson($selectedPerson))
async function showPerson(person: Person) {
if (lastPerson == person) {
return;
}
lastPerson = person;

let search = newSearchEMail();
search.includesPerson = person;
//let folder = new SavedSearchFolder(search);
//selectedFolder = folder;
searchMessages = await search.startSearch();
let messages = await search.startSearch();

if (lastPerson != person) { // User already clicked elsewhere.
return;
}
searchMessages = messages;
}

// Search.svelte is removed here above, and therefore cannot react anymore, so have to do it here.
// Reproduction: window title | search field | (x) button
$: if (!$globalSearchTerm) onClearSearch();
</script>

<style>
Expand Down
7 changes: 4 additions & 3 deletions app/frontend/Shared/Person/PersonsList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@
? persons.filter(p => p.name?.toLowerCase().includes(searchTerm))
: persons;

$: if (selected instanceof Person) {
$selectedPerson = selected
};
$: if (selected instanceof Person) setSelectedPerson(selected);
function setSelectedPerson(person: Person) {
$selectedPerson = person;
}
</script>

<style>
Expand Down