fix: preserve list scroll position when tagging an email
This commit is contained in:
@@ -139,6 +139,7 @@ export default function Home() {
|
|||||||
deleteEmail,
|
deleteEmail,
|
||||||
markAsRead,
|
markAsRead,
|
||||||
toggleStar,
|
toggleStar,
|
||||||
|
setEmailKeywordsLocal,
|
||||||
moveToMailbox,
|
moveToMailbox,
|
||||||
moveThreadToMailbox,
|
moveThreadToMailbox,
|
||||||
searchEmails,
|
searchEmails,
|
||||||
@@ -1085,11 +1086,9 @@ export default function Home() {
|
|||||||
// Update email keywords via JMAP
|
// Update email keywords via JMAP
|
||||||
await client.updateEmailKeywords(emailId, keywords);
|
await client.updateEmailKeywords(emailId, keywords);
|
||||||
|
|
||||||
// Update local state
|
// Patch the email in place so the list keeps its scroll/pagination state
|
||||||
selectEmail(email.id === selectedEmail?.id ? { ...email, keywords } : selectedEmail);
|
// instead of being reset to the first page by a full refetch.
|
||||||
|
setEmailKeywordsLocal(emailId, keywords);
|
||||||
// Refresh emails list to show color in list
|
|
||||||
await fetchEmails(client, selectedMailbox);
|
|
||||||
|
|
||||||
// Refresh tag counts
|
// Refresh tag counts
|
||||||
fetchTagCounts(client);
|
fetchTagCounts(client);
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ interface EmailStore {
|
|||||||
clearSearchFilters: () => void;
|
clearSearchFilters: () => void;
|
||||||
toggleAdvancedSearch: () => void;
|
toggleAdvancedSearch: () => void;
|
||||||
toggleStar: (client: IJMAPClient, emailId: string) => Promise<void>;
|
toggleStar: (client: IJMAPClient, emailId: string) => Promise<void>;
|
||||||
|
setEmailKeywordsLocal: (emailId: string, keywords: Record<string, boolean>) => void;
|
||||||
|
|
||||||
// Batch operations
|
// Batch operations
|
||||||
batchMarkAsRead: (client: IJMAPClient, read: boolean) => Promise<void>;
|
batchMarkAsRead: (client: IJMAPClient, read: boolean) => Promise<void>;
|
||||||
@@ -1057,6 +1058,17 @@ export const useEmailStore = create<EmailStore>((set, get) => ({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
setEmailKeywordsLocal: (emailId, keywords) => {
|
||||||
|
set((state) => ({
|
||||||
|
emails: state.emails.map(e =>
|
||||||
|
e.id === emailId ? { ...e, keywords: { ...keywords } } : e
|
||||||
|
),
|
||||||
|
selectedEmail: state.selectedEmail?.id === emailId
|
||||||
|
? { ...state.selectedEmail, keywords: { ...keywords } }
|
||||||
|
: state.selectedEmail,
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
|
||||||
// Batch operations
|
// Batch operations
|
||||||
batchMarkAsRead: async (client, read) => {
|
batchMarkAsRead: async (client, read) => {
|
||||||
const { selectedEmailIds, emails, mailboxes } = get();
|
const { selectedEmailIds, emails, mailboxes } = get();
|
||||||
|
|||||||
Reference in New Issue
Block a user