Skip to content

Commit

Permalink
static/*: update render functions to react18 syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
philli-m committed Sep 20, 2022
1 parent 04466cb commit 01a4a51
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 16 deletions.
5 changes: 3 additions & 2 deletions adhocracy4/comments/static/comments/react_comments.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from 'react'
import ReactDOM from 'react-dom'
import { createRoot } from 'react-dom/client'

import CommentBox from './CommentBox'

module.exports.renderComment = function (el) {
const props = JSON.parse(el.getAttribute('data-attributes'))
ReactDOM.render(<CommentBox {...props} />, el)
const root = createRoot(el)
root.render(<CommentBox {...props} />)
}
5 changes: 3 additions & 2 deletions adhocracy4/comments_async/static/comments_async/index.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from 'react'
import ReactDOM from 'react-dom'
import { createRoot } from 'react-dom/client'

import CommentBox from './comment_box'

export function renderComment (el) {
const props = JSON.parse(el.getAttribute('data-attributes'))
ReactDOM.render(<CommentBox {...props} ref={(commentbox) => { window.commentbox = commentbox }} />, el)
const root = createRoot(el)
root.render(<CommentBox {...props} ref={(commentbox) => { window.commentbox = commentbox }} />)
}
6 changes: 4 additions & 2 deletions adhocracy4/follows/static/follows/react_follows.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React from 'react'
import ReactDOM from 'react-dom'
import { createRoot } from 'react-dom/client'

import FollowButton from './FollowButton'

module.exports.renderFollow = function (el) {
const project = el.getAttribute('data-project')
ReactDOM.render(<FollowButton project={project} />, el)
const root = createRoot(el)
root.render(<FollowButton project={project} />)
}
11 changes: 7 additions & 4 deletions adhocracy4/polls/assets/react_polls.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import React from 'react'
import ReactDOM from 'react-dom'
import { createRoot } from 'react-dom/client'

import { EditPollQuestions } from './EditPollQuestions'
import PollQuestions from './PollQuestions'

module.exports.renderPolls = function (element) {
const pollId = element.getAttribute('data-poll-id')

ReactDOM.render(<PollQuestions pollId={pollId} />, element)
const container = element
const root = createRoot(container)
root.render(<PollQuestions pollId={pollId} />)
}

module.exports.renderPollManagement = function (element) {
const pollId = JSON.parse(element.getAttribute('data-poll-id'))

const reloadOnSuccess = JSON.parse(element.getAttribute('data-reloadOnSuccess'))

ReactDOM.render(<EditPollQuestions pollId={pollId} reloadOnSuccess={reloadOnSuccess} />, element)
const root = createRoot(element)
root.render(<EditPollQuestions pollId={pollId} reloadOnSuccess={reloadOnSuccess} />)
}
6 changes: 4 additions & 2 deletions adhocracy4/ratings/static/ratings/react_ratings.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import ReactDOM from 'react-dom'
import { createRoot } from 'react-dom/client'
import classnames from 'classnames'
import django from 'django'

Expand Down Expand Up @@ -152,5 +152,7 @@ module.exports.RatingBox = RatingBox

module.exports.renderRatings = function (el) {
const props = JSON.parse(el.getAttribute('data-attributes'))
ReactDOM.render(<RatingBox {...props} />, el)

const root = createRoot(el)
root.render(<RatingBox {...props} />)
}
8 changes: 4 additions & 4 deletions adhocracy4/reports/static/reports/react_reports.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import django from 'django'
import React from 'react'
import ReactDOM from 'react-dom'
import { createRoot } from 'react-dom/client'

import ReportModal from './ReportModal'

Expand All @@ -15,13 +15,13 @@ module.exports.renderReports = function (el) {
const container = document.createElement('div')
document.body.appendChild(container)

ReactDOM.render((
const root = createRoot(container)
root.render(
<ReportModal
name={props.modalName}
title={django.gettext('You want to report this content? Your message will be sent to the moderation. The moderation will look at the reported content. The content will be deleted if it does not meet our discussion rules (netiquette).')}
btnStyle="cta"
objectId={props.objectId}
contentType={props.contentType}
/>
), container)
/>)
}

0 comments on commit 01a4a51

Please sign in to comment.