Skip to content

Commit

Permalink
Add start of EmbedCode templater
Browse files Browse the repository at this point in the history
  • Loading branch information
jvgomg committed Jun 2, 2016
1 parent 87afd54 commit c5886c6
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 24 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
"redux-thunk": "^2.0.0",
"rimraf": "^2.5.1",
"sass-loader": "^3.0.0",
"string-template": "^1.0.0",
"style-loader": "^0.13.0",
"url-loader": "^0.5.6",
"webpack": "^1.12.14",
Expand Down
22 changes: 22 additions & 0 deletions src/components/EmbedCode/EmbedCode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React, { PropTypes } from 'react';
import format from 'string-template';


const template = `
<script src="https://npmcdn.com/react@^15.0/dist/react.min.js"></script>
<script src="https://npmcdn.com/react-dom@^15.0/dist/react-dom.min.js"></script>
<script src="https://npmcdn.com/[email protected]/dist/react-climb-social.min.js"></script>
<div data-climb data-collection-id="{id}" data-layout="{layout}"></div>
`.replace(/\r?\n|\r/g, '');


const EmbedCode = ({ collectionId: id, layoutName: layout }) => (
<code>{format(template, { id, layout })}</code>
);

EmbedCode.propTypes = {
collectionId: PropTypes.string.isRequired,
layoutName: PropTypes.string.isRequired,
};

export default EmbedCode;
2 changes: 2 additions & 0 deletions src/components/EmbedCode/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import EmbedCode from './EmbedCode';
export default EmbedCode;
16 changes: 10 additions & 6 deletions src/routes/Home/components/DisplayPicker/DisplayPicker.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React, { PropTypes } from 'react';

import Navigation from './DisplayPickerNavigation';
import Stage from './DisplayPickerStage';
import EmbedCode from './DisplayPickerEmbedCode';

import EmbedCode from 'components/EmbedCode';
import FastInput from 'components/FastInput';

const DisplayPicker = ({ setCollection, collectionId, ...props }) => (

const DisplayPicker = ({ setCollection, collectionId, selected, ...props }) => (
<div>
<FastInput
type="text"
Expand All @@ -16,6 +17,7 @@ const DisplayPicker = ({ setCollection, collectionId, ...props }) => (
{collectionId?
<div>
<Navigation
selected={selected}
{...props}
/>

Expand All @@ -24,7 +26,11 @@ const DisplayPicker = ({ setCollection, collectionId, ...props }) => (
{...props}
/>

<EmbedCode />
<EmbedCode
collectionId={collectionId}
layoutName={selected.layout}
{...props}
/>
</div>
:
<div>
Expand All @@ -38,9 +44,7 @@ const DisplayPicker = ({ setCollection, collectionId, ...props }) => (

DisplayPicker.propTypes = {
collectionId: PropTypes.string,
options: PropTypes.arrayOf(PropTypes.object).isRequired,
selected: PropTypes.object.isRequired,
setDisplay: PropTypes.func.isRequired,
setCollection: PropTypes.func.isRequired,
};

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@ import React, { PropTypes } from 'react';
import { ClimbView } from 'react-climb-social';


const DisplayPickerStage = ({ collectionId, layout, ...props }) => (
const DisplayPickerStage = ({ layout, ...props }) => (
<ClimbView
collectionId={collectionId}
View={layout}
domain="http://curate.vm-08.graph.uk"
hostname="curate.vm-08.graph.uk"
{...props}
/>
);

DisplayPickerStage.propTypes = {
name: PropTypes.string,
layout: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
layout: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
collectionId: PropTypes.string,
};

Expand Down
10 changes: 6 additions & 4 deletions src/routes/Home/containers/DisplayPickerContainer.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { actions as displayActions } from '../modules/display';
import { findView } from 'react-climb-social';

import DisplayPicker from '../components/DisplayPicker';


const mapStateToProps = (state) => ({
collectionId: state.display.collectionId,
options: state.display.options,
selected: state.display.selected,
const mapStateToProps = ({ display }) => ({
collectionId: display.collectionId,
options: display.options,
selected: display.selected,
layout: findView(display.selected.layout),
});

const mapDispatchToProps = (dispatch) =>
Expand Down
1 change: 1 addition & 0 deletions src/routes/Home/modules/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const displayOptions = [
{
key: 'list',
name: 'List',
layout: 'list',
},
{
key: 'grid',
Expand Down
8 changes: 8 additions & 0 deletions tests/components/EmbedCode.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react'
import EmbedCode from 'components/EmbedCode/EmbedCode'

describe('(Component) EmbedCode', () => {
it('should exist', () => {

});
});

0 comments on commit c5886c6

Please sign in to comment.