Skip to content

Commit

Permalink
apps/budgeting/proposal-item-detail/voting: passing same information to
Browse files Browse the repository at this point in the history
template tag for detail proposal view.
distuingish between if VoteButton used as list-item(React) or as widget(Django) and fetch
differently
  • Loading branch information
Kha authored and Rineee committed Dec 21, 2021
1 parent 835ab08 commit b22af6d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
14 changes: 13 additions & 1 deletion meinberlin/apps/budgeting/assets/VoteButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,25 @@ export default class VoteButton extends React.Component {
await updateItem({}, url, 'DELETE')
}

triggerRender = () => {
// FIXME: this distuingishes between if
// it has a parent that handles onVoteChange
// or if it is used as widget, and therefore page
// has to be reloaded --> fix would be one asynchronous way
if (this.props.asWidget) {
window.location.reload()
} else {
this.props.onVoteChange(this.props.currentPage)
}
}

async handleOnChange () {
if (this.props.isChecked) {
await this.deleteVote()
} else {
await this.addVote()
}
this.props.onVoteChange(this.props.currentPage)
this.triggerRender()
}

render () {
Expand Down
22 changes: 15 additions & 7 deletions meinberlin/apps/budgeting/assets/react_vote_button_init.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import React from 'react'
import ReactDOM from 'react-dom'
import { widget as ReactWidget } from 'adhocracy4'
import { VoteButton } from './VoteButton.jsx'
import VoteButton from './VoteButton.jsx'

function init () {
ReactWidget.initialise('mb', 'vote_button',
function (el) {
const props = el.getAttribute('data-attributes')
ReactDOM.render(<VoteButton {...props} />, el)
}
)
ReactWidget.initialise('mb', 'vote_button', function (el) {
const props = JSON.parse(el.getAttribute('data-attributes'))
const votesLeft = props.token_info ? props.token_info.votes_left : false
ReactDOM.render(
<VoteButton
objectID={props.objectID}
tokenvoteApiUrl={props.tokenvote_api_url}
isChecked={props.session_token_voted}
disabled={!votesLeft && !props.session_token_voted}
asWidget
/>,
el
)
})
}

document.addEventListener('DOMContentLoaded', init, false)
Expand Down

0 comments on commit b22af6d

Please sign in to comment.