Skip to content

Commit

Permalink
add poll embed component, you can now embed a poll by clicking the 'p…
Browse files Browse the repository at this point in the history
…oll' button in the embed toolbar
  • Loading branch information
JamieRL committed Jun 11, 2018
1 parent 7c94d0d commit e403ccd
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 17 deletions.
10 changes: 0 additions & 10 deletions dispatch/modules/content/embeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,6 @@ def render(self, data):
return ''

return widget.render(data=data['data'])

# except ZoneNotFound:
# return ''

# try:
# return zone.widget.render(add_context=kwargs)
# except (WidgetNotFound, AttributeError):
# pass

# return ''

class ImageEmbed(AbstractTemplateEmbed):
TEMPLATE = 'embeds/image.html'
Expand Down
4 changes: 4 additions & 0 deletions dispatch/modules/content/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def render_node(html, node):
return html + '<p>%s</p>' % node['data']
else:
try:
if node['type'] == 'poll':
node['type'] = 'widget'
node['data']['data'] = node['data']

return html + embeds.render(node['type'], node['data'])
except EmbedException:
return html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
PullQuoteEmbed,
GalleryEmbed,
CodeEmbed,
WidgetEmbed
WidgetEmbed,
PollEmbed
} from '../../vendor/dispatch-editor'

const embeds = [
Expand All @@ -18,7 +19,8 @@ const embeds = [
CodeEmbed,
PullQuoteEmbed,
GalleryEmbed,
WidgetEmbed
WidgetEmbed,
PollEmbed
]

export default class ArticleContentEditor extends React.Component {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ export default function PollField(props) {
many={props.field.many}
onChange={selected => props.onChange(selected)} />
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class PollSelectInputComponent extends React.Component {

return (
<ItemSelectInput
many={this.props.many}
many={false}
selected={this.props.selected}
results={this.props.polls.ids}
entities={this.props.entities.polls}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react'

import PollSelectInput from '../../../components/inputs/selects/PollSelectInput'
import { FormInput } from '../../../components/inputs'

function PollEmbedComponent(props) {
return (
<div className='o-embed o-embed--poll'>
<form>
<FormInput label='Poll'>
<PollSelectInput
fill={true}
selected={props.data.poll}
onChange={selected => {
props.updateField('poll',selected)
props.stopEditing()
}
} />
</FormInput>
</form>
</div>
)
}

export default {
type: 'poll',
component: PollEmbedComponent,
defaultData: {
poll:'',
widget_id: 'poll'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import CodeEmbed from './CodeEmbed'
import PullQuoteEmbed from './PullQuoteEmbed'
import GalleryEmbed from './GalleryEmbed'
import WidgetEmbed from './WidgetEmbed'
import PollEmbed from './PollEmbed'

export {
ImageEmbed,
VideoEmbed,
PullQuoteEmbed,
CodeEmbed,
GalleryEmbed,
WidgetEmbed
WidgetEmbed,
PollEmbed
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
PullQuoteEmbed,
VideoEmbed,
CodeEmbed,
WidgetEmbed
WidgetEmbed,
PollEmbed
} from './embeds'

import {
Expand All @@ -28,5 +29,6 @@ export {
PullQuoteEmbed,
VideoEmbed,
CodeEmbed,
WidgetEmbed
WidgetEmbed,
PollEmbed
}

0 comments on commit e403ccd

Please sign in to comment.