This repository has been archived by the owner on Nov 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
shallow copies are evil. Copy the DOM node properly. #126
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,28 +133,39 @@ class PostRenderBallotProcessor extends Handler { | |
if (pages.length % 2) { | ||
const pagedjsPages = pages[0].pagesArea | ||
if (pagedjsPages.lastChild) { | ||
pagedjsPages.appendChild(pagedjsPages.lastChild.cloneNode(true)) | ||
const newLastPageElement = pagedjsPages.lastChild.cloneNode( | ||
true | ||
) as HTMLElement | ||
pagedjsPages.appendChild(newLastPageElement) | ||
pagedjsPages.setAttribute( | ||
'style', | ||
`--pagedjs-page-count:${pages.length + 1};` | ||
) | ||
const lastPage = pagedjsPages.lastChild! as Element | ||
lastPage.id = `page-${pages.length + 1}` | ||
lastPage.classList.remove('pagedjs_first_page', 'pagedjs_right_page') | ||
lastPage.classList.add('pagedjs_left_page') | ||
lastPage.setAttribute('data-page-number', `${pages.length + 1}`) | ||
newLastPageElement.id = `page-${pages.length + 1}` | ||
newLastPageElement.classList.remove( | ||
'pagedjs_first_page', | ||
'pagedjs_right_page' | ||
) | ||
newLastPageElement.classList.add('pagedjs_left_page') | ||
newLastPageElement.setAttribute( | ||
'data-page-number', | ||
`${pages.length + 1}` | ||
) | ||
newLastPageElement.setAttribute('data-id', `page-${pages.length + 1}`) | ||
ReactDOM.render( | ||
<BlankPageContent> | ||
<Prose> | ||
<p>This ballot page is intentionally blank.</p> | ||
</Prose> | ||
</BlankPageContent>, | ||
lastPage.getElementsByClassName('pagedjs_page_content')[0] | ||
newLastPageElement.getElementsByClassName('pagedjs_page_content')[0] | ||
) | ||
|
||
const newPage = { ...pages[pages.length - 1] } | ||
newPage.element.dataset.pageNumber = `${pages.length + 1}` | ||
newPage.element.dataset.id = `page-${pages.length + 1}` | ||
const newPage = { | ||
...pages[pages.length - 1], | ||
element: newLastPageElement, | ||
} | ||
Comment on lines
+164
to
+167
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the actual fix, right? Everything else should be equivalent. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should, yes. Trying to change as little as possible. |
||
|
||
pages.push(newPage) | ||
} | ||
} | ||
|
@@ -178,22 +189,19 @@ class PostRenderBallotProcessor extends Handler { | |
ballotType, | ||
ballotId, | ||
}: HMPBBallotMetadata = JSON.parse(qrCodeTarget.dataset.metadata ?? '') | ||
ReactDOM.render( | ||
<QRCode | ||
level="H" | ||
value={v1.encodeHMPBBallotPageMetadata(election, { | ||
electionHash: electionHash.substring(0, 20), | ||
ballotStyleId, | ||
precinctId, | ||
locales, | ||
isTestMode, | ||
pageNumber: parseInt(pageNumber!, 10), | ||
ballotType, | ||
ballotId, | ||
})} | ||
/>, | ||
qrCodeTarget | ||
) | ||
|
||
const encoded = v1.encodeHMPBBallotPageMetadata(election, { | ||
electionHash: electionHash.substring(0, 20), | ||
ballotStyleId, | ||
precinctId, | ||
locales, | ||
isTestMode, | ||
pageNumber: parseInt(pageNumber!, 10), | ||
ballotType, | ||
ballotId, | ||
}) | ||
|
||
ReactDOM.render(<QRCode level="H" value={encoded} />, qrCodeTarget) | ||
} | ||
}) | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason not to use the approach we had, i.e.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe, but the approach we had was via
setAttribute
so I didn't want to change it. I added theid
one cause it was missing.