Skip to content

Commit a4a0e09

Browse files
authored
Merge pull request #68 from internxt/fix/folder-navigation
[_]: fix/reset the anchor Id when navigating through folders
2 parents 6984449 + 3577f9d commit a4a0e09

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ export const INTERNXT_EMAIL_DOMAINS = ['@inxt.me', '@inxt.eu', '@encrypt.eu'] as
1111

1212
export const DEFAULT_FOLDER_LIMIT = 15;
1313
export const MAX_TOTAL_ATTACHMENT_BYTES_PER_MAIL = 25 * 1024 * 1024;
14+
export const AUTO_POLLING_INTERVAL_IN_MILLISECONDS = 30000;

src/hooks/mail/useListFolderPaginated.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
import { DEFAULT_FOLDER_LIMIT } from '@/constants';
1+
import { AUTO_POLLING_INTERVAL_IN_MILLISECONDS, DEFAULT_FOLDER_LIMIT } from '@/constants';
22
import { useGetListFolderQuery } from '@/store/api/mail';
33
import type { FolderType } from '@/types/mail';
44
import { useState } from 'react';
55

66
const useListFolderPaginated = (mailbox: FolderType) => {
7+
const [currentMailbox, setCurrentMailbox] = useState(mailbox);
78
const [anchorId, setAnchorId] = useState<string | undefined>(undefined);
89
const [unreadFilter, setUnreadFilter] = useState<boolean | undefined>(undefined);
910

11+
if (currentMailbox !== mailbox) {
12+
setCurrentMailbox(mailbox);
13+
setAnchorId(undefined);
14+
setUnreadFilter(undefined);
15+
}
16+
1017
const {
1118
data: listFolder,
1219
isLoading: isLoadingListFolder,
@@ -19,7 +26,7 @@ const useListFolderPaginated = (mailbox: FolderType) => {
1926
unread: unreadFilter,
2027
},
2128
{
22-
pollingInterval: 30000,
29+
pollingInterval: AUTO_POLLING_INTERVAL_IN_MILLISECONDS,
2330
skipPollingIfUnfocused: true,
2431
skip: !mailbox,
2532
},
@@ -45,10 +52,10 @@ const useListFolderPaginated = (mailbox: FolderType) => {
4552
return {
4653
listFolderEmails,
4754
isLoadingListFolder,
48-
onLoadMore,
4955
hasMoreEmails: listFolder?.hasMoreMails,
5056
isUnreadFilter: unreadFilter,
5157
listEmailsCount: listFolderEmails?.length,
58+
onLoadMore,
5259
toggleUnreadFilter,
5360
};
5461
};

0 commit comments

Comments
 (0)