diff options
Diffstat (limited to 'src/components/Content')
| -rw-r--r-- | src/components/Content/Content.tsx | 7 |
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 @@ | |||
| 1 | import * as React from "react"; | 1 | import * as React from "react"; |
| 2 | import {Dispatch, SetStateAction, useMemo} from "react"; | 2 | import {Dispatch, SetStateAction, useContext, useMemo} from "react"; |
| 3 | import {RequestPayload, ResponsePayload} from "~hooks/useRequests"; | 3 | import {RequestPayload, ResponsePayload} from "~hooks/useRequests"; |
| 4 | import ReactJson from 'react-json-view'; | 4 | import ReactJson from 'react-json-view'; |
| 5 | import styles from './Content.module.scss'; | 5 | import styles from './Content.module.scss'; |
| 6 | import {Button, Col, Container, Row} from "react-bootstrap"; | 6 | import {Button, Col, Container, Row} from "react-bootstrap"; |
| 7 | import {DarkModeContext} from "../../contexts/DarkMode"; | ||
| 7 | 8 | ||
| 8 | function getHeader(headers: { [key: string]: string }, key: string, unit?: string): string | null { | 9 | function 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 | ||
| 65 | function ContentBody({ data, raw = false }: Omit<ContentProps, 'setRaw'>) { | 66 | function 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 | } |
