1
- import { faTrash } from '@fortawesome/free-solid-svg-icons' ;
1
+ import { faCaretLeft , faCaretRight , faTrash } from '@fortawesome/free-solid-svg-icons' ;
2
2
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' ;
3
3
import NotificationElement from 'app/containers/Notification/NotificationElement' ;
4
4
import * as styles from 'app/styles/Notification.module.css' ;
5
5
import * as NotificationInterfaces from 'app/types/Notification' ;
6
6
import classnames from 'classnames' ;
7
7
import * as React from 'react' ;
8
8
import { Col , Grid , Row } from 'react-bootstrap' ;
9
+ // tslint:disable-next-line
10
+ import ReactPaginate from 'react-paginate' ;
11
+
9
12
// tslint:disable-next-line
10
13
11
14
export class Notification extends React . Component <
12
15
NotificationInterfaces . Props ,
13
16
NotificationInterfaces . State
14
17
> {
18
+ private static paginationSize = 6 ;
19
+
15
20
constructor ( props : NotificationInterfaces . Props ) {
16
21
super ( props ) ;
17
22
this . state = {
18
23
activeNotificationTab : NotificationInterfaces . NotificationTabType . ALL ,
24
+ offset : 0 ,
19
25
tabType : NotificationInterfaces . TabType . NOTIFICATIONS ,
20
26
} ;
21
27
}
@@ -24,6 +30,12 @@ export class Notification extends React.Component<
24
30
this . props . getAllGlobalAnnouncements ( ) ;
25
31
}
26
32
33
+ public handlePageClick = ( data : { selected : number } ) => {
34
+ this . setState ( {
35
+ offset : Math . ceil ( data . selected * Notification . paginationSize ) ,
36
+ } ) ;
37
+ } ;
38
+
27
39
public render ( ) {
28
40
const { activeNotificationTab, tabType } = this . state ;
29
41
const { announcements, notifications, deleteNotificationType, deleteNotification } = this . props ;
@@ -151,17 +163,48 @@ export class Notification extends React.Component<
151
163
</ div >
152
164
</ Row >
153
165
< 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' }
163
192
/>
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
+ ) }
165
208
</ Row >
166
209
</ >
167
210
) : (
0 commit comments