diff --git a/public/styles.css b/public/styles.css index 36852f7..88a633a 100644 --- a/public/styles.css +++ b/public/styles.css @@ -120,5 +120,4 @@ body { .block-entry { border: 1px solid #ddd; - cursor: pointer; } diff --git a/src/containers/App.js b/src/containers/App.js index 4a42ee7..a755190 100644 --- a/src/containers/App.js +++ b/src/containers/App.js @@ -20,6 +20,19 @@ class App extends React.Component { this.handleChangeActiveTab = this.handleChangeActiveTab.bind(this); this.handleChangePreviewMode = this.handleChangePreviewMode.bind(this); this.handlePushBlock = this.handlePushBlock.bind(this); + this.handleMessage = this.handleMessage.bind(this); + } + + componentDidMount() { + window.addEventListener("message", this.handleMessage) + } + + componentWillUnmount() { + window.removeEventListener("message", this.handleMessage) + } + + handleMessage(event) { + console.log(event.data) } handleChangeActiveTab(index) { diff --git a/src/containers/BlocksGallery.js b/src/containers/BlocksGallery.js index 9e225f5..fd6f5e8 100644 --- a/src/containers/BlocksGallery.js +++ b/src/containers/BlocksGallery.js @@ -9,10 +9,9 @@ class BlocksGallery extends Component { {Object.keys(blocks).map(blockId => { const block = blocks[blockId]; if (block.category === this.props.category) { - return
+ return
{block.title}
diff --git a/src/reducers/layout.js b/src/reducers/layout.js index 0d9d2a9..8f6818a 100644 --- a/src/reducers/layout.js +++ b/src/reducers/layout.js @@ -19,7 +19,6 @@ export default function reducer(state = initialState, action) { } }] } - break; default: return state; } diff --git a/src/utils/renderHandlebars.js b/src/utils/renderHandlebars.js index da9cb07..2fc8ffe 100644 --- a/src/utils/renderHandlebars.js +++ b/src/utils/renderHandlebars.js @@ -1,11 +1,21 @@ import handlebars from "handlebars"; import document from "../views/document"; +import section from "../views/section"; import blocks from "../views/blocks"; function render(layoutBlocks) { const innerHTML = layoutBlocks.reduce((acc, layoutBlock) => { - const tpl = handlebars.compile(blocks[layoutBlock.blockId].component); - return `${acc}${tpl(layoutBlock.data)}`; + const blockHbs = blocks[layoutBlock.blockId].hbs; + const blockTemplate = handlebars.compile(blockHbs); + const blockHTML = blockTemplate(layoutBlock.data); + + const sectionTemplate = handlebars.compile(section); + const sectionHTML = sectionTemplate({ + content: blockHTML, + uuid: layoutBlock.uuid + }); + + return `${acc}${sectionHTML}`; }, ``); return handlebars.compile(document)({ diff --git a/src/views/blocks/a1.js b/src/views/blocks/a1.js index a3517f8..74efb17 100644 --- a/src/views/blocks/a1.js +++ b/src/views/blocks/a1.js @@ -1,4 +1,4 @@ -const component = ` +const hbs = `
@@ -37,7 +37,7 @@ const component = ` `; const block = { - component, + hbs, title: 'Article #1', preview: 'https://i.imgur.com/6QUsWtK.png', category: 'article', diff --git a/src/views/blocks/a2.js b/src/views/blocks/a2.js index 011f3b7..f5a27e8 100644 --- a/src/views/blocks/a2.js +++ b/src/views/blocks/a2.js @@ -1,4 +1,4 @@ -const component = ` +const hbs = `
@@ -28,7 +28,7 @@ const component = ` `; const block = { - component, + hbs, title: 'Article #2', preview: 'https://i.imgur.com/xljS5RC.png', category: 'article', diff --git a/src/views/blocks/g1.js b/src/views/blocks/g1.js index 638ffdb..89845bd 100644 --- a/src/views/blocks/g1.js +++ b/src/views/blocks/g1.js @@ -1,4 +1,4 @@ -const component = ` +const hbs = `
@@ -17,7 +17,7 @@ const component = ` `; const block = { - component, + hbs, title: 'Image Gallery #1', preview: 'https://i.imgur.com/EwoDspY.png', category: 'gallery', diff --git a/src/views/blocks/h1.js b/src/views/blocks/h1.js index 9c34a42..b9cfdf4 100644 --- a/src/views/blocks/h1.js +++ b/src/views/blocks/h1.js @@ -1,4 +1,4 @@ -const component = ` +const hbs = `
{{title}}

{{tagline}}

@@ -7,7 +7,7 @@ const component = ` `; const block = { - component, + hbs, title: 'Simple Header #1', preview: 'https://i.imgur.com/IXz7LZ5.png', category: 'header', diff --git a/src/views/blocks/h2.js b/src/views/blocks/h2.js index a07a8d2..db70eca 100644 --- a/src/views/blocks/h2.js +++ b/src/views/blocks/h2.js @@ -1,4 +1,4 @@ -const component = ` +const hbs = `

{{title}}

@@ -10,7 +10,7 @@ const component = ` `; const block = { - component, + hbs, title: 'Simple Header #2', preview: 'https://i.imgur.com/1bYEKB4.png', category: 'header', diff --git a/src/views/document.js b/src/views/document.js index a966add..cfc1be7 100644 --- a/src/views/document.js +++ b/src/views/document.js @@ -1,4 +1,4 @@ -export default ` +const document = ` @@ -11,6 +11,18 @@ export default ` {{{content}}} + `; + +export default document; diff --git a/src/views/section.js b/src/views/section.js new file mode 100644 index 0000000..0f9fb23 --- /dev/null +++ b/src/views/section.js @@ -0,0 +1,7 @@ +const section = ` +
+{{{content}}} +
+`; + +export default section;