@@ -6,15 +6,21 @@ import * as NotificationInterfaces from 'app/types/Notification';
66import classnames from 'classnames' ;
77import * as React from 'react' ;
88import { Col , Grid , Row } from 'react-bootstrap' ;
9+ import ReactPaginate from 'react-paginate' ;
10+ import { faCaretLeft , faCaretRight } from '@fortawesome/free-solid-svg-icons' ;
11+
912// tslint:disable-next-line
1013
1114export 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 = {
23+ offset : 0 ,
1824 activeNotificationTab : NotificationInterfaces . NotificationTabType . ALL ,
1925 tabType : NotificationInterfaces . TabType . NOTIFICATIONS ,
2026 } ;
@@ -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 ;
@@ -47,6 +59,7 @@ export class Notification extends React.Component<
4759 }
4860 } ) ;
4961
62+
5063 return (
5164 < Grid fluid = { true } className = { classnames ( styles . Notification ) } >
5265 < Row className = "justify-content-between py-2 px-3" >
@@ -151,17 +164,48 @@ export class Notification extends React.Component<
151164 </ div >
152165 </ Row >
153166 < 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 }
167+ < Col
168+ className = "d-flex justify-content-center"
169+ style = { { width : '100vw' , margin : '5px' } }
170+ >
171+ < ReactPaginate
172+ previousLabel = {
173+ < span >
174+ < FontAwesomeIcon icon = { faCaretLeft } /> < FontAwesomeIcon icon = { faCaretLeft } />
175+ </ span >
176+ }
177+ nextLabel = {
178+ < span >
179+ < FontAwesomeIcon icon = { faCaretRight } /> { ' ' }
180+ < FontAwesomeIcon icon = { faCaretRight } />
181+ </ span >
182+ }
183+ breakLabel = { '...' }
184+ breakClassName = { 'break-me' }
185+ pageCount = { Math . max ( activeNotifications . length / Notification . paginationSize ) }
186+ marginPagesDisplayed = { 1 }
187+ pageClassName = { 'atag' }
188+ pageRangeDisplayed = { 2 }
189+ activeLinkClassName = { 'active' }
190+ onPageChange = { this . handlePageClick }
191+ containerClassName = { 'pagination' }
192+ activeClassName = { 'active' }
163193 />
164- ) ) }
194+ </ Col >
195+ { activeNotifications . map ( ( { id, title, content, type, createdAt } , index ) =>
196+ index >= this . state . offset &&
197+ index <= this . state . offset + Notification . paginationSize - 1 ? (
198+ < NotificationElement
199+ createdAt = { createdAt }
200+ key = { id }
201+ id = { id }
202+ title = { title }
203+ content = { content }
204+ type = { type }
205+ deleteNotification = { deleteNotification }
206+ />
207+ ) : null ,
208+ ) }
165209 </ Row >
166210 </ >
167211 ) : (
0 commit comments