in frontend/src/js/components/viewer/Viewer.tsx [130:164]
componentDidUpdate(prevProps: Props) {
if (
this.props.currentHighlight !== prevProps.currentHighlight ||
this.props.totalHighlights !== prevProps.totalHighlights
) {
if (this.props.currentHighlight === undefined) {
// We must have just changed view to a view with no highlight in the state yet.
// So start at first search result.
if(this.props.match.params.uri && this.props.urlParams.q && this.props.urlParams.view) {
this.props.setCurrentHighlight(
this.props.match.params.uri,
this.props.urlParams.q,
this.props.urlParams.view,
0
);
}
} else {
// The highlights might have changed because the user has clicked next/previous,
// or because they've changed view between text & ocr. Either way, we need
// to get the scroll position and the URL in sync with the highlights.
this.scrollToCurrentHighlight();
this.props.setCurrentHighlightInUrl(this.props.currentHighlight.toString(10));
}
}
if(!this.props.urlParams.view && this.props.resource) {
const maybeDefaultView = getDefaultView(this.props.resource);
if(maybeDefaultView) {
this.props.setResourceView(maybeDefaultView);
}
}
document.title = calculateResourceTitle(this.props.resource);
}