Skip to content

Commit 5e2b001

Browse files
authored
Fix opening search everytime. (#239)
1 parent 54c4cee commit 5e2b001

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/components/Search/Search.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { type IPdfContext, PdfContext } from "../PdfProvider/PdfProvider";
44

55
import "./Search.css";
66

7-
export function Search({ onSearchFinished }: { onSearchFinished: () => void }) {
7+
export function Search({ onSearchFinished }: { onSearchFinished: (hasQuery: boolean) => void }) {
88
const { locationParams } = useContext(LocationContext) as ILocationContext;
99
const [query, setQuery] = useState("");
1010
// search query is persistent between tab switches
@@ -14,7 +14,7 @@ export function Search({ onSearchFinished }: { onSearchFinished: () => void }) {
1414
if (search) {
1515
setQuery(search);
1616
} else {
17-
onSearchFinished();
17+
onSearchFinished(false);
1818
}
1919
}, [search, onSearchFinished]);
2020

@@ -45,7 +45,7 @@ type PageResults = {
4545

4646
type SearchResultsProps = {
4747
query: string;
48-
onSearchFinished: () => void;
48+
onSearchFinished: (hasQuery: boolean) => void;
4949
};
5050

5151
function SearchResults({ query, onSearchFinished }: SearchResultsProps) {
@@ -112,7 +112,7 @@ function SearchResults({ query, onSearchFinished }: SearchResultsProps) {
112112
clearTimeout(resetTimeout.current);
113113
setIsLoading(false);
114114
setMatches({ count, pagesAndCount });
115-
onSearchFinished();
115+
onSearchFinished(true);
116116
};
117117

118118
eventBus.on("updatefindmatchescount", updateMatches);

src/components/Sidebar/Sidebar.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ export function Sidebar() {
3333
// if we have both search & section, we need to wait
3434
// for the search to be done, before scrolling to section.
3535
const [searchIsDone, setSearchIsDone] = useState(false);
36-
const onSearchFinished = useCallback(() => {
36+
const onSearchFinished = useCallback((hasQuery: boolean) => {
3737
setSearchIsDone(true);
38-
setTab("search");
38+
if (hasQuery) {
39+
setTab("search");
40+
}
3941
}, []);
4042

4143
const tabs = [

0 commit comments

Comments
 (0)