Skip to content
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
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export const INTERNXT_EMAIL_DOMAINS = ['@inxt.me', '@inxt.eu', '@encrypt.eu'] as

export const DEFAULT_FOLDER_LIMIT = 15;
export const MAX_TOTAL_ATTACHMENT_BYTES_PER_MAIL = 25 * 1024 * 1024;
export const AUTO_POLLING_INTERVAL_IN_MILLISECONDS = 30000;
13 changes: 10 additions & 3 deletions src/hooks/mail/useListFolderPaginated.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { DEFAULT_FOLDER_LIMIT } from '@/constants';
import { AUTO_POLLING_INTERVAL_IN_MILLISECONDS, DEFAULT_FOLDER_LIMIT } from '@/constants';
import { useGetListFolderQuery } from '@/store/api/mail';
import type { FolderType } from '@/types/mail';
import { useState } from 'react';

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

if (currentMailbox !== mailbox) {
setCurrentMailbox(mailbox);
setAnchorId(undefined);
setUnreadFilter(undefined);
}

const {
data: listFolder,
isLoading: isLoadingListFolder,
Expand All @@ -19,7 +26,7 @@ const useListFolderPaginated = (mailbox: FolderType) => {
unread: unreadFilter,
},
{
pollingInterval: 30000,
pollingInterval: AUTO_POLLING_INTERVAL_IN_MILLISECONDS,
skipPollingIfUnfocused: true,
skip: !mailbox,
},
Expand All @@ -45,10 +52,10 @@ const useListFolderPaginated = (mailbox: FolderType) => {
return {
listFolderEmails,
isLoadingListFolder,
onLoadMore,
hasMoreEmails: listFolder?.hasMoreMails,
isUnreadFilter: unreadFilter,
listEmailsCount: listFolderEmails?.length,
onLoadMore,
toggleUnreadFilter,
};
};
Expand Down
Loading