Skip to content

refactor(mail): improve error handling and feedback for label and fav… #993

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

Merged
merged 5 commits into from
May 24, 2025
Merged
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
25 changes: 15 additions & 10 deletions apps/mail/components/context/thread-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,17 @@ const LabelsList = ({ threadId }: { threadId: string }) => {
const handleToggleLabel = async (labelId: string) => {
if (!labelId) return;
const hasLabel = thread.labels?.map((label) => label.id).includes(labelId);
await modifyLabels({
const promise = modifyLabels({
threadId: [threadId],
addLabels: hasLabel ? [] : [labelId],
removeLabels: hasLabel ? [labelId] : [],
});
refetch();
toast.promise(promise, {
error: hasLabel ? "Failed to remove label" : "Failed to add label",
finally: async () => {
await refetch();
},
});
};

return (
Expand Down Expand Up @@ -209,14 +214,14 @@ export function ThreadContextMenu({

const handleFavorites = async () => {
const targets = mail.bulkSelected.length ? mail.bulkSelected : [threadId];
if (!isStarred) {
toast.success(t('common.actions.addedToFavorites'));
} else {
toast.success(t('common.actions.removedFromFavorites'));
}
await toggleStar({ ids: targets });
setMail((prev) => ({ ...prev, bulkSelected: [] }));
return await Promise.allSettled([refetchThread(), refetch()]);
const promise = toggleStar({ ids: targets });
toast.promise(promise, {
error: isStarred ? t('common.actions.failedToRemoveFromFavorites') : t('common.actions.failedToAddToFavorites'),
finally: async () => {
setMail((prev) => ({ ...prev, bulkSelected: [] }));
await Promise.allSettled([refetchThread(), refetch()]);
},
});
};

const handleToggleImportant = async () => {
Expand Down