forked from geosolutions-it/geonode-mapstore-client
-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Featured box glitch when loading the home page (#755)
- Loading branch information
1 parent
d754ecd
commit 985ce9e
Showing
2 changed files
with
106 additions
and
93 deletions.
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
geonode_mapstore_client/client/js/components/FeaturedList/Cards.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* Copyright 2020, GeoSolutions Sas. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import React, { useEffect } from 'react'; | ||
import ResourceCard from '@js/components/ResourceCard'; | ||
import { withResizeDetector } from 'react-resize-detector'; | ||
import { getResourceStatuses } from '@js/utils/ResourceUtils'; | ||
|
||
const Cards = ({ | ||
resources, | ||
formatHref, | ||
isCardActive, | ||
buildHrefByTemplate, | ||
containerWidth, | ||
width: detectedWidth, | ||
options, | ||
onResize, | ||
actions, | ||
onAction | ||
}) => { | ||
const width = detectedWidth || containerWidth; | ||
const margin = 24; | ||
const size = 320; | ||
const countNum = Math.floor(width / (size + margin)); | ||
const count = countNum > 4 ? 4 : countNum; // limit count in order not to request for more than 4 per page | ||
const cardWidth = width >= size + margin * 2 | ||
? Math.floor((width - margin * count) / count) | ||
: '100%'; | ||
useEffect(() => { | ||
onResize(count); | ||
}, [count]); | ||
const ulPadding = Math.floor(margin / 2); | ||
const isSingleCard = count === 0 || count === 1; | ||
|
||
const gridLayoutSpace = (idx) => { | ||
|
||
const gridSpace = isSingleCard | ||
? { | ||
width: width - margin, | ||
margin: ulPadding | ||
} | ||
: { | ||
width: cardWidth, | ||
marginRight: (idx + 1) % count === 0 ? 0 : margin, | ||
marginTop: 8 | ||
}; | ||
|
||
return gridSpace; | ||
}; | ||
|
||
const containerStyle = isSingleCard | ||
? { | ||
paddingBottom: 0 | ||
} | ||
: { | ||
paddingLeft: ulPadding, | ||
paddingBottom: 0 | ||
}; | ||
return (detectedWidth ? | ||
<ul | ||
style={containerStyle} | ||
> | ||
{resources.map((resource, idx) => { | ||
const { | ||
isProcessing, | ||
isDeleted | ||
} = getResourceStatuses(resource); | ||
|
||
if (isDeleted) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<li | ||
key={resource?.pk} | ||
style={(gridLayoutSpace(idx))} | ||
> | ||
<ResourceCard | ||
active={isCardActive(resource)} | ||
className={`${isDeleted ? 'deleted' : ''}`} | ||
data={resource} | ||
formatHref={formatHref} | ||
options={options} | ||
buildHrefByTemplate={buildHrefByTemplate} | ||
layoutCardsStyle="grid" | ||
loading={isProcessing} | ||
readOnly={isDeleted || isProcessing} | ||
featured | ||
actions={actions} | ||
onAction={onAction} | ||
/> | ||
</li> | ||
); | ||
})} | ||
</ul> : <div /> | ||
); | ||
}; | ||
|
||
export default withResizeDetector(Cards); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters