Skip to content

Commit 4adad5f

Browse files
Implement infinite scrolling for document search (#3855)
* Split up render method in PdfViewerSearch This is just a small refactoring to make it easier to adjust this method. * Rename fetchPage to fetchSearchResults … because that is what it actually does -- it doesn’t load a page from the document, it loads a list of pages that contain the search terms. * Implement infinite scrolling for document search results Fixes #3320 * Remove useless code I’m not sure what exactly the intention here was originally, but it didn’t have any effect in its current version. `page` and `res.index` would always be undefined and as a result, the `active` class was applied to every single link. The `active` class doesn’t apply any styles. Probably this is just leftover from a previous iteration of the UI, so I’ve removed this.
1 parent 11cc0d4 commit 4adad5f

File tree

1 file changed

+42
-26
lines changed

1 file changed

+42
-26
lines changed

ui/src/viewers/PdfViewerSearch.jsx

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import { FormattedMessage } from 'react-intl';
44
import classNames from 'classnames';
55
import { connect } from 'react-redux';
66
import queryString from 'query-string';
7-
import { SectionLoading, SearchHighlight } from 'components/common';
7+
import {
8+
SectionLoading,
9+
SearchHighlight,
10+
QueryInfiniteLoad,
11+
} from 'components/common';
812
import { Classes } from '@blueprintjs/core';
913
import c from 'classnames';
1014
import { queryEntities } from 'actions';
@@ -17,13 +21,13 @@ class PdfViewerSearch extends Component {
1721
}
1822

1923
componentDidMount() {
20-
this.fetchPage();
24+
this.fetchSearchResults();
2125
}
2226

2327
componentDidUpdate(prevProps) {
2428
const { query } = this.props;
2529
if (!query.sameAs(prevProps.query)) {
26-
this.fetchPage();
30+
this.fetchSearchResults();
2731
}
2832
}
2933

@@ -40,47 +44,37 @@ class PdfViewerSearch extends Component {
4044
return `#${queryString.stringify(hashQuery)}`;
4145
}
4246

43-
fetchPage() {
47+
fetchSearchResults() {
4448
const { query, result } = this.props;
4549
if (!!query.getString('q') && result.shouldLoad) {
4650
this.props.queryEntities({ query });
4751
}
4852
}
4953

5054
render() {
51-
const { page, dir, result } = this.props;
55+
const { result } = this.props;
5256

5357
if (result.total === undefined) {
5458
return <SectionLoading />;
5559
}
5660

5761
return (
5862
<div className="pages">
59-
{result.total === 0 && (
60-
<>
61-
<div
62-
className={c(
63-
Classes.CALLOUT,
64-
Classes.INTENT_WARNING,
65-
`${Classes.ICON}-search`
66-
)}
67-
>
68-
<FormattedMessage
69-
id="document.search.no_match"
70-
defaultMessage="No single page within this document matches all your search terms."
71-
/>
72-
</div>
73-
{this.props.children}
74-
</>
75-
)}
63+
{result.total === 0 ? this.renderEmptyState() : this.renderResults()}
64+
</div>
65+
);
66+
}
67+
68+
renderResults() {
69+
const { dir, result, query } = this.props;
70+
71+
return (
72+
<>
7673
<ul>
7774
{result.results.map((res) => (
7875
<li key={`page-${res.id}`}>
7976
<p dir={dir}>
80-
<Link
81-
to={this.getResultLink(res)}
82-
className={classNames({ active: page === res.index })}
83-
>
77+
<Link to={this.getResultLink(res)}>
8478
<span
8579
className={c(Classes.ICON, `${Classes.ICON}-document`)}
8680
/>
@@ -97,6 +91,28 @@ class PdfViewerSearch extends Component {
9791
</li>
9892
))}
9993
</ul>
94+
<QueryInfiniteLoad
95+
query={query}
96+
result={result}
97+
fetch={queryEntities}
98+
/>
99+
</>
100+
);
101+
}
102+
103+
renderEmptyState() {
104+
return (
105+
<div
106+
className={c(
107+
Classes.CALLOUT,
108+
Classes.INTENT_WARNING,
109+
`${Classes.ICON}-search`
110+
)}
111+
>
112+
<FormattedMessage
113+
id="document.search.no_match"
114+
defaultMessage="No single page within this document matches all your search terms."
115+
/>
100116
</div>
101117
);
102118
}

0 commit comments

Comments
 (0)