Skip to content

Commit b531444

Browse files
committed
fix: minor issues
1 parent fa85b5f commit b531444

7 files changed

Lines changed: 24 additions & 12 deletions

File tree

src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function App() {
2424
};
2525

2626
useEffect(() => {
27-
initializeUser();
27+
void initializeUser();
2828
}, []);
2929

3030
return (

src/components/user-chip/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ const UserChip = ({ avatar, name, email, onRemove }: UserChipProps) => {
1414
const [position, setPosition] = useState<{ top: number; left: number } | null>(null);
1515
const ref = useRef<HTMLDivElement>(null);
1616
const tooltipId = useId();
17-
const userName = name.split(' ')[0] || email.split('@')[0];
17+
const normalizedName = name.trim();
18+
const userName = normalizedName ? normalizedName.split(/\s+/)[0] : email.split('@')[0];
1819

1920
const handleMouseEnter = () => {
2021
const rect = ref.current?.getBoundingClientRect();

src/errors/mail/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ export class FetchMailboxesInfoError extends Error {
44
public requestId?: string,
55
) {
66
super('Error while fetching mailboxes info: ' + errorMsg);
7-
this.requestId = requestId;
87

98
Object.setPrototypeOf(this, FetchMailboxesInfoError.prototype);
109
}
@@ -16,7 +15,6 @@ export class FetchListFolderError extends Error {
1615
public requestId?: string,
1716
) {
1817
super('Error while fetching list folder: ' + errorMsg);
19-
this.requestId = requestId;
2018

2119
Object.setPrototypeOf(this, FetchListFolderError.prototype);
2220
}
@@ -28,7 +26,6 @@ export class FetchMessageError extends Error {
2826
public requestId?: string,
2927
) {
3028
super('Error while fetching message: ' + errorMsg);
31-
this.requestId = requestId;
3229

3330
Object.setPrototypeOf(this, FetchMessageError.prototype);
3431
}
@@ -41,7 +38,6 @@ export class UpdateMailError extends Error {
4138
public requestId?: string,
4239
) {
4340
super(`Error while updating mail when ${action}: ` + errorMsg);
44-
this.requestId = requestId;
4541

4642
Object.setPrototypeOf(this, UpdateMailError.prototype);
4743
}

src/features/mail/MailView.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Settings from './components/settings';
77
import { useGetListFolderQuery, useGetMailMessageQuery, useMarkAsReadMutation } from '@/store/queries/mail/mail.query';
88
import { DateService } from '@/services/date';
99
import { DEFAULT_FOLDER_LIMIT } from '@/constants';
10+
import { ErrorService } from '@/services/error';
1011

1112
interface MailViewProps {
1213
folder: FolderType;
@@ -40,10 +41,15 @@ const MailView = ({ folder }: MailViewProps) => {
4041

4142
if (isRead) return;
4243

43-
await markAsRead({
44-
emailId: id,
45-
query,
46-
});
44+
try {
45+
await markAsRead({
46+
emailId: id,
47+
query,
48+
});
49+
} catch (error) {
50+
const err = ErrorService.instance.castError(error);
51+
console.error(`Error while marking as read the email ${id}: `, err);
52+
}
4753
};
4854

4955
return (

src/services/sdk/mail/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ export class MailService {
3333
return this.client.listEmails(query);
3434
}
3535

36+
/**
37+
* Returns a specific email by its ID.
38+
*
39+
* @param {string} emailId - The ID of the email to fetch
40+
* @returns A promise that resolves with an EmailResponse object
41+
*/
3642
async getMessage(emailId: string): Promise<EmailResponse> {
3743
return this.client.getEmail(emailId);
3844
}

src/store/queries/mail/mail.query.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// store/queries/__tests__/storage.query.test.ts
2-
31
import { describe, test, expect, vi, beforeEach } from 'vitest';
42
import { ErrorService } from '@/services/error';
53
import { FetchListFolderError, FetchMailboxesInfoError, FetchMessageError, UpdateMailError } from '@/errors';

src/store/queries/mail/mail.query.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,20 @@ export const mailQuery = createApi({
5757
}
5858
},
5959
async onQueryStarted({ emailId, query }, { dispatch, queryFulfilled }) {
60+
let shouldUpdateUnreadCount = false;
61+
6062
const patchEmailList = dispatch(
6163
mailQuery.util.updateQueryData('getListFolder', query, (draft) => {
6264
const mail = draft.emails.find((m) => m.id === emailId);
6365
if (mail && !mail.isRead) {
6466
mail.isRead = true;
67+
shouldUpdateUnreadCount = true;
6568
}
6669
}),
6770
);
6871

72+
if (!shouldUpdateUnreadCount) return;
73+
6974
const patchMailboxes = dispatch(
7075
mailQuery.util.updateQueryData('getMailboxesInfo', undefined, (draft) => {
7176
const entry = draft.find((m) => m.type === query?.mailbox);

0 commit comments

Comments
 (0)