-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
225 additions
and
37 deletions.
There are no files selected for viewing
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
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
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
151 changes: 151 additions & 0 deletions
151
src/customizations/volto/components/theme/View/DefaultView.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,151 @@ | ||
/** | ||
* Document view component. | ||
* @module components/theme/View/DefaultView | ||
*/ | ||
|
||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Helmet } from '@plone/volto/helpers'; | ||
import { defineMessages, injectIntl } from 'react-intl'; | ||
import { Portal } from 'react-portal'; | ||
|
||
import { Container, Image } from 'semantic-ui-react'; | ||
import { map } from 'lodash'; | ||
|
||
import { settings, blocks } from '~/config'; | ||
|
||
import { | ||
getBlocksFieldname, | ||
getBlocksLayoutFieldname, | ||
hasBlocksData, | ||
getBaseUrl, | ||
} from '@plone/volto/helpers'; | ||
|
||
const messages = defineMessages({ | ||
unknownBlock: { | ||
id: 'Unknown Block', | ||
defaultMessage: 'Unknown Block {block}', | ||
}, | ||
}); | ||
|
||
/** | ||
* Component to display the default view. | ||
* @function DefaultView | ||
* @param {Object} content Content object. | ||
* @returns {string} Markup of the component. | ||
*/ | ||
const DefaultView = ({ content, intl, location }) => { | ||
const blocksFieldname = getBlocksFieldname(content); | ||
const blocksLayoutFieldname = getBlocksLayoutFieldname(content); | ||
|
||
return hasBlocksData(content) ? ( | ||
<div> | ||
<Portal node={__CLIENT__ && document.querySelector('#header-leadimage')}> | ||
{content.image && ( | ||
<div className="leadimage-header"> | ||
<div className="leadimage-container"> | ||
<div className="leadimage-wrapper"> | ||
<div className="leadimage document-image" | ||
style={{ backgroundImage: `url(${content.image.download})` }} | ||
> | ||
</div> | ||
<div className="image-layer"></div> | ||
<div class="ui container image-content"> | ||
<h1 class="leadimage-title">{content.title}</h1> | ||
<p>{content.description}</p> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
)} | ||
</Portal> | ||
<div id="page-document" className="ui container"> | ||
<Helmet title={content.title} /> | ||
{map(content[blocksLayoutFieldname].items, block => { | ||
const Block = | ||
blocks.blocksConfig[content[blocksFieldname]?.[block]?.['@type']]?.[ | ||
'view' | ||
] || null; | ||
return Block !== null ? ( | ||
<Block | ||
key={block} | ||
id={block} | ||
properties={content} | ||
data={content[blocksFieldname][block]} | ||
path={getBaseUrl(location.pathname)} | ||
/> | ||
) : ( | ||
<div key={block}> | ||
{intl.formatMessage(messages.unknownBlock, { | ||
block: content[blocksFieldname]?.[block]?.['@type'], | ||
})} | ||
</div> | ||
); | ||
})} | ||
</div> | ||
</div> | ||
) : ( | ||
<Container id="page-document"> | ||
<Helmet title={content.title} /> | ||
<h1 className="documentFirstHeading">{content.title}</h1> | ||
{content.description && ( | ||
<p className="documentDescription">{content.description}</p> | ||
)} | ||
{content.image && ( | ||
<Image | ||
className="document-image" | ||
src={content.image.scales.thumb.download} | ||
floated="right" | ||
/> | ||
)} | ||
{content.remoteUrl && ( | ||
<span> | ||
The link address is: | ||
<a href={content.remoteUrl}>{content.remoteUrl}</a> | ||
</span> | ||
)} | ||
{content.text && ( | ||
<div | ||
dangerouslySetInnerHTML={{ | ||
__html: content.text.data.replace( | ||
/a href="([^"]*\.[^"]*)"/g, | ||
`a href="${settings.apiPath}$1/download/file"`, | ||
), | ||
}} | ||
/> | ||
)} | ||
</Container> | ||
); | ||
}; | ||
|
||
/** | ||
* Property types. | ||
* @property {Object} propTypes Property types. | ||
* @static | ||
*/ | ||
DefaultView.propTypes = { | ||
/** | ||
* Content of the object | ||
*/ | ||
content: PropTypes.shape({ | ||
/** | ||
* Title of the object | ||
*/ | ||
title: PropTypes.string, | ||
/** | ||
* Description of the object | ||
*/ | ||
description: PropTypes.string, | ||
/** | ||
* Text of the object | ||
*/ | ||
text: PropTypes.shape({ | ||
/** | ||
* Data of the text of the object | ||
*/ | ||
data: PropTypes.string, | ||
}), | ||
}).isRequired, | ||
}; | ||
|
||
export default injectIntl(DefaultView); |
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
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