This repository has been archived by the owner on Jun 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
SinglePage.js
73 lines (63 loc) · 1.64 KB
/
SinglePage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import React from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import { getComponentMarkup } from '../../actions/atomic';
import parentUrl from '../../helpers/parentUrl';
import Single from './Single';
import Loader from './../../components/Loader/Loader';
/**
* Will display the component as a raw page
*
* @class SinglePage
* @extends {Single}
*/
class SinglePage extends Single {
constructor() {
super();
this.state = {
component: {},
};
}
/**
* Disable links default behavious inside the page
*
* @param {Event} e
* @memberof SinglePage
*/
handlePageClick(e) {
// If it's a link related event, redirect to page
const linkParent = parentUrl(e.target);
if (linkParent) {
e.preventDefault();
if (linkParent.href.includes('pages')) {
const slug = linkParent.href.split('pages/').slice(-1)[0];
this.props.history.push(`/pages/${slug}`);
}
}
}
render() {
return (
<div>
{ undefined === this.state.component.content ? <Loader /> : '' }
<div role="presentation" onClick={this.handlePageClick.bind(this)} dangerouslySetInnerHTML={{ __html: this.state.component.content }} />
</div>
);
}
}
SinglePage.propTypes = {
history: PropTypes.object.isRequired,
components: PropTypes.object,
};
function mapState(state) {
return {
atomic: state.atomic,
navigation: state.navigation,
};
}
function mapDispatch(dispatch) {
return bindActionCreators({
getComponentMarkup,
}, dispatch);
}
export default connect(mapState, mapDispatch)(SinglePage);