forked from usebruno/bruno
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refaktor: PdfResultViewer into its own file
- Loading branch information
1 parent
e24c0fd
commit 75d5010
Showing
2 changed files
with
24 additions
and
13 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
...no-app/src/components/ResponsePane/QueryResult/QueryResultViewer/PdfResultViewer/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { useState } from 'react'; | ||
import { Document, Page } from 'react-pdf'; | ||
|
||
const PdfResultViewer = ({ dataBuffer }) => { | ||
const [numPages, setNumPages] = useState(null); | ||
function onDocumentLoadSuccess({ numPages }) { | ||
// Only show up to 10 pages, because more will cause lag | ||
setNumPages(Math.min(numPages, 50)); | ||
} | ||
|
||
return ( | ||
<div className="preview-pdf" style={{ height: '100%', overflow: 'auto', maxHeight: 'calc(100vh - 220px)' }}> | ||
<Document file={`data:application/pdf;base64,${dataBuffer}`} onLoadSuccess={onDocumentLoadSuccess}> | ||
{Array.from(new Array(numPages), (el, index) => ( | ||
<Page key={`page_${index + 1}`} pageNumber={index + 1} renderAnnotationLayer={false} /> | ||
))} | ||
</Document> | ||
</div> | ||
); | ||
}; | ||
|
||
export default PdfResultViewer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters