Skip to content

Commit 57bfcae

Browse files
authored
Merge branch 'development' into 7499-update-react-router-dom
2 parents 038167d + ce9767b commit 57bfcae

File tree

6 files changed

+23
-9
lines changed

6 files changed

+23
-9
lines changed

app/react/Viewer/PDFView.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ class PDFViewComponent extends Component {
7979
}
8080
}
8181

82-
changePage(nextPage) {
82+
changePage(nextPage, force = false) {
8383
const { raw = 'false' } = searchParamsFromSearchParams(this.props.searchParams);
8484

8585
const notRaw = String(raw).toLowerCase() === 'false';
8686
if (notRaw) {
87-
return scrollToPage(nextPage);
87+
return scrollToPage(nextPage, 50, force);
8888
}
8989

9090
return this.changeBrowserHistoryPage(nextPage, notRaw);

app/react/Viewer/actions/specs/uiActions.spec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,19 @@ describe('Viewer uiActions', () => {
262262
});
263263
});
264264

265+
describe('scrollToPage', () => {
266+
it('should scroll to the page passed forcing the load', async () => {
267+
spyOn(scroller, 'to').and.callFake(async () => Promise.resolve());
268+
actions.scrollToPage(3, 1, true);
269+
expect(scroller.to).toHaveBeenCalledWith('.document-viewer div#page-3', '.document-viewer', {
270+
dividerOffset: 1,
271+
duration: 1,
272+
force: true,
273+
offset: 50,
274+
});
275+
});
276+
});
277+
265278
describe('highlightSnippet', () => {
266279
it('should unmark all and mark snippets passed only once (only the ones for the pages being rendered)', () => {
267280
const container = document.createElement('div');

app/react/Viewer/actions/uiActions.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,12 @@ export function highlightSnippet(snippet) {
114114
});
115115
}
116116

117-
export function scrollToPage(page, duration = 50) {
117+
export function scrollToPage(page, duration = 50, force = false) {
118118
scroller.to(`.document-viewer div#page-${page}`, '.document-viewer', {
119119
duration,
120120
dividerOffset: 1,
121121
offset: 50,
122+
force,
122123
});
123124
}
124125

app/react/Viewer/components/Paginator.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const Paginator = ({ page = 1, totalPages = 1, onPageChange = () => {} }) => {
2020
queryParams={{ page: prevPage }}
2121
onClick={e => {
2222
e.preventDefault();
23-
onPageChange(prevPage);
23+
onPageChange(prevPage, true);
2424
}}
2525
{...disableButton(page, 1)}
2626
>
@@ -31,7 +31,7 @@ const Paginator = ({ page = 1, totalPages = 1, onPageChange = () => {} }) => {
3131
queryParams={{ page: nextPage }}
3232
onClick={e => {
3333
e.preventDefault();
34-
onPageChange(nextPage);
34+
onPageChange(nextPage, true);
3535
}}
3636
{...disableButton(page, totalPages)}
3737
>

app/react/Viewer/components/specs/Paginator.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe('Paginator', () => {
7777
});
7878

7979
describe('when passing onPageChange callback', () => {
80-
it('should execute callback on prev/next passing the page selecte', () => {
80+
it('should execute callback on prev/next passing the adjacent page forcing navigation for partially visible pages', () => {
8181
page = 5;
8282
const props = {
8383
totalPages: 25,
@@ -91,13 +91,13 @@ describe('Paginator', () => {
9191
.find(CurrentLocationLink)
9292
.at(0)
9393
.simulate('click', { preventDefault: () => {} });
94-
expect(props.onPageChange).toHaveBeenCalledWith(4);
94+
expect(props.onPageChange).toHaveBeenCalledWith(4, true);
9595

9696
component
9797
.find(CurrentLocationLink)
9898
.at(1)
9999
.simulate('click', { preventDefault: () => {} });
100-
expect(props.onPageChange).toHaveBeenCalledWith(6);
100+
expect(props.onPageChange).toHaveBeenCalledWith(6, true);
101101
});
102102
});
103103
});

app/react/Viewer/specs/PDFView.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ describe('PDFView', () => {
271271
render();
272272
component.find({ page: 15 }).at(0).props().changePage(16);
273273
expect(mockNavigate).not.toHaveBeenCalled();
274-
expect(uiActions.scrollToPage).toHaveBeenCalledWith(16);
274+
expect(uiActions.scrollToPage).toHaveBeenCalledWith(16, 50, false);
275275
});
276276
});
277277
});

0 commit comments

Comments
 (0)