mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-27 20:01:10 +01:00
Response viewer for PDF (#48)
This PR adds a response viewer for PDF files using `react-pdf`
This commit is contained in:
@@ -35,21 +35,14 @@ export function TextViewer({ response, pretty, className }: Props) {
|
||||
);
|
||||
|
||||
const contentType = useContentTypeFromHeaders(response.headers);
|
||||
const rawBody = useResponseBodyText(response) ?? '';
|
||||
const rawBody = useResponseBodyText(response) ?? null;
|
||||
const isSearching = filterText != null;
|
||||
const formattedBody =
|
||||
pretty && contentType?.includes('json')
|
||||
? tryFormatJson(rawBody)
|
||||
: pretty && contentType?.includes('xml')
|
||||
? tryFormatXml(rawBody)
|
||||
: rawBody;
|
||||
|
||||
const filteredResponse = useFilterResponse({
|
||||
filter: debouncedFilterText ?? '',
|
||||
responseId: response.id,
|
||||
});
|
||||
|
||||
const body = isSearching && filterText?.length > 0 ? filteredResponse : formattedBody;
|
||||
const toggleSearch = useCallback(() => {
|
||||
if (isSearching) {
|
||||
setFilterText(null);
|
||||
@@ -104,6 +97,18 @@ export function TextViewer({ response, pretty, className }: Props) {
|
||||
return result;
|
||||
}, [canFilter, filterText, isJson, isSearching, response.id, setFilterText, toggleSearch]);
|
||||
|
||||
if (rawBody == null) {
|
||||
return 'bad';
|
||||
}
|
||||
|
||||
const formattedBody =
|
||||
pretty && contentType?.includes('json')
|
||||
? tryFormatJson(rawBody)
|
||||
: pretty && contentType?.includes('xml')
|
||||
? tryFormatXml(rawBody)
|
||||
: rawBody;
|
||||
const body = isSearching && filterText?.length > 0 ? filteredResponse : formattedBody;
|
||||
|
||||
return (
|
||||
<Editor
|
||||
readOnly
|
||||
|
||||
Reference in New Issue
Block a user