Skip to content

Commit

Permalink
redirect instead of showing siblings of child
Browse files Browse the repository at this point in the history
  • Loading branch information
mihai-macaneata committed Apr 8, 2020
1 parent 936a221 commit 83fc18e
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 8 deletions.
53 changes: 53 additions & 0 deletions src/components/theme/View/RedirectView.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Redirect } from 'react-router-dom';

class RedirectView extends Component {
constructor(props) {
super(props);
this.state = {
redirect: false,
};
console.log('topicsView');
}
static propTypes = {
content: PropTypes.shape({
title: PropTypes.string,

description: PropTypes.string,

items: PropTypes.arrayOf(
PropTypes.shape({
title: PropTypes.string,
description: PropTypes.string,
url: PropTypes.string,
image: PropTypes.object,
image_caption: PropTypes.string,
'@type': PropTypes.string,
}),
),
}).isRequired,
};

componentDidMount() {
const mainItem = this.props.content.items[0];
const mainUrl = mainItem && mainItem.url;
console.log('mainitem,mainurl', mainItem, mainUrl);
if (__CLIENT__ && mainUrl && window) {
this.setState({ redirect: mainUrl });
} else {
this.setState({ redirect: false });
}
}

render() {
console.log('redirect state', this.state.redirect);
if (this.state.redirect) {
return <Redirect to={{ pathname: this.state.redirect }} />;
} else {
return '';
}
}
}

export default RedirectView;
11 changes: 3 additions & 8 deletions src/localconfig.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import TabsView from '~/components/theme/View/TabsView';
import RedirectView from '~/components/theme/View/RedirectView';

import ChildrenListView from '~/components/manage/Blocks/DetailedLink/View';
import ChildrenListEdit from '~/components/manage/Blocks/DetailedLink/Edit';
Expand All @@ -11,6 +12,8 @@ console.log('config', config)
layoutViews: {
...config.views.layoutViews,
tabs_view: TabsView,
redirect_view: RedirectView,

},
};

Expand All @@ -25,14 +28,6 @@ console.log('config', config)
icon: config.blocks.blocksConfig.text.icon,
};

// config.blocks.blocksConfig.collection_block = {
// id: 'collection_block',
// title: 'Collection Listing',
// view: CollectionBlockView,
// edit: CollectionBlockEdit,
// icon: chartIcon,
// group: 'custom_addons',
// };
return config;
}

Expand Down

0 comments on commit 83fc18e

Please sign in to comment.