Skip to content

Commit

Permalink
place image below in document preview
Browse files Browse the repository at this point in the history
  • Loading branch information
vgeorge committed Oct 18, 2023
1 parent 665cd00 commit 4e9563d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
12 changes: 10 additions & 2 deletions app/assets/scripts/components/documents/pdf-preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import DocumentBody from '../single-view/document-body';
import DocumentTitle from '../single-view/document-title';
import { DocumentProse } from '../single-view/document-content';
import { ScrollAnchorProvider } from '../single-view/scroll-manager';
import { applyNumberCaptionsToDocument } from '../../../utils/apply-number-captions-to-document';
import {
PLACEMENTS,

Check failure on line 13 in app/assets/scripts/components/documents/pdf-preview/index.js

View workflow job for this annotation

GitHub Actions / lint

'PLACEMENTS' is defined but never used
applyNumberCaptionsToDocument
} from '../../../utils/apply-number-captions-to-document';
import { IMAGE_BLOCK } from '../../slate/plugins/constants';

Check failure on line 16 in app/assets/scripts/components/documents/pdf-preview/index.js

View workflow job for this annotation

GitHub Actions / lint

'IMAGE_BLOCK' is defined but never used

const TocHeader = styled.h1`
border-bottom: 3px solid #000;
Expand Down Expand Up @@ -240,7 +244,11 @@ function PdfPreview() {
}

if (atbd.status === 'succeeded') {
setDocument(applyNumberCaptionsToDocument(atbd.data.document));
setDocument(
applyNumberCaptionsToDocument(atbd.data.document, {
imageCaptionBelow: true
})
);
waitForImages();
}
}, [atbd.status]);

Check warning on line 254 in app/assets/scripts/components/documents/pdf-preview/index.js

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has a missing dependency: 'atbd.data.document'. Either include it or remove the dependency array
Expand Down
15 changes: 12 additions & 3 deletions app/assets/scripts/utils/apply-number-captions-to-document.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
/**
* Include table numbers and move captions before the table in the document.
*/
export function applyNumberCaptionsToDocument(document) {
export function applyNumberCaptionsToDocument(document, placement) {
// Section id list in the order they should appear in the document
const documentSectionIds = [
'key_points',
Expand Down Expand Up @@ -73,9 +73,9 @@ export function applyNumberCaptionsToDocument(document) {

// Reverse the table rows to make caption appear first
// and add the table number to the caption
return {
let nextChild = {
...child,
children: child.children.reverse().map((c) => {
children: child.children.map((c) => {
if (c.type !== 'caption') {
return c;
}
Expand All @@ -93,6 +93,15 @@ export function applyNumberCaptionsToDocument(document) {
};
})
};

if (child.type === IMAGE_BLOCK && placement?.imageCaptionBelow) {
return nextChild;
} else {
return {
...nextChild,
children: nextChild.children.reverse()
};
}
}

return child;
Expand Down

0 comments on commit 4e9563d

Please sign in to comment.