Skip to content

Commit

Permalink
more coverPrefs boilerplate #223
Browse files Browse the repository at this point in the history
isRequired and fallback {} so I don't need safety everywhere
  • Loading branch information
forresto committed Jul 29, 2016
1 parent 0b4d179 commit 9d1ca41
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
12 changes: 7 additions & 5 deletions src/components/attribution-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ class AttributionEditor extends React.Component {
clearTimeout(this.hideDropIndicatorTimeout)
}
render () {
const {coverPrefs} = this.props
const {block} = this.state
const {type, metadata, cover} = block
const schema = blockMetaSchema[type] || blockMetaSchema.default

const menus = renderMenus(type, schema, metadata, cover, this.boundOnChange, this.boundOnMoreClick, this.boundOnUploadRequest, this.boundOnCoverRemove)
const menus = renderMenus(type, schema, metadata, cover, this.boundOnChange, this.boundOnMoreClick, this.boundOnUploadRequest, this.boundOnCoverRemove, coverPrefs)

return el('div'
, { className: 'AttributionEditor'
Expand Down Expand Up @@ -332,7 +333,7 @@ AttributionEditor.childContextTypes =
AttributionEditor.propTypes =
{ initialBlock: React.PropTypes.object.isRequired
, id: React.PropTypes.string.isRequired
, coverPrefs: React.PropTypes.object
, coverPrefs: React.PropTypes.object.isRequired
}
export default React.createFactory(AttributionEditor)

Expand Down Expand Up @@ -370,7 +371,7 @@ function renderTextField (key, label, value, onChange) {
)
}

function renderMenus (type, schema, metadata = {}, cover, onChange, onMoreClick, onUploadRequest, onCoverRemove) {
function renderMenus (type, schema, metadata = {}, cover, onChange, onMoreClick, onUploadRequest, onCoverRemove, siteCoverPrefs) {
let menus = []
if (schema.isBasedOnUrl && metadata.isBasedOnUrl != null) {
menus.push(
Expand Down Expand Up @@ -398,7 +399,7 @@ function renderMenus (type, schema, metadata = {}, cover, onChange, onMoreClick,
const allowCoverChange = schema.changeCover
const allowCoverRemove = (cover && schema.removeCover)
menus.push(
renderImageEditor(hasCover, allowCoverChange, allowCoverRemove, type, metadata.title, metadata.coverPrefs, onChange, onUploadRequest, onCoverRemove)
renderImageEditor(hasCover, allowCoverChange, allowCoverRemove, type, metadata.title, metadata.coverPrefs, onChange, onUploadRequest, onCoverRemove, siteCoverPrefs)
)
}
menus.push(
Expand Down Expand Up @@ -428,13 +429,14 @@ function renderCreditEditor (onlyUrl, key, label, item, onChange, path) {
)
}

function renderImageEditor (hasCover, allowCoverChange, allowCoverRemove, type, title, coverPrefs = {}, onChange, onUploadRequest, onCoverRemove) {
function renderImageEditor (hasCover, allowCoverChange, allowCoverRemove, type, title, coverPrefs = {}, onChange, onUploadRequest, onCoverRemove, siteCoverPrefs) {
const {filter, crop, overlay} = coverPrefs
return el(ImageEditor
, { hasCover
, allowCoverChange
, allowCoverRemove
, title
, siteCoverPrefs
, filter
, crop
, overlay
Expand Down
2 changes: 1 addition & 1 deletion src/components/media.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Media.childContextTypes =
Media.propTypes =
{ initialBlock: React.PropTypes.object.isRequired
, store: React.PropTypes.object.isRequired
, coverPrefs: React.PropTypes.object.isRequired
, imgfloConfig: React.PropTypes.object
, coverPrefs: React.PropTypes.object
}
export default React.createFactory(Media)
1 change: 1 addition & 0 deletions src/plugins/widget-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default class WidgetBase {
this.el.setAttribute('grid-id', options.id)
this.id = options.id
this.initialBlock = options.initialBlock
this.coverPrefs = options.coverPrefs
this.el.style.position = 'absolute'
this.move(options.initialRectangle)
options.widgetContainer.appendChild(this.el)
Expand Down
1 change: 1 addition & 0 deletions src/plugins/widget-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default class WidgetReact extends WidgetBase {
, onChange: this.onChange
, imgfloConfig: this.ed.imgfloConfig
, store: this.ed
, coverPrefs: this.coverPrefs
}

this.mounted = ReactDOM.render(new Media(props), this.el)
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default class PluginWidget {
this.editableView = options.editableView
this.pm = pm
this.widgetPath = options.widgetPath
this.coverPrefs = options.coverPrefs
this.coverPrefs = options.coverPrefs || {}

this.widgets = {}
this.el = document.createElement('div')
Expand Down

0 comments on commit 9d1ca41

Please sign in to comment.