From 51a2ac628822e96459b3d570eada953ac8927d43 Mon Sep 17 00:00:00 2001 From: Tom van der Lee Date: Wed, 19 Jan 2022 21:27:21 +0100 Subject: Added boostrap --- src/components/Content/Content.tsx | 74 +++++++++++++++++++++++++++++--------- 1 file changed, 58 insertions(+), 16 deletions(-) (limited to 'src/components/Content') diff --git a/src/components/Content/Content.tsx b/src/components/Content/Content.tsx index a7b5949..cb5e6bc 100644 --- a/src/components/Content/Content.tsx +++ b/src/components/Content/Content.tsx @@ -13,6 +13,21 @@ import { } from "react"; import ReactJson from 'react-json-view'; import styles from './Content.module.scss'; +import {Col, Container, Row} from "react-bootstrap"; + +function getHeader(headers: { [key: string]: string }, key: string, unit?: string): string | null { + console.log(headers, key) + try { + const [_, value] = Object + .entries(headers) + .find(([headerKey]) => headerKey.toLowerCase() === key.toLowerCase()) + return unit !== undefined + ? `${value}${unit}` + : value + } catch { + return null; + } +} interface ContentProps { data: RequestPayload | ResponsePayload @@ -20,17 +35,29 @@ interface ContentProps { raw?: boolean } -export default function Content({ raw, setRaw, ...props }: ContentProps): JSX.Element { +export default function Content({ raw, setRaw, data }: ContentProps): JSX.Element { return ( -
-
- setRaw(!raw)}/> - -
-
+ <> + + + + setRaw(!raw)}/> + + + + { + [ + getHeader(data.headers, 'content-length', 'bytes'), + getHeader(data.headers, 'content-type'), + ].filter(x => x !== null).join('; ') + } + + + + {(() => { try { - return ContentBody({ ...props, raw }) + return ContentBody({ data, raw }) } catch { return (
@@ -40,8 +67,28 @@ export default function Content({ raw, setRaw, ...props }: ContentProps): JSX.El ) } })()} -
-
+ + + //
+ //
+ // setRaw(!raw)}/> + // + //
+ //
+ // {(() => { + // try { + // return ContentBody({ ...props, raw }) + // } catch { + // return ( + //
+ //

Body could not be rendered

+ // setRaw(true)}>View raw + //
+ // ) + // } + // })()} + //
+ //
) }; @@ -51,12 +98,7 @@ function ContentBody({ data, raw = false }: Omit) { return ''; } - const [_, type] = ( - Object - .entries(data.headers) - .find(([key]) => key.toLowerCase() === 'content-type') - ); - + const type = getHeader(data.headers, 'content-type'); return type.toLowerCase().split(';')[0]; }, [data, raw]); -- cgit v1.2.3