design-comuni-plone-theme 11.17.0 → 11.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.yarn/cache/{volto-site-settings-npm-0.4.3-7926886a97-690d1c03a0.zip → volto-site-settings-npm-0.4.4-11da224a90-ef0c504b64.zip} +0 -0
- package/.yarn/install-state.gz +0 -0
- package/CHANGELOG.md +30 -0
- package/RELEASE.md +16 -0
- package/package.json +2 -2
- package/publiccode.yml +2 -2
- package/src/components/ItaliaTheme/AppExtras/SiteSettingsExtras.jsx +8 -2
- package/src/components/ItaliaTheme/Blocks/EventSearch/Body.jsx +1 -1
- package/src/components/ItaliaTheme/Blocks/UOSearch/Body.jsx +1 -1
- package/src/components/ItaliaTheme/BrandText/BrandText.jsx +14 -16
- package/src/components/ItaliaTheme/Header/HeaderSlim/HeaderSlim.jsx +8 -9
- package/src/components/ItaliaTheme/Pagination/Pagination.jsx +0 -1
- package/src/components/ItaliaTheme/View/Commons/RelatedArticles.jsx +11 -1
- package/src/components/ItaliaTheme/View/ServizioView/ServizioMetatag.jsx +7 -8
- package/src/components/ItaliaTheme/View/UOView/UOServices.jsx +5 -25
- package/src/config/italiaConfig.js +10 -1
- package/src/helpers/index.js +1 -0
- package/src/helpers/usePaginatedItemsSection.hook.ts +63 -0
|
Binary file
|
package/.yarn/install-state.gz
CHANGED
|
Binary file
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
+
## [11.18.1](https://github.com/RedTurtle/design-comuni-plone-theme/compare/v11.18.0...v11.18.1) (2024-07-25)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* removed fullobjects from query in EventSearch and UOSearch blocks ([#731](https://github.com/RedTurtle/design-comuni-plone-theme/issues/731)) ([1f48864](https://github.com/RedTurtle/design-comuni-plone-theme/commit/1f48864869e2086f28671899a6acaca1b87c23a8))
|
|
9
|
+
* set maxFileUploadSize config setting to 100mb in binary ([#725](https://github.com/RedTurtle/design-comuni-plone-theme/issues/725)) ([8bd05c0](https://github.com/RedTurtle/design-comuni-plone-theme/commit/8bd05c039e753159421c6d94d5166b5657f7b92a))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Documentation
|
|
13
|
+
|
|
14
|
+
* updated publiccode and release log ([c91931e](https://github.com/RedTurtle/design-comuni-plone-theme/commit/c91931e4591165b313fe0ca32f9c09295a8bd784))
|
|
15
|
+
|
|
16
|
+
## [11.18.0](https://github.com/RedTurtle/design-comuni-plone-theme/compare/v11.17.0...v11.18.0) (2024-07-19)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Features
|
|
20
|
+
|
|
21
|
+
* add pagination to cards listings in Venue, refactor pagination logic into custom hook ([#726](https://github.com/RedTurtle/design-comuni-plone-theme/issues/726)) ([305a467](https://github.com/RedTurtle/design-comuni-plone-theme/commit/305a46764ba337ff01ed576f06a6b2bf065e7ff6))
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### Bug Fixes
|
|
25
|
+
|
|
26
|
+
* site settings issues with race conditions and hook rendering ([5f350bc](https://github.com/RedTurtle/design-comuni-plone-theme/commit/5f350bc2548e7d835380d8a1631ca2d37afd1bff))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### Documentation
|
|
30
|
+
|
|
31
|
+
* updated publiccode and release log ([955ff49](https://github.com/RedTurtle/design-comuni-plone-theme/commit/955ff499c78b34fb472ce9ddf2df9267d0f432fe))
|
|
32
|
+
|
|
3
33
|
## [11.17.0](https://github.com/RedTurtle/design-comuni-plone-theme/compare/v11.16.0...v11.17.0) (2024-07-16)
|
|
4
34
|
|
|
5
35
|
|
package/RELEASE.md
CHANGED
|
@@ -41,6 +41,18 @@
|
|
|
41
41
|
- ...
|
|
42
42
|
-->
|
|
43
43
|
|
|
44
|
+
## Versione 11.18.1 (25/07/2024)
|
|
45
|
+
|
|
46
|
+
### Fix
|
|
47
|
+
|
|
48
|
+
- Migliorata la visualizzazione delle card risultato nella ricerca Eventi e Unità Organizzativa.
|
|
49
|
+
|
|
50
|
+
## Versione 11.18.0 (19/07/2024)
|
|
51
|
+
|
|
52
|
+
### Migliorie
|
|
53
|
+
|
|
54
|
+
- Aggiunta la paginazione per le card presenti sotto i campi "Sede di" e "Servizi presenti nel luogo", ora verranno mostrati solo 4 elementi alla volta.
|
|
55
|
+
|
|
44
56
|
## Versione 11.17.0 (16/07/2024)
|
|
45
57
|
|
|
46
58
|
### Novità
|
|
@@ -51,6 +63,10 @@
|
|
|
51
63
|
|
|
52
64
|
- Ripristinato il funzionamento del filtro luogo nella ricerca eventi.
|
|
53
65
|
|
|
66
|
+
### Migliorie
|
|
67
|
+
|
|
68
|
+
- Viene ora mostrato un errore parlante nel caso si tenti di caricare un file che superi le dimensioni massime consentite, di default 100mb, come già esplicitato sul manuale utente.
|
|
69
|
+
|
|
54
70
|
## Versione 11.16.0 (10/07/2024)
|
|
55
71
|
|
|
56
72
|
### Migliorie
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "design-comuni-plone-theme",
|
|
3
3
|
"description": "Volto Theme for Italia design guidelines",
|
|
4
4
|
"license": "GPL-v3",
|
|
5
|
-
"version": "11.
|
|
5
|
+
"version": "11.18.1",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -159,7 +159,7 @@
|
|
|
159
159
|
"volto-querywidget-with-browser": "0.4.2",
|
|
160
160
|
"volto-rss-block": "3.0.0",
|
|
161
161
|
"volto-secondarymenu": "4.1.1",
|
|
162
|
-
"volto-site-settings": "0.4.
|
|
162
|
+
"volto-site-settings": "0.4.4",
|
|
163
163
|
"volto-slimheader": "0.1.2",
|
|
164
164
|
"volto-social-settings": "3.0.0",
|
|
165
165
|
"volto-subblocks": "2.1.0",
|
package/publiccode.yml
CHANGED
|
@@ -227,9 +227,9 @@ maintenance:
|
|
|
227
227
|
name: io-Comune - Il sito AgID per Comuni ed Enti Pubblici
|
|
228
228
|
platforms:
|
|
229
229
|
- web
|
|
230
|
-
releaseDate: '2024-07-
|
|
230
|
+
releaseDate: '2024-07-25'
|
|
231
231
|
softwareType: standalone/web
|
|
232
|
-
softwareVersion: 11.
|
|
232
|
+
softwareVersion: 11.18.1
|
|
233
233
|
url: 'https://github.com/italia/design-comuni-plone-theme'
|
|
234
234
|
usedBy:
|
|
235
235
|
- ASP Comuni Modenesi Area Nord
|
|
@@ -5,30 +5,36 @@ CUSTOMIZATIONS:
|
|
|
5
5
|
|
|
6
6
|
import React from 'react';
|
|
7
7
|
import { useIntl } from 'react-intl';
|
|
8
|
+
import { useSelector } from 'react-redux';
|
|
8
9
|
import { Helmet } from '@plone/volto/helpers';
|
|
9
10
|
import { SiteProperty } from 'volto-site-settings';
|
|
10
11
|
import { getSiteProperty } from 'design-comuni-plone-theme/helpers';
|
|
11
12
|
|
|
12
13
|
const SiteSettingsExtras = (props) => {
|
|
13
14
|
const intl = useIntl();
|
|
15
|
+
const subsite = useSelector((state) => state.subsite?.data);
|
|
14
16
|
let siteTitle = SiteProperty({
|
|
15
17
|
property: 'site_title',
|
|
16
18
|
getValue: true,
|
|
17
19
|
defaultValue: getSiteProperty('siteTitle', intl.locale),
|
|
20
|
+
// TODO DEPRECATED: remove and only use defaultValue in v12
|
|
21
|
+
forceValue: subsite?.title || getSiteProperty('siteTitle', intl.locale),
|
|
18
22
|
});
|
|
19
23
|
|
|
20
24
|
const parentSiteTitle = SiteProperty({
|
|
21
25
|
property: 'site_title',
|
|
22
26
|
getValue: true,
|
|
23
27
|
getParent: true,
|
|
24
|
-
defaultValue: getSiteProperty('
|
|
28
|
+
defaultValue: getSiteProperty('siteTitle', intl.locale),
|
|
29
|
+
// TODO DEPRECATED: remove and only use defaultValue in v12
|
|
30
|
+
forceValue: getSiteProperty('siteTitle', intl.locale),
|
|
25
31
|
});
|
|
26
32
|
|
|
27
33
|
if (parentSiteTitle !== siteTitle) {
|
|
28
34
|
siteTitle = siteTitle + ' - ' + parentSiteTitle;
|
|
29
35
|
}
|
|
30
36
|
|
|
31
|
-
siteTitle = siteTitle
|
|
37
|
+
siteTitle = siteTitle?.replaceAll('\\n', ' - ') ?? '';
|
|
32
38
|
|
|
33
39
|
return <Helmet titleTemplate={`%s - ${siteTitle}`} />;
|
|
34
40
|
};
|
|
@@ -98,8 +98,8 @@ const Body = ({ data, id, inEditMode, path, onChangeBlock }) => {
|
|
|
98
98
|
getQueryStringResults(
|
|
99
99
|
subsite ? flattenToAppURL(subsite['@id']) : '',
|
|
100
100
|
{
|
|
101
|
-
fullobjects: 1,
|
|
102
101
|
query: query,
|
|
102
|
+
metadata: '_all',
|
|
103
103
|
b_size: b_size,
|
|
104
104
|
sort_order: 'ascending',
|
|
105
105
|
sort_on: 'start',
|
|
@@ -9,26 +9,24 @@ const BrandText = ({ mobile = false, subsite, getParent = false }) => {
|
|
|
9
9
|
// TODO DEPRECATED: remove and only use SiteProperty
|
|
10
10
|
const deprecatedSiteTitle =
|
|
11
11
|
subsite?.title || getSiteProperty('siteTitle', intl.locale);
|
|
12
|
-
let title =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
});
|
|
12
|
+
let title = SiteProperty({
|
|
13
|
+
property: 'site_title',
|
|
14
|
+
forceValue: deprecatedSiteTitle,
|
|
15
|
+
defaultValue: getSiteProperty('siteTitle', intl.locale),
|
|
16
|
+
getValue: true,
|
|
17
|
+
getParent: getParent,
|
|
18
|
+
});
|
|
20
19
|
|
|
21
20
|
// TODO DEPRECATED: remove and only use SiteProperty
|
|
22
21
|
const deprecatedSiteSubtitle =
|
|
23
22
|
subsite?.description || getSiteProperty('siteSubtitle', intl.locale);
|
|
24
|
-
const description =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
});
|
|
23
|
+
const description = SiteProperty({
|
|
24
|
+
property: 'site_subtitle',
|
|
25
|
+
forceValue: deprecatedSiteSubtitle,
|
|
26
|
+
defaultValue: getSiteProperty('siteSubtitle', intl.locale),
|
|
27
|
+
getValue: true,
|
|
28
|
+
getParent: getParent,
|
|
29
|
+
});
|
|
32
30
|
const titleSplit = title?.split('\n') ?? null;
|
|
33
31
|
title = titleSplit?.map((t, i) => (
|
|
34
32
|
<React.Fragment key={i}>
|
|
@@ -35,14 +35,13 @@ const HeaderSlim = () => {
|
|
|
35
35
|
intl.locale,
|
|
36
36
|
);
|
|
37
37
|
|
|
38
|
-
const subsiteParentSiteTitle =
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
});
|
|
38
|
+
const subsiteParentSiteTitle = SiteProperty({
|
|
39
|
+
property: 'site_title',
|
|
40
|
+
forceValue: deprecatedSubsiteParentSiteTitle,
|
|
41
|
+
defaultValue: getSiteProperty('subsiteParentSiteTitle', intl.locale),
|
|
42
|
+
getValue: true,
|
|
43
|
+
getParent: true,
|
|
44
|
+
});
|
|
46
45
|
|
|
47
46
|
const target = subsite ? null : '_blank';
|
|
48
47
|
return (
|
|
@@ -55,7 +54,7 @@ const HeaderSlim = () => {
|
|
|
55
54
|
rel="noopener noreferrer"
|
|
56
55
|
>
|
|
57
56
|
{!subsite && staticParentSiteTitle}
|
|
58
|
-
{subsite && subsiteParentSiteTitle
|
|
57
|
+
{subsite && (subsiteParentSiteTitle?.replaceAll('\\n', ' - ') ?? '')}
|
|
59
58
|
</HeaderBrand>
|
|
60
59
|
<HeaderRightZone>
|
|
61
60
|
<HeaderSlimRightZone />
|
|
@@ -58,7 +58,6 @@ class Pagination extends Component {
|
|
|
58
58
|
|
|
59
59
|
handleItemClick = (e, nextActivePage) => {
|
|
60
60
|
const { activePage: prevActivePage } = this.state;
|
|
61
|
-
|
|
62
61
|
// Heads up! We need the cast to the "number" type there, as `activePage` can be a string
|
|
63
62
|
if (+prevActivePage === +nextActivePage) return;
|
|
64
63
|
this.setState({ activePage: nextActivePage.children });
|
|
@@ -2,6 +2,8 @@ import React from 'react';
|
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import cx from 'classnames';
|
|
4
4
|
import { OfficeCard } from 'design-comuni-plone-theme/components/ItaliaTheme/View';
|
|
5
|
+
import { usePaginatedItemsSection } from 'design-comuni-plone-theme/helpers';
|
|
6
|
+
import { Pagination } from 'design-comuni-plone-theme/components/ItaliaTheme';
|
|
5
7
|
|
|
6
8
|
const RelatedArticles = ({
|
|
7
9
|
id = 'related-articles',
|
|
@@ -12,6 +14,9 @@ const RelatedArticles = ({
|
|
|
12
14
|
show_title = true,
|
|
13
15
|
noMargin = false,
|
|
14
16
|
}) => {
|
|
17
|
+
const { batches, currentPage, onPaginationChange, pageNumbers } =
|
|
18
|
+
usePaginatedItemsSection({ data: items });
|
|
19
|
+
|
|
15
20
|
return (
|
|
16
21
|
<article
|
|
17
22
|
id={id}
|
|
@@ -27,7 +32,7 @@ const RelatedArticles = ({
|
|
|
27
32
|
) : null}
|
|
28
33
|
|
|
29
34
|
<div className="card-wrapper card-teaser-wrapper card-teaser-wrapper-equal">
|
|
30
|
-
{
|
|
35
|
+
{batches?.map((item, i) => (
|
|
31
36
|
<OfficeCard
|
|
32
37
|
key={item['@id']}
|
|
33
38
|
office={item}
|
|
@@ -36,6 +41,11 @@ const RelatedArticles = ({
|
|
|
36
41
|
/>
|
|
37
42
|
))}
|
|
38
43
|
</div>
|
|
44
|
+
<Pagination
|
|
45
|
+
activePage={currentPage}
|
|
46
|
+
totalPages={pageNumbers}
|
|
47
|
+
onPageChange={onPaginationChange}
|
|
48
|
+
/>
|
|
39
49
|
</article>
|
|
40
50
|
);
|
|
41
51
|
};
|
|
@@ -18,14 +18,13 @@ const ServizioMetatag = ({ content }) => {
|
|
|
18
18
|
const intl = useIntl();
|
|
19
19
|
// TODO DEPRECATED use only SiteProperty
|
|
20
20
|
const deprecatedSiteTitle = getSiteProperty('siteTitle', intl.locale);
|
|
21
|
-
let siteTitle =
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
siteTitle = siteTitle.replaceAll('\\n', ' - ');
|
|
21
|
+
let siteTitle = SiteProperty({
|
|
22
|
+
property: 'site_title',
|
|
23
|
+
forceValue: deprecatedSiteTitle,
|
|
24
|
+
getValue: true,
|
|
25
|
+
defaultTitle: getSiteProperty('siteTitle', intl.locale),
|
|
26
|
+
});
|
|
27
|
+
siteTitle = siteTitle?.replaceAll('\\n', ' - ') ?? '';
|
|
29
28
|
|
|
30
29
|
const schemaOrg = {
|
|
31
30
|
'@context': 'https://schema.org',
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
} from 'design-react-kit';
|
|
12
12
|
import { Pagination } from 'design-comuni-plone-theme/components/ItaliaTheme';
|
|
13
13
|
import { UniversalLink } from '@plone/volto/components';
|
|
14
|
+
import { usePaginatedItemsSection } from 'design-comuni-plone-theme/helpers';
|
|
14
15
|
|
|
15
16
|
const messages = defineMessages({
|
|
16
17
|
servizi_offerti: {
|
|
@@ -19,34 +20,15 @@ const messages = defineMessages({
|
|
|
19
20
|
},
|
|
20
21
|
});
|
|
21
22
|
|
|
22
|
-
//* Pagination **/
|
|
23
|
-
const divideServicesIntoBatches = (arr, batchSize) => {
|
|
24
|
-
const batches = [];
|
|
25
|
-
for (let i = 0; i < arr.length; i += batchSize) {
|
|
26
|
-
batches.push(arr.slice(i, i + batchSize));
|
|
27
|
-
}
|
|
28
|
-
return batches;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
23
|
const UOServices = ({ content }) => {
|
|
32
24
|
const intl = useIntl();
|
|
33
25
|
|
|
34
|
-
const [currentPage, setCurrentPage] = useState(1);
|
|
35
|
-
const bSize = 4;
|
|
36
|
-
|
|
37
|
-
//* Calcolo numero pagine
|
|
38
|
-
|
|
39
26
|
const servizi_offerti =
|
|
40
27
|
content.servizi_offerti === undefined || content.servizi_offerti === null
|
|
41
28
|
? []
|
|
42
29
|
: content.servizi_offerti;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const onPaginationChange = (activePage) => {
|
|
47
|
-
const current = activePage?.children ?? 1;
|
|
48
|
-
setCurrentPage(current);
|
|
49
|
-
};
|
|
30
|
+
const { batches, currentPage, onPaginationChange, pageNumbers } =
|
|
31
|
+
usePaginatedItemsSection({ data: servizi_offerti });
|
|
50
32
|
|
|
51
33
|
return content?.servizi_offerti?.length > 0 ? (
|
|
52
34
|
<section
|
|
@@ -57,9 +39,7 @@ const UOServices = ({ content }) => {
|
|
|
57
39
|
{intl.formatMessage(messages.servizi_offerti)}
|
|
58
40
|
</h2>
|
|
59
41
|
<Row className="card-wrapper card-teaser-wrapper align-items-stretch">
|
|
60
|
-
{
|
|
61
|
-
currentPage - 1
|
|
62
|
-
]?.map((servizio, i) => (
|
|
42
|
+
{batches?.map((servizio, i) => (
|
|
63
43
|
<Col xs="12" lg="6">
|
|
64
44
|
<Card className="shadow rounded card-big-io-comune p-3 my-3">
|
|
65
45
|
<CardBody>
|
|
@@ -79,7 +59,7 @@ const UOServices = ({ content }) => {
|
|
|
79
59
|
<Pagination
|
|
80
60
|
activePage={currentPage}
|
|
81
61
|
totalPages={pageNumbers}
|
|
82
|
-
onPageChange={
|
|
62
|
+
onPageChange={onPaginationChange}
|
|
83
63
|
/>
|
|
84
64
|
</div>
|
|
85
65
|
</section>
|
|
@@ -127,6 +127,16 @@ export default function applyConfig(voltoConfig) {
|
|
|
127
127
|
errorPages: true,
|
|
128
128
|
},
|
|
129
129
|
},
|
|
130
|
+
/*
|
|
131
|
+
Set to 100mb in BINARY bytes, not decimal, see volto/helpers/FormValidation.js.validateFileUploadSize error message
|
|
132
|
+
...
|
|
133
|
+
messages.fileTooLarge, {
|
|
134
|
+
limit: `${Math.floor(
|
|
135
|
+
config.settings.maxFileUploadSize / 1024 / 1024,
|
|
136
|
+
)}MB`,
|
|
137
|
+
}
|
|
138
|
+
*/
|
|
139
|
+
maxFileUploadSize: 104857600,
|
|
130
140
|
querystringAdditionalFields: [],
|
|
131
141
|
searchBlockTemplates: [
|
|
132
142
|
'simpleCard',
|
|
@@ -305,7 +315,6 @@ export default function applyConfig(voltoConfig) {
|
|
|
305
315
|
component: SiteSettingsExtras,
|
|
306
316
|
},
|
|
307
317
|
],
|
|
308
|
-
maxFileUploadSize: null,
|
|
309
318
|
'volto-blocks-widget': {
|
|
310
319
|
allowedBlocks: [
|
|
311
320
|
...(config.settings['volto-blocks-widget']?.allowedBlocks ?? []).filter(
|
package/src/helpers/index.js
CHANGED
|
@@ -53,3 +53,4 @@ export { commonSearchBlockMessages } from 'design-comuni-plone-theme/helpers/Tra
|
|
|
53
53
|
|
|
54
54
|
export { getComponentWithFallback } from 'design-comuni-plone-theme/helpers/registry';
|
|
55
55
|
export { useHomePath } from 'design-comuni-plone-theme/helpers/url';
|
|
56
|
+
export { usePaginatedItemsSection } from 'design-comuni-plone-theme/helpers/usePaginatedItemsSection.hook.ts';
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { useState, useMemo } from 'react';
|
|
2
|
+
import type { IntlShape } from 'react-intl';
|
|
3
|
+
|
|
4
|
+
interface usePaginatedItemsSectionProps {
|
|
5
|
+
data: Array<any> | null | undefined;
|
|
6
|
+
bSize?: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
type ActivePage = {
|
|
10
|
+
active: boolean;
|
|
11
|
+
type: 'pageItem' | string;
|
|
12
|
+
ellipsisItem: '...' | string | null | undefined;
|
|
13
|
+
isPrevButtonInactive: boolean;
|
|
14
|
+
isForwButtonInactive: boolean;
|
|
15
|
+
children: number;
|
|
16
|
+
intl: IntlShape;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
type PaginationFunctionExtraArgs = {
|
|
20
|
+
activePage: ActivePage;
|
|
21
|
+
onClick: (
|
|
22
|
+
e: MouseEvent | KeyboardEvent,
|
|
23
|
+
obj: PaginationFunctionExtraArgs,
|
|
24
|
+
) => void;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const DEFAULT_PAGINATED_CARDS_SECTION_BSIZE = 4;
|
|
28
|
+
|
|
29
|
+
function getBatches(
|
|
30
|
+
arr: usePaginatedItemsSectionProps['data'],
|
|
31
|
+
batchSize: number,
|
|
32
|
+
): any[][] {
|
|
33
|
+
const batches = [];
|
|
34
|
+
if (arr) {
|
|
35
|
+
for (let i = 0; i < arr.length; i += batchSize) {
|
|
36
|
+
batches.push(arr.slice(i, i + batchSize));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return batches;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function usePaginatedItemsSection({
|
|
43
|
+
data,
|
|
44
|
+
bSize = DEFAULT_PAGINATED_CARDS_SECTION_BSIZE,
|
|
45
|
+
}: usePaginatedItemsSectionProps) {
|
|
46
|
+
const [currentPage, setCurrentPage] = useState<number>(1);
|
|
47
|
+
|
|
48
|
+
const pageNumbers = data ? Math.ceil(data.length / bSize) : 0;
|
|
49
|
+
|
|
50
|
+
const onPaginationChange = (
|
|
51
|
+
_e: MouseEvent | KeyboardEvent,
|
|
52
|
+
{ activePage }: PaginationFunctionExtraArgs,
|
|
53
|
+
) => {
|
|
54
|
+
const current = activePage?.children ?? 1;
|
|
55
|
+
setCurrentPage(current);
|
|
56
|
+
};
|
|
57
|
+
const batches: Array<any> = useMemo(() => {
|
|
58
|
+
const currentIndex = currentPage - 1;
|
|
59
|
+
return getBatches(data, bSize)[currentIndex];
|
|
60
|
+
}, [data, bSize, currentPage]);
|
|
61
|
+
|
|
62
|
+
return { batches, currentPage, onPaginationChange, pageNumbers };
|
|
63
|
+
}
|