Skip to content

Commit

Permalink
Merge pull request #101 from comicrelief/47_provide_menu_fallback_items
Browse files Browse the repository at this point in the history
Provide menu fallback items
  • Loading branch information
lebaz20 authored Nov 20, 2017
2 parents ac6474e + 1929465 commit cc4f7f2
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/components/Menu/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import connect from '../../utils/drupal-api-connector';
import MenuLink from './MenuLink/MenuLink';
import './menu.scss';

const cachedEndpointsUrl = 'https://cached-endpoints.spa.comicrelief.com/';

/**
* Menu class
*/
Expand All @@ -21,7 +23,17 @@ class Menu extends Component {
default:
this.source = 'https://www.comicrelief.com';
}
fetchLinks(this.source, type);
fetchLinks(this.source, type, '');
}
}

/**
* componentDidUpdate
*/
componentDidUpdate() {
const { menuFetch, type, campaign, fetchLinks } = this.props;
if (menuFetch && menuFetch.rejected && typeof campaign !== 'undefined' && typeof type !== 'undefined') {
fetchLinks(`${cachedEndpointsUrl}${campaign}`, type, '.json');
}
}

Expand All @@ -31,6 +43,7 @@ class Menu extends Component {
*/
render() {
const { menuFetch, type } = this.props;

if (menuFetch && menuFetch.fulfilled) {
const source = this.source;
return (
Expand All @@ -52,8 +65,8 @@ Menu.propTypes = {
};

export default connect(() => ({
fetchLinks: (source, type) => ({
menuFetch: `${source}/entity/menu/${type}/tree?_format=json`,
fetchLinks: (source, type, fileType) => ({
menuFetch: `${source}/entity/menu/${type}/tree${fileType}?_format=json`,
}),
}))(Menu);

0 comments on commit cc4f7f2

Please sign in to comment.