Skip to content

Commit

Permalink
Add Pagination for notification messages
Browse files Browse the repository at this point in the history
  • Loading branch information
BLNDLYBLV committed Feb 10, 2021
1 parent 38a5c6a commit 19525d6
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 11 deletions.
65 changes: 54 additions & 11 deletions src/app/components/Notification/index.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
import { faTrash } from '@fortawesome/free-solid-svg-icons';
import { faCaretLeft, faCaretRight, faTrash } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import NotificationElement from 'app/containers/Notification/NotificationElement';
import * as styles from 'app/styles/Notification.module.css';
import * as NotificationInterfaces from 'app/types/Notification';
import classnames from 'classnames';
import * as React from 'react';
import { Col, Grid, Row } from 'react-bootstrap';
// tslint:disable-next-line
import ReactPaginate from 'react-paginate';

// tslint:disable-next-line

export class Notification extends React.Component<
NotificationInterfaces.Props,
NotificationInterfaces.State
> {
private static paginationSize = 6;

constructor(props: NotificationInterfaces.Props) {
super(props);
this.state = {
activeNotificationTab: NotificationInterfaces.NotificationTabType.ALL,
offset: 0,
tabType: NotificationInterfaces.TabType.NOTIFICATIONS,
};
}
Expand All @@ -24,6 +30,12 @@ export class Notification extends React.Component<
this.props.getAllGlobalAnnouncements();
}

public handlePageClick = (data: { selected: number }) => {
this.setState({
offset: Math.ceil(data.selected * Notification.paginationSize),
});
};

public render() {
const { activeNotificationTab, tabType } = this.state;
const { announcements, notifications, deleteNotificationType, deleteNotification } = this.props;
Expand Down Expand Up @@ -151,17 +163,48 @@ export class Notification extends React.Component<
</div>
</Row>
<Row className={classnames('mb-2', styles.notificationWrap)}>
{activeNotifications.map(({ id, title, content, type, createdAt }) => (
<NotificationElement
createdAt={createdAt}
key={id}
id={id}
title={title}
content={content}
type={type}
deleteNotification={deleteNotification}
<Col
className="d-flex justify-content-center"
style={{ width: '100vw', margin: '5px' }}
>
<ReactPaginate
previousLabel={
<span>
<FontAwesomeIcon icon={faCaretLeft} /> <FontAwesomeIcon icon={faCaretLeft} />
</span>
}
nextLabel={
<span>
<FontAwesomeIcon icon={faCaretRight} />{' '}
<FontAwesomeIcon icon={faCaretRight} />
</span>
}
breakLabel={'...'}
breakClassName={'break-me'}
pageCount={Math.max(activeNotifications.length / Notification.paginationSize)}
marginPagesDisplayed={1}
pageClassName={'atag'}
pageRangeDisplayed={2}
activeLinkClassName={'active'}
onPageChange={this.handlePageClick}
containerClassName={'pagination'}
activeClassName={'active'}
/>
))}
</Col>
{activeNotifications.map(({ id, title, content, type, createdAt }, index) =>
index >= this.state.offset &&
index <= this.state.offset + Notification.paginationSize - 1 ? (
<NotificationElement
createdAt={createdAt}
key={id}
id={id}
title={title}
content={content}
type={type}
deleteNotification={deleteNotification}
/>
) : null,
)}
</Row>
</>
) : (
Expand Down
1 change: 1 addition & 0 deletions src/app/types/Notification/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export interface NotificationStoreState {
}

export interface State {
offset: number;
activeNotificationTab: NotificationTabType;
tabType: TabType;
}
Expand Down

0 comments on commit 19525d6

Please sign in to comment.