Skip to content

Commit

Permalink
fix(): jump to the first match of pre-defined keywords automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
weareoutman committed Sep 23, 2024
1 parent 2afbd92 commit 99afbf1
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions bricks/advanced/src/pdf-viewer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useEffect, useState } from "react";
import { createDecorators } from "@next-core/element";
import { ReactNextElement } from "@next-core/react-element";
import "@next-core/theme";
Expand Down Expand Up @@ -67,13 +67,20 @@ export function PdfViewerComponent({
page,
viewerStyle,
}: PdfViewerComponentProps) {
const defaultLayoutPluginInstance = defaultLayoutPlugin({
toolbarPlugin: {
searchPlugin: {
keyword: search,
},
},
});
// https://react-pdf-viewer.dev/examples/jump-to-the-first-match-of-pre-defined-keywords-automatically/
const [isDocumentLoaded, setDocumentLoaded] = useState(false);

Check warning on line 71 in bricks/advanced/src/pdf-viewer/index.tsx

View check run for this annotation

Codecov / codecov/patch

bricks/advanced/src/pdf-viewer/index.tsx#L71

Added line #L71 was not covered by tests

const defaultLayoutPluginInstance = defaultLayoutPlugin();

Check warning on line 73 in bricks/advanced/src/pdf-viewer/index.tsx

View check run for this annotation

Codecov / codecov/patch

bricks/advanced/src/pdf-viewer/index.tsx#L73

Added line #L73 was not covered by tests

useEffect(() => {

Check warning on line 75 in bricks/advanced/src/pdf-viewer/index.tsx

View check run for this annotation

Codecov / codecov/patch

bricks/advanced/src/pdf-viewer/index.tsx#L75

Added line #L75 was not covered by tests
if (isDocumentLoaded && search) {
defaultLayoutPluginInstance.toolbarPluginInstance.searchPluginInstance.highlight(

Check warning on line 77 in bricks/advanced/src/pdf-viewer/index.tsx

View check run for this annotation

Codecov / codecov/patch

bricks/advanced/src/pdf-viewer/index.tsx#L77

Added line #L77 was not covered by tests
{
keyword: search,
}
);
}
}, [isDocumentLoaded, search]);

return (
// See: https://react-pdf-viewer.dev/examples/compile-and-set-the-worker-source-with-webpack/
Expand All @@ -85,6 +92,7 @@ export function PdfViewerComponent({
fileUrl={url}
initialPage={page}
plugins={[defaultLayoutPluginInstance]}
onDocumentLoad={() => setDocumentLoaded(true)}

Check warning on line 95 in bricks/advanced/src/pdf-viewer/index.tsx

View check run for this annotation

Codecov / codecov/patch

bricks/advanced/src/pdf-viewer/index.tsx#L95

Added line #L95 was not covered by tests
/>
</div>
</Worker>
Expand Down

0 comments on commit 99afbf1

Please sign in to comment.