Skip to content

Commit

Permalink
override listing view correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
nileshgulia1 committed May 27, 2021
1 parent 096581b commit f8cc8a0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 77 deletions.
33 changes: 3 additions & 30 deletions src/components/manage/Blocks/Listing/ListTemplate.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import React, { useEffect } from 'react';
import { shallowEqual, useSelector, useDispatch } from 'react-redux';
import React from 'react';

import PropTypes from 'prop-types';
import { FormattedDate } from 'react-intl';
import config from '@plone/volto/registry';
import { Item, Breadcrumb } from 'semantic-ui-react';
import { Link } from 'react-router-dom';
import { getBaseUrl } from '@plone/volto/helpers';
import { getContent } from '@plone/volto/actions';

const getPath = (url) => {
return url
Expand All @@ -15,32 +13,7 @@ const getPath = (url) => {
};

const ListTemplate = (props) => {
const { block, data = {}, isEditMode } = props;

const sort_on =
(isEditMode ? props.sort_on : props.content?.sort_on) || 'created';

const items = isEditMode ? props.items : props.content?.items;

const dispatch = useDispatch();
useEffect(() => {
loadContent();
}, []);

const getRequestKey = () => {
return `col-content:${block}`;
};

const loadContent = () => {
const path = isEditMode ? props.pathname : data.collection_url;
if (!path) return;
const url = `${getBaseUrl(path)}`;
const options = {
metadata_fields: '_all',
is_search: 1,
};
dispatch(getContent(url, null, getRequestKey(), options));
};
const { items, sort_on = 'created' } = props;

const searchItems = items?.sort(
(a, b) => new Date(b[sort_on]) - new Date(a[sort_on]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,13 @@
import React from 'react';
import { Helmet } from '@plone/volto/helpers';
import { Container, Item } from 'semantic-ui-react';
import { map, find } from 'lodash';
import { compose } from 'redux';
import { defineMessages, injectIntl } from 'react-intl';
import { find } from 'lodash';
//import BlockView from './BlockView';
import ListingBlockTemplate from '@eeacms/volto-energy-theme/components/manage/Blocks/Listing/ListTemplate';
import {
getBlocksFieldname,
getBlocksLayoutFieldname,
hasBlocksData,
} from '@plone/volto/helpers';
import { getBaseUrl } from '@plone/volto/helpers';
import config from '@plone/volto/registry';

/**
* List view component class.
Expand All @@ -26,24 +21,12 @@ import config from '@plone/volto/registry';
* @returns {string} Markup of the component.
*/

const messages = defineMessages({
unknownBlock: {
id: 'Unknown Block',
defaultMessage: 'Unknown Block {block}',
},
});

const ListingView = (props) => {
const { content } = props;
const intl = props.intl;

const blocksFieldname = getBlocksFieldname(content);
const blocksLayoutFieldname = getBlocksLayoutFieldname(content);

let url = content['@id']
.replace(config.settings.internalApiPath, '')
.replace(config.settings.apiPath, '');
url = getBaseUrl(url);

const getListingBlock = () => {
return find(
content[blocksLayoutFieldname].items,
Expand All @@ -53,11 +36,7 @@ const ListingView = (props) => {

const listingBlockid = getListingBlock();

const Block =
config.blocks.blocksConfig[
content[blocksFieldname]?.[listingBlockid]?.['@type']
]?.['view'] || null;

const listingBlockProps = content[blocksFieldname]?.[listingBlockid] || {};
return (
<Container id="page-search" className="">
<Helmet title={content.title} />
Expand All @@ -83,26 +62,14 @@ const ListingView = (props) => {
{content.description}
</p>
)}
{Block !== null ? (
<>
<Block
key={`block-${listingBlockid}`}
blockID={listingBlockid}
properties={content}
data={content[blocksFieldname][listingBlockid]}
/>
</>
) : (
<div key={`blocktype-${listingBlockid}`}>
{intl.formatMessage(messages.unknownBlock, {
block: content[blocksFieldname]?.[listingBlockid]?.['@type'],
})}
</div>
)}
<ListingBlockTemplate
items={content.items}
{...listingBlockProps}
/>
</Item.Group>
</div>
</section>
</Container>
);
};
export default compose(injectIntl)(ListingView);
export default ListingView;
6 changes: 0 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,6 @@ export default function applyConfig(config) {
topics_view: TopicsView,
topic_tab_view: TopicsTabView,
},
contentTypesViews: {
...config.views.contentTypesViews,
Collection: ListingView,
// EmbeddedMap: MapView,
// embeddedmap: MapView,
},
};

config.widgets = {
Expand Down

0 comments on commit f8cc8a0

Please sign in to comment.