Skip to content

Commit 19525d6

Browse files
committed
Add Pagination for notification messages
1 parent 38a5c6a commit 19525d6

File tree

2 files changed

+55
-11
lines changed

2 files changed

+55
-11
lines changed

src/app/components/Notification/index.tsx

+54-11
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
1-
import { faTrash } from '@fortawesome/free-solid-svg-icons';
1+
import { faCaretLeft, faCaretRight, faTrash } from '@fortawesome/free-solid-svg-icons';
22
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
33
import NotificationElement from 'app/containers/Notification/NotificationElement';
44
import * as styles from 'app/styles/Notification.module.css';
55
import * as NotificationInterfaces from 'app/types/Notification';
66
import classnames from 'classnames';
77
import * as React from 'react';
88
import { Col, Grid, Row } from 'react-bootstrap';
9+
// tslint:disable-next-line
10+
import ReactPaginate from 'react-paginate';
11+
912
// tslint:disable-next-line
1013

1114
export class Notification extends React.Component<
1215
NotificationInterfaces.Props,
1316
NotificationInterfaces.State
1417
> {
18+
private static paginationSize = 6;
19+
1520
constructor(props: NotificationInterfaces.Props) {
1621
super(props);
1722
this.state = {
1823
activeNotificationTab: NotificationInterfaces.NotificationTabType.ALL,
24+
offset: 0,
1925
tabType: NotificationInterfaces.TabType.NOTIFICATIONS,
2026
};
2127
}
@@ -24,6 +30,12 @@ export class Notification extends React.Component<
2430
this.props.getAllGlobalAnnouncements();
2531
}
2632

33+
public handlePageClick = (data: { selected: number }) => {
34+
this.setState({
35+
offset: Math.ceil(data.selected * Notification.paginationSize),
36+
});
37+
};
38+
2739
public render() {
2840
const { activeNotificationTab, tabType } = this.state;
2941
const { announcements, notifications, deleteNotificationType, deleteNotification } = this.props;
@@ -151,17 +163,48 @@ export class Notification extends React.Component<
151163
</div>
152164
</Row>
153165
<Row className={classnames('mb-2', styles.notificationWrap)}>
154-
{activeNotifications.map(({ id, title, content, type, createdAt }) => (
155-
<NotificationElement
156-
createdAt={createdAt}
157-
key={id}
158-
id={id}
159-
title={title}
160-
content={content}
161-
type={type}
162-
deleteNotification={deleteNotification}
166+
<Col
167+
className="d-flex justify-content-center"
168+
style={{ width: '100vw', margin: '5px' }}
169+
>
170+
<ReactPaginate
171+
previousLabel={
172+
<span>
173+
<FontAwesomeIcon icon={faCaretLeft} /> <FontAwesomeIcon icon={faCaretLeft} />
174+
</span>
175+
}
176+
nextLabel={
177+
<span>
178+
<FontAwesomeIcon icon={faCaretRight} />{' '}
179+
<FontAwesomeIcon icon={faCaretRight} />
180+
</span>
181+
}
182+
breakLabel={'...'}
183+
breakClassName={'break-me'}
184+
pageCount={Math.max(activeNotifications.length / Notification.paginationSize)}
185+
marginPagesDisplayed={1}
186+
pageClassName={'atag'}
187+
pageRangeDisplayed={2}
188+
activeLinkClassName={'active'}
189+
onPageChange={this.handlePageClick}
190+
containerClassName={'pagination'}
191+
activeClassName={'active'}
163192
/>
164-
))}
193+
</Col>
194+
{activeNotifications.map(({ id, title, content, type, createdAt }, index) =>
195+
index >= this.state.offset &&
196+
index <= this.state.offset + Notification.paginationSize - 1 ? (
197+
<NotificationElement
198+
createdAt={createdAt}
199+
key={id}
200+
id={id}
201+
title={title}
202+
content={content}
203+
type={type}
204+
deleteNotification={deleteNotification}
205+
/>
206+
) : null,
207+
)}
165208
</Row>
166209
</>
167210
) : (

src/app/types/Notification/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export interface NotificationStoreState {
5858
}
5959

6060
export interface State {
61+
offset: number;
6162
activeNotificationTab: NotificationTabType;
6263
tabType: TabType;
6364
}

0 commit comments

Comments
 (0)