diff options
Diffstat (limited to 'src/components')
| -rw-r--r-- | src/components/App/App.tsx | 5 | ||||
| -rw-r--r-- | src/components/Content/Content.tsx | 7 |
2 files changed, 9 insertions, 3 deletions
diff --git a/src/components/App/App.tsx b/src/components/App/App.tsx index bbab612..3f50f22 100644 --- a/src/components/App/App.tsx +++ b/src/components/App/App.tsx | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | import * as React from "react"; | 1 | import * as React from "react"; |
| 2 | import {ReactElement, useEffect, useMemo, useState} from "react"; | 2 | import {ReactElement, useContext, useEffect, useMemo, useState} from "react"; |
| 3 | import useRequests, { | 3 | import useRequests, { |
| 4 | ReadyState, | 4 | ReadyState, |
| 5 | RequestResponse | 5 | RequestResponse |
| @@ -16,6 +16,7 @@ import {Sliders} from "../Icons/Sliders"; | |||
| 16 | import {Sun} from "../Icons/Sun"; | 16 | import {Sun} from "../Icons/Sun"; |
| 17 | import {Moon} from "../Icons/Moon"; | 17 | import {Moon} from "../Icons/Moon"; |
| 18 | import Trash from "../Icons/Trash"; | 18 | import Trash from "../Icons/Trash"; |
| 19 | import {DarkModeContext} from "../../contexts/DarkMode"; | ||
| 19 | 20 | ||
| 20 | interface Config { | 21 | interface Config { |
| 21 | url: string | 22 | url: string |
| @@ -49,7 +50,7 @@ const statusTextMap: ReadyStateMap = { | |||
| 49 | } | 50 | } |
| 50 | 51 | ||
| 51 | export default function App() { | 52 | export default function App() { |
| 52 | const { darkMode, toggle } = useDarkMode(); | 53 | const { darkMode, toggle } = useContext(DarkModeContext); |
| 53 | const [config, setConfig]= useState<Config | null>(null) | 54 | const [config, setConfig]= useState<Config | null>(null) |
| 54 | 55 | ||
| 55 | const { calls, readyState, clear } = useRequests({ | 56 | const { calls, readyState, clear } = useRequests({ |
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 | } |
