Skip to content

Commit 7cda628

Browse files
authored
fix: Add itemsPerFetch prop for updating notification count
1 parent bbfa36c commit 7cda628

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ loadMoreLabel | Text to be shown on the bottom load more component | string | "L
9999
hideHeader | Flag to hide or show the header | boolean | false |
100100
hideClearAll | Flag to hide or show the clear all button | boolean | false |
101101
darkMode | Flag to enable dark mode | boolean | false |
102+
itemsPerFetch | Number of notifications fetch per api request (have a max cap of 50) | number | 20 |
102103
windowViewOnly | Flag to enable window view | boolean | false |
103104
notificationIcon | Option to use custom notification Icon | JSX Element | null |
104105
noOfNotificationsPerFetch | Number of notifications to fetch per page | number | 10 |

src/components/SirenInbox.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useSirenContext } from "./SirenProvider";
66
import type { SirenProps } from "../types";
77
import { Constants } from "../utils";
88
import { applyTheme, calculateModalPosition } from "../utils/commonUtils";
9-
import { BadgeType, ThemeMode } from "../utils/constants";
9+
import { BadgeType, MAXIMUM_ITEMS_PER_FETCH, ThemeMode } from "../utils/constants";
1010
import "../styles/sirenInbox.css";
1111

1212
const { DEFAULT_WINDOW_TITLE } = Constants;
@@ -55,8 +55,10 @@ const SirenInbox: FC<SirenProps> = ({
5555
customNotificationCard,
5656
onNotificationCardClick,
5757
onError,
58-
noOfNotificationsPerFetch = 10,
58+
itemsPerFetch = 20,
5959
}) => {
60+
const notificationsPerPage =
61+
itemsPerFetch > MAXIMUM_ITEMS_PER_FETCH ? MAXIMUM_ITEMS_PER_FETCH : itemsPerFetch;
6062
const [isModalOpen, setIsModalOpen] = useState(false);
6163
const { siren } = useSirenContext();
6264
const iconRef = useRef<HTMLDivElement>(null);
@@ -155,7 +157,7 @@ const SirenInbox: FC<SirenProps> = ({
155157
<SirenPanel
156158
title={title}
157159
styles={styles}
158-
noOfNotificationsPerFetch={noOfNotificationsPerFetch}
160+
noOfNotificationsPerFetch={notificationsPerPage}
159161
hideHeader={hideHeader}
160162
cardProps={cardProps}
161163
customFooter={customFooter}

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ export type SirenInboxProps = {
1313
hideHeader?: boolean;
1414
hideClearAll?: boolean;
1515
darkMode?: boolean;
16+
itemsPerFetch?: number;
1617
cardProps?: CardProps;
1718
listEmptyComponent?: JSX.Element;
1819
loadMoreComponent?:JSX.Element;
1920
customFooter?: JSX.Element;
2021
customHeader?: JSX.Element;
2122
customLoader?: JSX.Element;
2223
customErrorWindow?: JSX.Element;
23-
noOfNotificationsPerFetch?: number;
2424
customNotificationCard?: (notification: NotificationDataType) => JSX.Element;
2525
onNotificationCardClick?: (notification: NotificationDataType) => void;
2626
onError?: (error: SirenErrorType) => void;

src/utils/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ export const DEFAULT_WINDOW_TITLE = "Notifications";
101101
export const RETRY_BUTTON_LABEL = "Retry";
102102
export const CLEAR_ALL_LABEL = "Clear All";
103103
export const TOKEN_VERIFICATION_FAILED = 'TOKEN_VERIFICATION_FAILED';
104+
export const MAXIMUM_ITEMS_PER_FETCH = 50;
104105

105106
export const errorMap = {
106107
SIREN_OBJECT_NOT_FOUND: {

0 commit comments

Comments
 (0)