summaryrefslogtreecommitdiffstats
path: root/src/components/Content
diff options
context:
space:
mode:
authorGravatar Tom van der Lee <tom@vanderlee.io>2022-01-25 22:03:00 +0100
committerGravatar Tom van der Lee <tom@vanderlee.io>2022-01-25 22:06:58 +0100
commitf69a7786da3ba21373574ee6c96371769a72ac42 (patch)
treea9e9cc0cb6122223b4f0e3d8a533733b55cb44df /src/components/Content
parentf9cd68181137c72e92c6951efd9b8d29c4b73bc1 (diff)
downloadclient-f69a7786da3ba21373574ee6c96371769a72ac42.tar.gz
client-f69a7786da3ba21373574ee6c96371769a72ac42.tar.bz2
client-f69a7786da3ba21373574ee6c96371769a72ac42.zip
Fixed issue with json viewer
Diffstat (limited to 'src/components/Content')
-rw-r--r--src/components/Content/Content.tsx7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/components/Content/Content.tsx b/src/components/Content/Content.tsx
index 95ee444..1341e4f 100644
--- a/src/components/Content/Content.tsx
+++ b/src/components/Content/Content.tsx
@@ -1,9 +1,10 @@
1import * as React from "react"; 1import * as React from "react";
2import {Dispatch, SetStateAction, useMemo} from "react"; 2import {Dispatch, SetStateAction, useContext, useMemo} from "react";
3import {RequestPayload, ResponsePayload} from "~hooks/useRequests"; 3import {RequestPayload, ResponsePayload} from "~hooks/useRequests";
4import ReactJson from 'react-json-view'; 4import ReactJson from 'react-json-view';
5import styles from './Content.module.scss'; 5import styles from './Content.module.scss';
6import {Button, Col, Container, Row} from "react-bootstrap"; 6import {Button, Col, Container, Row} from "react-bootstrap";
7import {DarkModeContext} from "../../contexts/DarkMode";
7 8
8function getHeader(headers: { [key: string]: string }, key: string, unit?: string): string | null { 9function getHeader(headers: { [key: string]: string }, key: string, unit?: string): string | null {
9 console.log(headers, key) 10 console.log(headers, key)
@@ -63,6 +64,7 @@ export default function Content({ raw, setRaw, data }: ContentProps): JSX.Elemen
63}; 64};
64 65
65function ContentBody({ data, raw = false }: Omit<ContentProps, 'setRaw'>) { 66function ContentBody({ data, raw = false }: Omit<ContentProps, 'setRaw'>) {
67 const { darkMode } = useContext(DarkModeContext);
66 const contentType = useMemo(() => { 68 const contentType = useMemo(() => {
67 if (raw) { 69 if (raw) {
68 return ''; 70 return '';
@@ -84,6 +86,7 @@ function ContentBody({ data, raw = false }: Omit<ContentProps, 'setRaw'>) {
84 86
85 if (['application/pdf', 'text/html'].includes(contentType)) { 87 if (['application/pdf', 'text/html'].includes(contentType)) {
86 return <iframe 88 return <iframe
89 className="bg-white"
87 src={`data:${contentType};base64,${data.body}`} 90 src={`data:${contentType};base64,${data.body}`}
88 srcDoc={contentType === 'text/html' ? atob(data.body) : undefined} 91 srcDoc={contentType === 'text/html' ? atob(data.body) : undefined}
89 loading='lazy' 92 loading='lazy'
@@ -94,10 +97,12 @@ function ContentBody({ data, raw = false }: Omit<ContentProps, 'setRaw'>) {
94 if (contentType.startsWith('application/json')) { 97 if (contentType.startsWith('application/json')) {
95 return <ReactJson 98 return <ReactJson
96 src={JSON.parse(atob(data.body))} 99 src={JSON.parse(atob(data.body))}
100 theme={darkMode ? "monokai" : undefined}
97 style={{ 101 style={{
98 padding: '1em', 102 padding: '1em',
99 width: '100%', 103 width: '100%',
100 height: '100%', 104 height: '100%',
105 overflowY: 'auto',
101 }} 106 }}
102 /> 107 />
103 } 108 }