@@ -11,6 +11,7 @@ import {
1111import Toolbar from '@plone/volto/components/manage/Toolbar/Toolbar' ;
1212import Error from '@plone/volto/components/theme/Error/Error' ;
1313import Icon from '@plone/volto/components/theme/Icon/Icon' ;
14+ import Pagination from '@plone/volto/components/theme/Pagination/Pagination' ;
1415import { getParentUrl } from '@plone/volto/helpers/Url/Url' ;
1516import { useClient } from '@plone/volto/hooks' ;
1617import React , { useEffect , useState } from 'react' ;
@@ -74,9 +75,17 @@ const KeywordManager = (props) => {
7475 const [ selectedRadio , setSelectedRadio ] = useState < string > ( 'select' ) ;
7576 const [ name , setName ] = useState < null | string > ( null ) ;
7677 const [ index , setIndex ] = useState < string > ( 'Subject' ) ;
78+ // Pagination
79+ const [ currentPage , setCurrentPage ] = useState < number > ( 0 ) ;
80+ const [ pageSize , setPageSize ] = useState < number > ( 25 ) ;
81+
82+ const options = {
83+ batchSize : pageSize ,
84+ batchStart : currentPage ,
85+ } ;
7786
7887 useEffect ( ( ) => {
79- dispatch ( getKeywords ( ) ) ;
88+ dispatch ( getKeywords ( options ) ) ;
8089 dispatch ( getKeywordIndexes ( ) ) ;
8190 } , [ ] ) ;
8291
@@ -85,13 +94,13 @@ const KeywordManager = (props) => {
8594 } ;
8695
8796 const handleDeleteKeywords = async ( kw : string | Array < string > ) => {
88- await dispatch ( deleteKeywords ( { items : kw } ) ) ;
89- dispatch ( getKeywords ( ) ) ;
97+ dispatch ( deleteKeywords ( { items : kw } ) ) . then ( ( ) => dispatch ( getKeywords ( ) ) ) ;
9098 } ;
9199
92100 const handleUpdateKeywords = async ( kw : string , olds : Array < string > ) => {
93- await dispatch ( updateKeywords ( { new_keyword : kw , old_keywords : olds } ) ) ;
94- dispatch ( getKeywords ( ) ) ;
101+ dispatch ( updateKeywords ( { new_keyword : kw , old_keywords : olds } ) ) . then ( ( ) =>
102+ dispatch ( getKeywords ( ) ) ,
103+ ) ;
95104 } ;
96105
97106 if ( keywords . loading ) {
@@ -321,17 +330,41 @@ const KeywordManager = (props) => {
321330 actions : (
322331 < >
323332 < Button onPress = { ( ) => onShowKeyword ( kw . name ) } >
324- < Icon name = { showSVG } />
333+ < Icon name = { showSVG } size = "20px" />
325334 </ Button >
326335 < Button onPress = { ( ) => handleDeleteKeywords ( kw . name ) } >
327- < Icon name = { trashSVG } />
336+ < Icon name = { trashSVG } size = "20px" />
328337 </ Button >
329338 </ >
330339 ) ,
331340 } ) ) }
332341 selectionMode = "multiple"
333342 onSelectionChange = { setSelectedKeys }
334343 />
344+ < Pagination
345+ current = { currentPage }
346+ total = { Math . ceil ( keywords ?. items_total / pageSize ) }
347+ pageSize = { pageSize }
348+ pageSizes = { [ 25 , 50 , 100 ] }
349+ onChangePage = { ( e , { value } ) => {
350+ setCurrentPage ( value ) ;
351+ dispatch (
352+ getKeywords ( {
353+ batchSize : pageSize ,
354+ batchStart : pageSize * value ,
355+ } ) ,
356+ ) ;
357+ } }
358+ onChangePageSize = { ( e , { value } ) => {
359+ setPageSize ( value ) ;
360+ dispatch (
361+ getKeywords ( {
362+ batchSize : value ,
363+ batchStart : currentPage ,
364+ } ) ,
365+ ) ;
366+ } }
367+ />
335368 { isClient &&
336369 createPortal (
337370 < Toolbar
0 commit comments